-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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: constrain expression indexes with IS NULL expressions #83619
opt: constrain expression indexes with IS NULL expressions #83619
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@rytaft do you mind taking a look? Can you think of any reasons why the check I've removed is required? |
@rytaft friendly ping :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 3 of 3 files at r1, all commit messages.
Reviewable status: complete! 2 of 0 LGTMs obtained (waiting on @mgartner)
TFTR! bors r+ |
Build succeeded: |
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_idx
becausev
depends ona
and the query filter holdsa
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 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 NULL
expressions andexpression indexes with
IS NULL
expressions.Fixes #83390
Release note (performance improvement): The optimizer now explores more
efficient query plans when index computed columns and expressions have
IS NULL
expressions.