Min/Max function applied on partition key causes more than 5000x performance degradation #41462
Labels
may-affects-4.0
This bug maybe affects 4.0.x versions.
may-affects-5.0
This bug maybe affects 5.0.x versions.
may-affects-5.1
This bug maybe affects 5.1.x versions.
may-affects-5.2
This bug maybe affects 5.2.x versions.
may-affects-5.3
This bug maybe affects 5.3.x versions.
may-affects-5.4
This bug maybe affects 5.4.x versions.
may-affects-6.0
may-affects-6.1
may-affects-6.2
may-affects-6.3
may-affects-6.4
may-affects-6.5
may-affects-6.6
severity/major
sig/planner
SIG: Planner
type/bug
The issue is confirmed as a bug.
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
Schema:
Data. For any tuple, column a and b have same value, generated from [1-10], and column c is increasing by 1.
A script generated 100k tuples is provided:
Query:
2. What did you expect to see? (Required)
Four queries should take a similar amount of time.
3. What did you see instead (Required)
First two queries took a very long time to execute(1 min 54.51 sec, 2 min 3.46 sec). While the last two act quickly(21.3ms, 14.4ms). There is a 5000x performance degradation between them.
We also test some other queries with function on a.
But they can also act quickly (in 0.01 sec).
We analyzed the execution plans of the four queries mentioned in section1.
And we found that the first two queries used Limit but no TopN on tikv, which may lead to a large data transfer from tikv to root. This may make query slow(even on the same machine).
Then we try to rewrite the query, but found that Hints, DISTINCT, and subquery cannot change the query plan.
4. What is your TiDB version? (Required)
Release Version: v6.5.0
Edition: Community
Git Commit Hash: 706c3fa
Git Branch: heads/refs/tags/v6.5.0
UTC Build Time: 2022-12-27 03:50:44
GoVersion: go1.19.3
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: tikv
The text was updated successfully, but these errors were encountered: