Skip to content

fix(qual): use operator commutator when swapping operands in WHERE clauses - #646

Open
Vishv07 wants to merge 1 commit into
supabase:mainfrom
Vishv07:fix/qual-swap-operands-commutator
Open

fix(qual): use operator commutator when swapping operands in WHERE clauses#646
Vishv07 wants to merge 1 commit into
supabase:mainfrom
Vishv07:fix/qual-swap-operands-commutator

Conversation

@Vishv07

@Vishv07 Vishv07 commented Sep 4, 2026

Copy link
Copy Markdown

Summary

Fixes #643

Problem: When extracting WHERE clauses with constants on the left (e.g. 100 > price), operand swapping kept the original operator instead of its commutator. This pushed inverted operators to remote systems (e.g. price > 100 instead of price < 100), returning incorrect results.

Fix: Update opr with get_operator((*opr).oprcom) when operands are swapped, ensuring the correct commuted operator is used (e.g. < for >, <= for >=, <@ for @>).

…auses

When an OpExpr comparison has the constant on the left and the column on
the right (e.g. `WHERE 100 > price` or `WHERE '2026-06-01' BETWEEN valid_from AND valid_to`),
extract_from_op_expr swaps the operands so the column becomes the Qual field.
However, it previously kept the original operator without looking up its
commutator via `oprcom`. As a result, the inverted operator was pushed
down to remote systems (e.g. `price > 100` instead of `price < 100`),
causing queries to return empty or incorrect results.

Update `opr` with `get_operator((*opr).oprcom)` when operands are swapped.

Fixes supabase#643
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.

extract_from_op_expr keeps the original operator after swapping operands

1 participant