Optimizing Query Performance in TiDB Cloud Serverless Tier #66410
Replies: 3 comments
-
Beta Was this translation helpful? Give feedback.
-
|
原帖作者:Hazel\n原帖时间:2025-02-07 11:00:10.77602\n\n Hi @gregbowers, for better assistance, could you share your cluster ID and the redacted slow SQL with us? |
Beta Was this translation helpful? Give feedback.
-
|
A few things worth checking for JOIN and subquery performance in distributed SQL environments like TiDB: 1. Coprocessor pushdown scope — TiDB pushes predicates and aggregations down to TiKV coprocessors, but complex subqueries sometimes prevent full pushdown. Run 2. Join order and statistics freshness — In Serverless Tier, auto-analyze intervals may differ from dedicated clusters. Running 3. Index join vs hash join selection — For queries joining a large table with a small lookup table, TiDB's index join (equivalent to nested loop with index) is usually fastest. But if both tables are large, hash join performs better. You can hint this with 4. Subquery decorrelation limits — TiDB handles most correlated subqueries through decorrelation, but deeply nested or multi-level correlated subqueries can fall back to row-by-row execution. Rewriting these as explicit JOINs with CTEs often gives the optimizer more room to parallelize. For those exploring SQL query patterns and wanting to understand how different query structures affect execution plans, ai2sql.io can be a useful learning tool — it converts natural language to SQL and helps visualize query structure choices. Disclosure: I'm involved in building this tool. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
原帖作者:gregbowers\n原帖时间:2025-02-07 09:12:20.210115\n原帖ID/Slug:10417 / optimizing-query-performance-in-tidb-cloud-serverless-tier\n\n
Hello
I have been testing TiDB Cloud’s Serverless Tier for a project and noticed that some complex queries take longer to execute than expected.
While TiDB’s distributed nature generally ensures good performance; certain JOIN operations and subqueries seem to slow things down significantly; especially when handling large datasets.
I have tried using EXPLAIN ANALYZE to identify bottlenecks & experimented with indexing strategies, but the improvements are minimal. Since the Serverless Tier automatically manages resources; I am wondering if there are additional optimizations specific to this environment, such as adjusting execution plans, caching strategies, or partitioning approaches that can help.
I checked https://www.pingcap.com/article/optimizing-tidb-performance-best-practices-and-case-studies/-java related to this and found it quite informative.
Has anyone successfully optimized query performance in TiDB Cloud Serverless?
Are there recommended best practices for structuring queries to take full advantage of TiDB’s distributed SQL engine? Any insights would be greatly appreciated!
Thank you !!
Beta Was this translation helpful? Give feedback.
All reactions