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: use partial indexes for lookup joins #54157

Merged
merged 1 commit into from
Sep 10, 2020

Conversation

mgartner
Copy link
Collaborator

@mgartner mgartner commented Sep 9, 2020

Lookup joins are now generated when the ON filters of a join or the
right-side Select filters imply the partial index predicate.

In several cases, the filters are reduced once implication is proven.
This currently prevents optimal plans from being generated in several
cases, either because unnecessary joins remaining in the expression
tree, or because lookup semi- and anti-joins that should be created are
not. I've left TODOs to denote these cases.

Fixes #50227

Release note (performance improvement): The optimizer can now use
partial indexes for lookup join operations. This results in potentially
more efficient query plans for joins on tables with partial indexes.

@mgartner mgartner requested a review from a team as a code owner September 9, 2020 23:27
@cockroach-teamcity
Copy link
Member

This change is Reviewable

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 4 of 4 files at r1.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @mgartner and @RaduBerinde)


pkg/sql/logictest/testdata/logic_test/partial_index, line 1005 at r1 (raw file):

CREATE TABLE join_small (m INT, n INT);
CREATE TABLE join_large (i INT, s STRING, INDEX (i) WHERE s IN ('foo', 'bar', 'baz'));
ALTER TABLE join_small INJECT STATISTICS '[

in case we ever decide to re-enable automatic stats for the logic tests... I'd add SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false here. You could also just force the lookup join using a LOOKUP JOIN hint.


pkg/sql/opt/xform/testdata/rules/join, line 3030 at r1 (raw file):


# --------------------------------------------------
# GenerateLookupJoinsWithFilter + Partial Indexes

how about adding at least one test where the filters don't imply the index predicate?

Lookup joins are now generated when the ON filters of a join or the
right-side Select filters imply the partial index predicate.

In several cases, the filters are reduced once implication is proven.
This currently prevents optimal plans from being generated in several
cases, either because unnecessary joins remaining in the expression
tree, or because lookup semi- and anti-joins that should be created are
not. I've left TODOs to denote these cases.

Release note (performance improvement): The optimizer can now use
partial indexes for lookup join operations. This results in potentially
more efficient query plans for joins on tables with partial indexes.
Copy link
Collaborator Author

@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.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @RaduBerinde and @rytaft)


pkg/sql/logictest/testdata/logic_test/partial_index, line 1005 at r1 (raw file):

Previously, rytaft (Rebecca Taft) wrote…

in case we ever decide to re-enable automatic stats for the logic tests... I'd add SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false here. You could also just force the lookup join using a LOOKUP JOIN hint.

I've disabled automatic stats collection because for the last two test cases (which I removed but will re-add when they perform lookup joins) they cannot use join hints AFAIK.


pkg/sql/opt/xform/testdata/rules/join, line 3030 at r1 (raw file):

Previously, rytaft (Rebecca Taft) wrote…

how about adding at least one test where the filters don't imply the index predicate?

good idea. done.

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.

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

Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @RaduBerinde)

@mgartner
Copy link
Collaborator Author

TFTRs!

bors r+

@craig
Copy link
Contributor

craig bot commented Sep 10, 2020

Build succeeded:

@craig craig bot merged commit 849df69 into cockroachdb:master Sep 10, 2020
@mgartner mgartner deleted the lookup-join branch September 10, 2020 22:51
@rafiss rafiss added this to the 20.2 milestone Apr 22, 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.

opt: utilize partial indexes for lookup joins
5 participants