fix(qual): use operator commutator when swapping operands in WHERE clauses - #646
Open
Vishv07 wants to merge 1 commit into
Open
fix(qual): use operator commutator when swapping operands in WHERE clauses#646Vishv07 wants to merge 1 commit into
Vishv07 wants to merge 1 commit into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 > 100instead ofprice < 100), returning incorrect results.Fix: Update
oprwithget_operator((*opr).oprcom)when operands are swapped, ensuring the correct commuted operator is used (e.g.<for>,<=for>=,<@for@>).