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

sql: improved partial index implication with virtual columns #61565

Open
RaduBerinde opened this issue Mar 5, 2021 · 3 comments
Open

sql: improved partial index implication with virtual columns #61565

RaduBerinde opened this issue Mar 5, 2021 · 3 comments
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-queries SQL Queries Team

Comments

@RaduBerinde
Copy link
Member

RaduBerinde commented Mar 5, 2021

The issue tracks figuring out how to prove implication (and thus enable the use of the partial index) for cases like:

CREATE TABLE t (
  k INT PRIMARY KEY,
  a INT,
  b INT,
  c INT AS (b + 10) VIRTUAL,
  INDEX (a) WHERE c IN (10, 20, 30)
)

SELECT k FROM t WHERE c = 20

Jira issue: CRDB-2993

@RaduBerinde RaduBerinde added the C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. label Mar 5, 2021
@jlinder jlinder added the T-sql-queries SQL Queries Team label Jun 16, 2021
@github-actions
Copy link

We have marked this issue as stale because it has been inactive for
18 months. If this issue is still relevant, removing the stale label
or adding a comment will keep it active. Otherwise, we'll close it in
10 days to keep the issue queue tidy. Thank you for your contribution
to CockroachDB!

@yuzefovich
Copy link
Member

cc @mgartner has this been addressed?

@mgartner mgartner changed the title sql: improved partial index handling with virtual columns sql: improved partial index implication with virtual columns May 2, 2024
@mgartner
Copy link
Collaborator

mgartner commented May 2, 2024

This was fixed for some cases in #123163. However, the specific case mentioned in this issue has not been fixed. See: https://github.com/mgartner/cockroach/blob/3aa3d6f135cf09bae622747d670a22c94e781785/pkg/sql/opt/partialidx/testdata/implicator/false-negative#L53-L60

# We do not prove implication in this case because a + 10 > 4 is normalized to
# a > -6 before a + 10 can be replaced with b.
predtest vars=(a int, b int as (a + 10) virtual)
a + 10 > 4
=>
a + 10 IS NOT NULL
----
false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-queries SQL Queries Team
Projects
Status: Backlog
Development

No branches or pull requests

4 participants