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

opt: allow lookup joins to preserve index ordering with DESC columns #93673

Merged
merged 1 commit into from
Dec 16, 2022

Conversation

DrewKimball
Copy link
Collaborator

This patch fixes an oversight of #84689 that prevented lookup joins from maintaining the index ordering for each lookup if the index ordering contained descending columns. The execution logic will respect descending index columns as-is, so only the optimizer code needed to be changed. This will allow plans with lookup joins to avoid sorts in more cases.

Fixes #88319

Release note (performance improvement): The optimizer can now avoid planning a sort in more cases with joins that perform lookups into an index with one or more columns sorted in descending order. This can significantly decrease the number of rows that have to be scanned in order to satisfy a LIMIT clause.

@DrewKimball DrewKimball requested a review from a team as a code owner December 15, 2022 02:37
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@msirek msirek 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 7 of 7 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @mgartner and @yuzefovich)

Copy link
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

Nice! :lgtm:

Let's also backport this to 22.2 but after having it bake on master for like a week.

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


pkg/sql/opt/ordering/lookup_join.go line 218 at r1 (raw file):

// input of the lookup join. Additionally, the 'x' column alone is not a key
// for the 'xy' table, so each lookup may return multiple rows (which need
// to be ordered among themselves). Since the postfix of the ordering that

nit: I think using "suffix" instead of "postfix" is more common.

This patch fixes an oversight of cockroachdb#84689 that prevented lookup joins
from maintaining the index ordering for each lookup if the index ordering
contained descending columns. The execution logic will respect descending
index columns as-is, so only the optimizer code needed to be changed.
This will allow plans with lookup joins to avoid sorts in more cases.

Fixes cockroachdb#88319

Release note (performance improvement): The optimizer can now avoid
planning a sort in more cases with joins that perform lookups into an
index with one or more columns sorted in descending order. This can
significantly decrease the number of rows that have to be scanned in
order to satisfy a `LIMIT` clause.
Copy link
Collaborator Author

@DrewKimball DrewKimball left a comment

Choose a reason for hiding this comment

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

TFTRs!

Reviewable status: :shipit: complete! 2 of 0 LGTMs obtained (waiting on @mgartner)


pkg/sql/opt/ordering/lookup_join.go line 218 at r1 (raw file):

Previously, yuzefovich (Yahor Yuzefovich) wrote…

nit: I think using "suffix" instead of "postfix" is more common.

Done.

@DrewKimball
Copy link
Collaborator Author

bors r+

@craig
Copy link
Contributor

craig bot commented Dec 16, 2022

Build succeeded:

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.

Avoid sorts for descending ORDER BY on lookup join index columns
4 participants