Skip to content

Conversation

Uzair5162
Copy link
Contributor

We normalize symmetric RangeCond expressions (<left> BETWEEN SYMMETRIC <from> AND <to>) by expanding them into 2 pairs of ComparisonExpr, covering both orderings of the BETWEEN bounds. When the type-checks for the left/from and left/to comparisons chose different coercions, the symmetric half could pair leftFrom with to (and leftTo with from) during normalization. This resulted in mixed-type comparisons on type-checked expressions and caused panics in some paths (e.g. AOST normalization).

This change ensures that the type-checked pairings are kept aligned when constructing ComparisonExpr in the symmetric case.

Fixes: #133395

Release note (bug fix): Previously, executing certain statements with BETWEEN SYMMETRIC expressions could panic if used with values of different types, such as ... b'bytes' BETWEEN SYMMETRIC 'a' AND 'c', which is now fixed.

We normalize symmetric `RangeCond` expressions (`<left> BETWEEN
SYMMETRIC <from> AND <to>`) by expanding them into 2 pairs of
`ComparisonExpr`, covering both orderings of the BETWEEN bounds. When
the type-checks for the left/from and left/to comparisons chose
different coercions, the symmetric half could pair `leftFrom` with
`to` (and `leftTo` with `from`) during normalization. This resulted in
mixed-type comparisons on type-checked expressions and caused panics in
some paths (e.g. AOST normalization).

This change ensures that the type-checked pairings are kept aligned when
constructing `ComparisonExpr` in the symmetric case.

Fixes: cockroachdb#133395

Release note (bug fix): Previously, executing certain statements with
`BETWEEN SYMMETRIC` expressions could panic if used with values of
different types, such as `... b'bytes' BETWEEN SYMMETRIC 'a' AND 'c'`,
which is now fixed.
@Uzair5162 Uzair5162 requested a review from a team August 15, 2025 21:38
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@Uzair5162 Uzair5162 requested review from mw5h and a team and removed request for a team August 15, 2025 21:39
Copy link
Contributor

@mw5h mw5h left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: Great job, thanks!

@mw5h reviewed 3 of 3 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @Uzair5162)

@Uzair5162
Copy link
Contributor Author

bors r+

@craig
Copy link
Contributor

craig bot commented Aug 20, 2025

@craig craig bot merged commit 9f25778 into cockroachdb:master Aug 20, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sql: CockroachDB panics when executing SELECT statement with JOIN and ill-formed AS FOR SYSTEM TIME
3 participants