indexrec: improve ordering recommendations #73565
Merged
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.
Previously, in order to avoid redundant recommendations, we standardized the
index candidate creation for *memo.SortExprs, or ordering candidates. More
specifically, if the recommendation query contained
ORDER BY k DESC, i ASC
we would create an index candidate with the key (k, i DESC), allowing for a
reverse scan of the index. Since reverse scans are less efficient than
forward scans, this is not ideal.
In this commit, we no longer standardize ordering recommendations. We always
create the sort candidate according to how it is in the query.
There is no handling for redundant recommendations (meaning recommending an
index on
(k ASC)
and(k DESC)
). Since queries usually only have oneORDER BY
clause, it doesn't seem like an important case to consider.Plus, through experimentation, it seems that when there are redundant
candidates, (only possible for single column indexes), there is no redundant
recommendation. See tests added in this PR.
Fixes: #73451.
Release note: None