Skip to content

sql: a NULL comparison or key matches no row in reads and DML - #501

Draft
EnRaiha wants to merge 2 commits into
NodeDB-Lab:mainfrom
EnRaiha:fix/indexed-eq-null
Draft

EnRaiha wants to merge 2 commits into
NodeDB-Lab:mainfrom
EnRaiha:fix/indexed-eq-null

Conversation

@EnRaiha

@EnRaiha EnRaiha commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

col = NULL matches no row, in reads and in DML.

The index lookup rewrite took the NULL literal as the key "", and a point key did the same. A plain fallback to a scan is not enough, because the scan filter matches a stored NULL against a NULL literal. A comparison with a NULL literal now never matches on the fallback paths.

What changed

  • Index lookup and point get plan no key for a NULL literal.
  • The scan filter, the columnar mask, the scan-side filter and the vector prefilter treat the comparison as never matching.
  • UPDATE and DELETE by a NULL key leave the row with a NULL key alone.
  • A positive IN list drops its NULL members. A list of only NULL matches no row.

Behaviour on document_strict and document_schemaless

Statement Result
WHERE tag = NULL, WHERE NULL = tag, indexed or not no rows
WHERE id = 'b' AND tag = NULL no rows
DELETE ... WHERE tag = NULL the NULL row stays

On a schemaless collection with no declared primary key:

Statement Result
WHERE id = NULL no rows
UPDATE ... WHERE id IN ('a', NULL) only row a changes
DELETE ... WHERE id = NULL no row removed

Checks

  • Targeted unit and SQL suite tests: pass.
  • pgwire probes of the statements above: pass, on a tree that also holds other open work on main.
  • Preflight, including clippy: pass.

Not run: full wire suite, dml_suite, common_suite. Not probed over pgwire: KV, columnar and timeseries, and the HTTP, WebSocket and native routes.

`col = NULL` matches no row. The lookup rewrite took the NULL literal as
the key "" and returned rows holding an empty string. The equality now
stays a filter, so the scan path decides it.
A comparison with a NULL literal is unknown. The indexed equality, the scan
filter, the columnar mask, the scan-side filter and the vector prefilter
treat it as never matching. A NULL key plans no point lookup, and its
fallback filter never matches, so UPDATE and DELETE leave a row with a NULL
key alone.
@EnRaiha EnRaiha changed the title sql: a NULL literal equality offers no index lookup sql: a NULL comparison or key matches no row in reads and DML Nov 25, 2026

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