WIP: MDEV-38728 Improve join size estimation for ref access#4608
Open
WIP: MDEV-38728 Improve join size estimation for ref access#4608
Conversation
When estimating number of rows produced by a join after `ref` access,
the optimizer assumes all driving table values will find matches
in the inner table. This causes overestimation when the driving
table has more distinct values than the inner table's key.
Fix: use number of distinct values (NDV) for columns in the
join predicate to calculate match probability:
match_prob = min(1.0, NDV(inner) / NDV(driving))
The expected number of records after `ref` access is then multiplied
by match probability to provide more accurate estimate.
Limitations:
- EITS must be available for both columns in the join predicate
- both columns must be real table fields
- only single-column ref access is supported
- only first key part of the inner table's index is used
TODO:
- WHERE filter on the driving table may reduce NDV and affect estimation.
Currently, it is handled only basically
(driving_ndv must be <= number of records of current partial join)
This commit overwrites only those test results which have been verified,
i.e. provided better join size estimation. Other failing tests are not
yet verified.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When estimating number of rows produced by a join after
refaccess, the optimizer assumes all driving table values will find matches in the inner table. This causes overestimation when the driving table has more distinct values than the inner table's key.Fix: use number of distinct values (NDV) for columns in the join predicate to calculate match probability:
match_prob = min(1.0, NDV(inner) / NDV(driving))
The expected number of records after
refaccess is then multiplied by match probability to provide more accurate estimate.Limitations:
TODO:
This commit overwrites only those test results which have been verified, i.e. provided better join size estimation. Other failing tests are not yet verified.