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: constrain expression indexes with IS NULL expressions #83619

Merged
merged 1 commit into from
Jul 11, 2022

Conversation

mgartner
Copy link
Collaborator

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:

#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 #83390

Release note (performance improvement): The optimizer now explores more
efficient query plans when index computed columns and expressions have
IS NULL expressions.

@mgartner mgartner requested review from rytaft and msirek June 29, 2022 21:39
@mgartner mgartner requested a review from a team as a code owner June 29, 2022 21:40
@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_strong:

Reviewed 3 of 3 files at r1, all commit messages.
Reviewable status: :shipit: 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.
@mgartner mgartner force-pushed the 83390-fix-is-null-expression branch from a665c6e to 35e9737 Compare July 1, 2022 14:27
@mgartner
Copy link
Collaborator Author

mgartner commented Jul 5, 2022

@rytaft do you mind taking a look? Can you think of any reasons why the check I've removed is required?

@mgartner
Copy link
Collaborator Author

mgartner commented Jul 8, 2022

@rytaft friendly ping :)

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: Thanks! Sorry for the delay!

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

@mgartner
Copy link
Collaborator Author

TFTR!

bors r+

@craig
Copy link
Contributor

craig bot commented Jul 11, 2022

Build succeeded:

@craig craig bot merged commit c16f589 into cockroachdb:master Jul 11, 2022
@mgartner mgartner deleted the 83390-fix-is-null-expression branch July 11, 2022 19:04
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.

optimizer not take into account expression index (even with index hinting)
4 participants