-
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
Optimizer choose full table scan when there is a better execution path #56321
Comments
I'm able to reproduce the problem using this script to generate test data: https://gist.github.com/mzhang77/a7cb08949d8473edbde4a27bde0d3530 |
Cost for default choice
Cost for index join choice
Cost for hash join choice
|
@mzhang77 From the explain result, when we push a top-n down to the outer join's outer child. We'll remove the offset and make a full TopN |
@mzhang77 So currently, both sides will use 19000 rows to calculate the cost. Oh, but I noticed that your join key from the inner side is the primary key, so this can ensure each match of the outer side is exactly one. So the total execution logic can be improved maybe. If the join key doesn't have the unique property, i'm afraid that the execution logic and the estimation logic will not change. |
@winoros This is a real case from a paid customer. Actually in their application all join key has unique property. |
i know. i just want to explain the current situation and the possible improvment tidb can do. |
Bug Report
1. Minimal reproduce step (Required)
2. What did you expect to see? (Required)
The execution plan should use table
i
as driving table to access tabled
3. What did you see instead (Required)
The problem is captured by slow log, it is not reproducible any more.
The issue with this plan is, there is no need to full table scan
d
. Optimizer should offset 18000 rows fromi
, take the next 1000 rows, and join them to tabled
. So maybe full table scani
is necessary, but full table scand
to do a merge join is unnecessary.4. What is your TiDB version? (Required)
v7.5.1
The text was updated successfully, but these errors were encountered: