Open michae2 opened 4 months ago
Best idea I've had so far is to turn NormalizeCmpPlusConst
into an exploration rule.
We run into similar problems when these types of virtual computed columns (i.e., ones with simple arithmetic operators that are likely to be normalized) are referenced in partial index predicates. They can prevent us from proving partial index implication. See #123163 which is somewhat relevant.
Best idea I've had so far is to turn NormalizeCmpPlusConst into an exploration rule.
Another option would be to try to denormalize expressions into computed column expressions when building constraints and proving implication.
Usually
GenerateConstrainedScans
is able to turn a filter on a computed column into a constrained scan of an index on that computed column. Here's a simple example:Produces the constrained scan we expect:
But if I change the expression from
PK % 10
toPK + 1
, thenNormalizeCmpPlusConst
simplifies the filter to a constantc > 4
and this messes up some part ofGenerateConstrainedScans
:Produces a full scan and a filter:
Interestingly, if I change the query to use equality instead of an inequality it is able to generate a constrained scan:
Produces:
This behavior reproduces on both v23.2.0 and tip of master (v24.1.0-alpha.2).
Jira issue: CRDB-36337