Skip to content
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

indexrec: improve ordering recommendations #73565

Merged
merged 1 commit into from
Dec 16, 2021

Conversation

nehageorge
Copy link

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 one
ORDER 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

@nehageorge nehageorge requested a review from a team as a code owner December 7, 2021 19:59
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@nehageorge nehageorge requested review from mgartner and rytaft December 7, 2021 19:59
Copy link
Collaborator

@rytaft rytaft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @mgartner)

Copy link
Collaborator

@mgartner mgartner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r2, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @nehageorge)

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 one
ORDER 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: cockroachdb#73451.

Release note: None
@nehageorge
Copy link
Author

TFTRs!

bors r+

@craig
Copy link
Contributor

craig bot commented Dec 16, 2021

Build succeeded:

@craig craig bot merged commit d05ec98 into cockroachdb:master Dec 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

indexrec: improve ordering recommendations
4 participants