Skip to content

Commit

Permalink
Merge #59499 #59594
Browse files Browse the repository at this point in the history
59499: opt: scan partial indexes with virtual columns in predicate r=mgartner a=mgartner

This commit makes it possible for the optimizer to generate scans on
partial indexes with predicates that have references to virtual columns.
When partial index predicate expressions are added to table metadata,
virtual column expressions are inlined. This allows implication to be
proven by a query filter with virtual columns that have also been
inlined by the PushSelectIntoInlinableProject rule.

Unfortunately, this only supports query filters that have expressions
that exactly match the partial index predicate. Partial index
implication is not guaranteed to be proven for queries that imply
a partial index predicate in theory, but do not have exactly matching
expressions. For example:

    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

The virtual column in the query filter `c = 20` is inlined to
`(b + 10) = 20` and the expression is normalized to `b = 10`. The
virtual column in the partial index `c IN (10, 20, 30)` is normalized to
`(b + 10) IN (10, 20, 30)`. Implication cannot easily be proven for the
filter `b = 10` and the predicate `(b + 10) IN (10, 20, 30)`.

Release note: None

59594: opt: remove unused inverted index logic in idxconstraint r=mgartner a=mgartner

Constraining inverted indexes is now done with InvertedConstraints.
Logic in idxconstraint for generating Constraints for inverted indexes
is no longer used and has been removed.

Release note: None

Co-authored-by: Marcus Gartner <[email protected]>
  • Loading branch information
craig[bot] and mgartner committed Jan 29, 2021
3 parents ac799bd + 95d550b + 6e2cc52 commit 171cc86
Show file tree
Hide file tree
Showing 16 changed files with 206 additions and 551 deletions.
2 changes: 0 additions & 2 deletions pkg/sql/opt/idxconstraint/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ go_library(
"//pkg/sql/sem/tree",
"//pkg/sql/types",
"//pkg/util",
"//pkg/util/json",
"//pkg/util/log",
"@com_github_cockroachdb_errors//:errors",
],
)
Expand Down
Loading

0 comments on commit 171cc86

Please sign in to comment.