Skip to content

expr: fix non-injective text_to_"char"/text_to_bytea uniqueness annotation#36663

Merged
def- merged 1 commit into
MaterializeInc:mainfrom
def-:pr-literal-constraints
May 21, 2026
Merged

expr: fix non-injective text_to_"char"/text_to_bytea uniqueness annotation#36663
def- merged 1 commit into
MaterializeInc:mainfrom
def-:pr-literal-constraints

Conversation

@def-
Copy link
Copy Markdown
Contributor

@def- def- commented May 21, 2026

These casts were marked preserves_uniqueness = true, but neither is injective: text_to_"char" keeps only the first byte (so 'a' and 'abc' collapse to the same "char"), and text_to_bytea accepts both hex and traditional encodings for the same bytes. The annotation made invert_casts_on_expr_eq_literal_inner rewrite col::text = lit to col = f_inv(lit), which can match rows whose col::text does not actually equal lit — producing wrong query answers via MFP canonicalization and index literal-constraint lookups.

…ation

These casts were marked `preserves_uniqueness = true`, but neither is
injective: `text_to_"char"` keeps only the first byte (so 'a' and 'abc'
collapse to the same `"char"`), and `text_to_bytea` accepts both hex
and traditional encodings for the same bytes. The annotation made
`invert_casts_on_expr_eq_literal_inner` rewrite `col::text = lit` to
`col = f_inv(lit)`, which can match rows whose `col::text` does not
actually equal `lit` — producing wrong query answers via MFP
canonicalization and index literal-constraint lookups.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@def- def- requested a review from ggevay May 21, 2026 02:57
@def- def- requested a review from a team as a code owner May 21, 2026 02:57
Copy link
Copy Markdown
Contributor

@ggevay ggevay left a comment

Choose a reason for hiding this comment

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

Nice catches!

@def- def- merged commit 07cd068 into MaterializeInc:main May 21, 2026
118 checks passed
@def- def- deleted the pr-literal-constraints branch May 21, 2026 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants