-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Analyze is too slow when run dml in million tables scenario #57631
Comments
During the analysis process, stats are expected to be collected from TiKV and stored in TiDB. Additionally, the stats cache needs to be updated to ensure it reflects the latest stats flushed to TiDB. This guarantees that users can execute SQL queries on the table immediately after the stats collection is completed. For this issue, the problem originates from the stats cache updating process. As you can tell from here:
TiDB queries all updated stats metadata from the system table and processes them one by one. In this case, with more than 100k tables being updated simultaneously, this results in a bulk read. Processing them one by one significantly impacts performance, making it even worse. As a result, you can see that analyzing a table takes a very long time, as it gets stuck at the final step of updating the stats cache. To address this problem, we can do two things to reduce the duration. We can limit the number of tables processed at a time. In this case, throughput isn’t a major concern, and a delay of a few minutes is acceptable. Adding a The reason we need to load the latest stats into the cache is to ensure that the most relevant stats are immediately available after the analysis. We don’t want to compromise this guarantee. However, we can improve the performance of this process by updating only the stats for tables that have been modified, rather than reloading stats for all tables. This approach will significantly enhance performance. I have verified the short-term solution in this cluster, it worked very well. Check my changes at #57638. |
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
It takes about 3 seconds if not having dml workload
2. What did you expect to see? (Required)
3. What did you see instead (Required)
4. What is your TiDB version? (Required)
master
Release Version: v8.5.0
Edition: Community
Git Commit Hash: eb871f8
Git Branch: heads/refs/tags/v8.5.0
UTC Build Time: 2024-11-22 03:01:24
GoVersion: go1.23.3
Race Enabled: false
Check Table Before Drop: false
Store: tikv
The text was updated successfully, but these errors were encountered: