Concurrent Reads Execute Slowly

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 并发读执行慢

| username: jiangh

We have a relatively simple read SQL that can produce results in just over 1 second when executed individually. However, when this SQL is executed concurrently, it takes more than 20 seconds, but the data load does not significantly increase during concurrent execution. Is there any way to optimize the SQL execution time?

| username: Billmay表妹 | Original post link

[Resource Allocation] Go to TiDB Dashboard - Cluster Info - Hosts and take a screenshot of this page

Please post this.

| username: jiangh | Original post link

Sorry, I can’t translate the content from the image. Please provide the text you need translated.

| username: Billmay表妹 | Original post link

When the execution time of an SQL query significantly increases during concurrent execution, but the data load does not noticeably rise, you can try the following methods to optimize the SQL execution time:

  1. Check Indexes: Ensure that the relevant fields in the table have appropriate indexes. Indexes can speed up queries and reduce execution time. You can use the EXPLAIN command to view the SQL execution plan and confirm whether the correct indexes are being used.

  2. Adjust Concurrency: Try adjusting the number of threads for concurrent execution by modifying the database configuration parameters. Increasing concurrency appropriately can enhance the concurrent execution capability of queries and reduce execution time.

  3. Optimize SQL Statements: Check if the SQL statements can be optimized, such as using more suitable query methods, avoiding unnecessary subqueries, and reducing the data scan range. You can find potential optimization points by analyzing the SQL execution plan and query logs.

  4. Database Parameter Tuning: Adjust the database configuration parameters as needed, such as adjusting cache size and query optimizer parameters. Determine the parameters that need adjustment based on database performance metrics and monitoring data.

  5. Database Version Upgrade: If you are using an older database version, consider upgrading to the latest version. New versions typically include performance optimizations and bug fixes that may improve query execution performance.

Please note that optimizing SQL execution time is a comprehensive task that requires adjustments based on specific business scenarios and database configurations. It is recommended to try these methods according to your actual situation and conduct performance testing and monitoring during the optimization process to ensure the effectiveness and stability of the optimizations.

| username: jiangh | Original post link

Looking at the monitoring, this metric coincides with the period when the SQL slows down. Is there any way to optimize it?

| username: 路在何chu | Original post link

Let’s compare the execution plans for concurrent execution of 20 seconds and 1 second to see where the differences lie.

| username: jiangh | Original post link

The execution plans are exactly the same.

| username: 大飞哥online | Original post link

Take a look at the EXPLAIN ANALYZE results to see where the 20 seconds of execution time is being spent.

| username: jiangh | Original post link

Sorry, I can’t assist with that.

| username: jiangh | Original post link

The image you provided is not visible. Please provide the text you need translated.

| username: hey-hoho | Original post link

Please provide the complete execution plan.

At first glance, the two 120K table lookups are putting a lot of pressure on the read pool. We need to consider the rationality of these two indexes.

| username: jiangh | Original post link

Is there a way to execute the subquery first? Currently, the filter on table b is executed first, and then it joins with table c. The filter result of table b is 120,000, while the subquery result is only a few.

| username: jiangh | Original post link

Collected some statistics, it’s good now.

| username: Fly-bird | Original post link

Check the dashboard to see if there are any slow SQL queries.

| username: jiangh | Original post link

Of course there is, no need to ask.

| username: zhanggame1 | Original post link

Is it an execution plan issue?

| username: jiangh | Original post link

Well, the statistics are inaccurate, leading to an incorrect execution plan.

| username: 大飞哥online | Original post link

It is still necessary to regularly run the statistics.

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.