Skip to content

fix(sql): strip a table's own qualifier in every predicate shape - #493

Draft
EnRaiha wants to merge 2 commits into
NodeDB-Lab:mainfrom
EnRaiha:fix/own-qualifier-all-predicate-shapes
Draft

EnRaiha wants to merge 2 commits into
NodeDB-Lab:mainfrom
EnRaiha:fix/own-qualifier-all-predicate-shapes

Conversation

@EnRaiha

@EnRaiha EnRaiha commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

WHERE u1.id IN ('a', 'b'), NOT IN, BETWEEN and LIKE matched zero rows on a single-table query. The planner strips the table's own qualifier before it builds a filter, but the walk read only comparisons, AND, OR, NOT, parentheses and IS NULL. Any other shape kept the qualified name as a field name, which no stored document has. The check that refuses a qualifier naming another table had the same gap, so wrong.id IN (...) also matched nothing instead of failing.

Both walks now visit every expression shape, including function arguments, CASE and CAST. A subquery body keeps its own qualifiers.

`WHERE u1.id IN ('a', 'b')`, `NOT IN`, `BETWEEN` and `LIKE` matched zero
rows on a single-table query. The planner strips the table's own
qualifier before it builds a filter, but the walk read only comparisons,
`AND`, `OR`, `NOT`, parentheses and `IS NULL`. Any other shape kept the
qualified name as a field name, which no stored document has. The check
that refuses a qualifier naming another table had the same gap, so
`wrong.id IN (...)` also matched nothing instead of failing.

Both walks now visit every expression shape, including function
arguments, `CASE` and `CAST`. A subquery body keeps its own qualifiers.
UPDATE (no FROM) and DELETE never ran the WHERE through the
qualifier-stripping walk SELECT, UPDATE ... FROM and MERGE all share.
WHERE orders.status = 1 built a filter keyed literally 'orders.status',
which no stored document has -- a WHERE this shape silently matched no
row, so the statement touched nothing, with no error.

Both now compute the valid qualifier the same way UPDATE ... FROM's
target_ref already does: the alias once the table is aliased, else the
table's own name, then strip it through strip_and_convert_filters
before building filters. A qualifier naming neither is refused as a
typed error, not a silent no-op, matching every other statement kind.

This branch has not been deployed

No deployments
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.

1 participant