[DocDB][PgVector] ybhnsw searches fail with "Vector column (N) missing in row" when a row with a NULL vector is still in intents
Jira Link: DB-23876
Description
A ybhnsw search fails with
ERROR: Vector column (2) missing in row: { 0: 900105 2: <NULL> }when the tablet holds, in its intents, a row whose vector is NULL. This happens when a transaction inserts rows with a NULL vector and then searches the table, and to other sessions' searches while such a transaction's rows are committed but not yet applied. The error comes from an RSTATUS_DCHECK(..., Corruption, ...), so a debug build would crash instead. A row without a vector should simply be left out of the search.
In the same transaction, setting the nearest rows' vectors to NULL and then searching still returns those rows first, although in that transaction they no longer have a vector.
Updating another column, inserting a vector, moving a vector and deleting rows inside the transaction all work.
Steps to reproduce
CREATE EXTENSION IF NOT EXISTS vector;
CREATE TABLE t (id int PRIMARY KEY, n int, embedding vector(8)) SPLIT INTO 3 TABLETS;
INSERT INTO t
SELECT id, 0, (SELECT array_agg(random() * 2 - 1) FROM generate_series(1, 8) WHERE id > 0)::vector
FROM generate_series(1, 2000) AS g(id);
CREATE INDEX t_l2 ON t USING ybhnsw (embedding vector_l2_ops) WITH (m = 16, ef_construction = 64);
-- 1. Rows with a NULL vector, written by this transaction
BEGIN;
INSERT INTO t SELECT id, 0, NULL FROM generate_series(900101, 900110) AS g(id);
SELECT id FROM t ORDER BY embedding <-> '[0,0,0,0,0,0,0,0]' LIMIT 10;
ROLLBACK;
-- 2. The nearest rows' vectors set to NULL by this transaction
SELECT id FROM t ORDER BY embedding <-> '[0,0,0,0,0,0,0,0]' LIMIT 5; -- note these 5 ids
BEGIN;
UPDATE t SET embedding = NULL WHERE id IN (/* the 5 ids */);
SELECT id FROM t ORDER BY embedding <-> '[0,0,0,0,0,0,0,0]' LIMIT 10;
ROLLBACK;Expected: both searches return 10 rows that have a vector.
Actual:
ERROR: Vector column (2) missing in row: { 0: 900105 2: <NULL> }- The 5 rows whose vector was just set to NULL come back as the first 5 results.
With other sessions writing at the same time: 4 sessions ran short transactions that insert rows with NULL vectors (and update other rows) while 4 sessions searched in autocommit for 2 minutes. 628 of 16,176 searches failed with the same error; the rows named in the errors were ones the writers had just inserted with a NULL vector.
What we see on 2.31.0.0-b479
One transaction per case: write, search, roll back.
| Case | Result |
|---|---|
| insert a row with a vector at the query point | found |
| move 5 vectors next to the query point | all 5 found |
| delete the 5 nearest rows | not returned |
| update another column of the 5 nearest rows | OK |
| insert 10 rows with a NULL vector | search fails: Vector column (2) missing in row |
| set the 5 nearest rows' vectors to NULL | those 5 rows returned first |
A stress run whose workload writes some NULL vectors while it searches hit the same error 57 times in 8 minutes.
Not checked
- indexes on the usearch engine
- 2026.1 and 2025.2 builds
Environment
2.31.0.0-b479 (master, 061caa5dd119fa07a6691b75924fe411968d0fdd) release build, AWS, RF3, one universe (no xCluster).
Source: yugabyte/yugabyte-db