Skip to content

opt: support SplitScanIntoUnionScans for exclusive constraint boundaries#65350

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
rytaft:inclusive-boundary
May 18, 2021
Merged

opt: support SplitScanIntoUnionScans for exclusive constraint boundaries#65350
craig[bot] merged 1 commit intocockroachdb:masterfrom
rytaft:inclusive-boundary

Conversation

@rytaft
Copy link
Copy Markdown
Collaborator

@rytaft rytaft commented May 17, 2021

This commit adds support for applying the SplitScanIntoUnionScans
rule in some cases if the constraint boundary is exclusive. For example,
prior to this commit, SplitScanIntoUnionScans did not apply for the following
query, even if an index was available on (x, y):

  SELECT x, y FROM tab
  WHERE (x = 0 OR x = 10) AND y IS NOT NULL
  ORDER BY y LIMIT 10

This was because the index constraint, (/0/NULL - /0] (/10/NULL - /10], had an
exclusive boundary. This commit adds support for applying the rule in such
cases, as long as the prefix length is shorter than the key length. In this
case, the prefix length is 1 (for column x), and the key with the exclusive
boundary has length 2, so it is valid to apply SplitScanIntoUnionScans.

Release note (performance improvement): The optimizer can now avoid
full table scans for queries with a LIMIT and ORDER BY clause in some
additional cases where the ORDER BY columns are not a prefix of an index.

@rytaft rytaft requested review from a team and DrewKimball May 17, 2021 19:34
This commit adds support for applying the SplitScanIntoUnionScans
rule in some cases if the constraint boundary is exclusive. For example,
prior to this commit, SplitScanIntoUnionScans did not apply for the following
query, even if an index was available on (x, y):

  SELECT x, y FROM tab
  WHERE (x = 0 OR x = 10) AND y IS NOT NULL
  ORDER BY y LIMIT 10

This was because the index constraint, (/0/NULL - /0] (/10/NULL - /10], had an
exclusive boundary. This commit adds support for applying the rule in such
cases, as long as the prefix length is shorter than the key length. In this
case, the prefix length is 1 (for column x), and the key with the exclusive
boundary has length 2, so it is valid to apply SplitScanIntoUnionScans.

Release note (performance improvement): The optimizer can now avoid
full table scans for queries with a LIMIT and ORDER BY clause in some
additional cases where the ORDER BY columns are not a prefix of an index.
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Contributor

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

Cool! :lgtm_strong:

Reviewed 3 of 3 files at r1.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @DrewKimball)

Copy link
Copy Markdown
Collaborator

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

Great catch!

Copy link
Copy Markdown
Collaborator Author

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

TFTRs!

bors r+

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

@craig
Copy link
Copy Markdown
Contributor

craig bot commented May 18, 2021

Build succeeded:

@craig craig bot merged commit 65f685b into cockroachdb:master May 18, 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.

4 participants