opt: constrain expression indexes with IS NULL expressions#83619
Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom Jul 11, 2022
Merged
opt: constrain expression indexes with IS NULL expressions#83619craig[bot] merged 1 commit intocockroachdb:masterfrom
craig[bot] merged 1 commit intocockroachdb:masterfrom
Conversation
Member
msirek
approved these changes
Jun 30, 2022
Contributor
msirek
left a comment
There was a problem hiding this comment.
Reviewed 3 of 3 files at r1, all commit messages.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on @rytaft)
The optimizer can generate constrained scans over indexes on computed
columns when columns referenced in the computed column expression are
held constant. Consider this example:
CREATE TABLE t (a INT, v INT AS (a + 1) STORED, INDEX v_idx (v))
SELECT * FROM t WHERE a = 1
A constrained scan can be generated over `v_idx` because `v` depends on
`a` and the query filter holds `a` constant.
This commit lifts a restriction that prevented this optimization when
columns referenced in the computed column expression were held constant
to the `NULL` value. As far as I can tell, this restriction is not
necessary. In fact, @rytaft had questioned its purpose originally, but
the question was never answered:
cockroachdb#43450 (review)
By lifting this restriction, the optimizer can explore constrained scans
over both indexed computed columns with `IS NULL` expressions and
expression indexes with `IS NULL` expressions.
Fixes cockroachdb#83390
Release note (performance improvement): The optimizer now explores more
efficient query plans when index computed columns and expressions have
`IS NULL` expressions.
a665c6e to
35e9737
Compare
Contributor
Author
|
@rytaft do you mind taking a look? Can you think of any reasons why the check I've removed is required? |
Contributor
Author
|
@rytaft friendly ping :) |
rytaft
approved these changes
Jul 11, 2022
Collaborator
rytaft
left a comment
There was a problem hiding this comment.
Reviewed 3 of 3 files at r1, all commit messages.
Reviewable status:complete! 2 of 0 LGTMs obtained (waiting on @mgartner)
Contributor
Author
|
TFTR! bors r+ |
Contributor
|
Build succeeded: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The optimizer can generate constrained scans over indexes on computed
columns when columns referenced in the computed column expression are
held constant. Consider this example:
A constrained scan can be generated over
v_idxbecausevdepends onaand the query filter holdsaconstant.This commit lifts a restriction that prevented this optimization when
columns referenced in the computed column expression were held constant
to the
NULLvalue. As far as I can tell, this restriction is notnecessary. In fact, @rytaft had questioned its purpose originally, but
the question was never answered:
#43450 (review)
By lifting this restriction, the optimizer can explore constrained scans
over both indexed computed columns with
IS NULLexpressions andexpression indexes with
IS NULLexpressions.Fixes #83390
Release note (performance improvement): The optimizer now explores more
efficient query plans when index computed columns and expressions have
IS NULLexpressions.