WIP: MDEV-38728 Improve join size estimation for ref access #4608
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.