Repository navigation
fix(scan): do not crash on a NULL query vector - #378
Draft
pavanmanishd wants to merge 1 commit into
Draft
pavanmanishd wants to merge 1 commit into
pavanmanishd wants to merge 1 commit into
Conversation
pavanmanishd
force-pushed
the
bugfix/null-query-vector
branch
3 times, most recently
from
October 18, 2026 22:38
5083fac to
0502a9f
Compare
An ORDER BY argument that evaluates to NULL, such as a subquery that matched no row, reached the distance code as a NULL datum and segfaulted the backend in pg_detoast_datum. Every row compares equal to a NULL, so any order satisfies the query; search with a fixed unit vector instead and return arbitrary rows, which is what a sequential scan does with the same expression. One difference from a sequential scan remains, and is inherent to an approximate index: rows whose indexed column is NULL are not in the index, so a NULL-argument scan returns fewer rows than the sequential scan would whenever the query wants more rows than the indexed ones provide. The unit vector is built as float32 directly rather than through the opclass input type, so a vec16 index gets the same vector instead of a float32 buffer read as half-floats, and it is cached in the scan context so a rescan does not rebuild it. Adds regression coverage: the plan is pinned and the statement executed through generic prepared plans for both the L2 and cosine opclasses, and a LATERAL top-k covers the rescan path.
pavanmanishd
force-pushed
the
bugfix/null-query-vector
branch
from
October 19, 2026 10:01
0502a9f to
3922b84
Compare
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.
Fixes #377.
An ORDER BY argument that evaluates to NULL — a subquery that matched no row, a parameter a client bound — reached the distance code as a NULL datum and segfaulted the backend in
pg_detoast_datum. Every row compares equal to a NULL, so any order satisfies the query: the scan now searches with a fixed unit vector and returns arbitrary rows, which is what a sequential scan does with the same expression.Two details worth knowing. The substitute is built as float32 directly rather than through the opclass input type, so a vec16 index gets the same vector instead of a float32 buffer read as half-floats, and it is cached in the scan context so a rescan does not rebuild it. And one difference from a sequential scan remains, inherent to an approximate index: rows whose indexed column is NULL are not in the index, so a NULL-argument scan returns fewer rows than the sequential scan would whenever the query wants more rows than the indexed ones provide.
The regression test pins the plan and executes the statement through generic prepared plans for both the L2 and cosine opclasses, and a LATERAL top-k covers the rescan path.