sql: prevent unsafe comparison constant unification - #172989
Conversation
|
Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR. Before a member of our team reviews your PR, I have some potential action items for you:
I have added a few people who may be able to assist in reviewing:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
|
Review focus: please validate the intentionally conservative The regression covers both paths from #172978 (scalar/ANY INT8-vs-FLOAT8 and prepared TIMESTAMP/TIMESTAMPTZ after a time-zone change). Local full test execution is blocked by the machine's unavailable WSL/Docker disk, as described in the PR body. |
Summary
Fixes #172978.
UnifyComparisoncould replace a mixed-type comparison with one against a converted constant even when the comparison's implicit cast collapses distinct column values. This caused INT8 values above 2^53 to be missed when compared to a FLOAT8 constant. It also performed stable casts without consultingFoldingControl, allowing session-time-zone-dependent TIMESTAMP to TIMESTAMPTZ conversions to be baked into prepared plans.This change only permits the rewrite when the variable-to-original conversion is injective, and consults cast volatility through
FoldingControlbefore evaluating either cast. It adds logic tests for scalar and ANY comparisons and for prepared statements across a time-zone change.Validation
git diff --checkgo test ./pkg/sql/opt/normis not supported in this checkout without Bazel-generated protobuf packages.