Skip to content

Check only the deleted row's validity bit on DELETE - #358

Open
MayCXC wants to merge 1 commit into
asg017:mainfrom
MayCXC:delete-validity-bit
Open

MayCXC wants to merge 1 commit into
asg017:mainfrom
MayCXC:delete-validity-bit

Conversation

@MayCXC

@MayCXC MayCXC commented Oct 24, 2026

Copy link
Copy Markdown

vec0Update_Delete_ClearValidity() checks a row's validity bit with bx >> (chunk_offset % CHAR_BIT), which is nonzero whenever a later row's bit in the same byte of the chunk's validity bitmap is set. A DELETE of a row whose own bit is already clear therefore succeeds instead of failing with "validity bit is not set". Only a damaged _chunks table has such a row:

create virtual table t1 using vec0(aaa float[4], chunk_size=8);
insert into t1(aaa) values ('[1,1,1,1]'), ('[2,1,1,1]');
update t1_chunks set validity = x'02';  -- row 1's bit clear, row 2's set
delete from t1 where rowid = 1;         -- succeeds on main

The check now tests the row's bit alone, (bx >> (chunk_offset % CHAR_BIT)) & 1. This is photostructure/sqlite-vec@f6a3244 by Matthew McEachen, ported.

test_vec0_delete_errors gains that case, which fails on main and passes here. The full suite passes (239 passed, 66 skipped, 204 snapshots), also with vec0 built with AddressSanitizer and UBSan. It merges cleanly with each of our open PRs here.

The same change is open on vlasky's fork as vlasky#25.

vec0Update_Delete_ClearValidity() tested `bx >> (chunk_offset % CHAR_BIT)`,
which is nonzero whenever a later row's bit in the same byte of the chunk's
validity bitmap is set. Deleting a row whose own bit was already clear
therefore succeeded instead of failing with "validity bit is not set". Only
a damaged _chunks table has such a row. The check now tests the row's bit
alone, `(bx >> (chunk_offset % CHAR_BIT)) & 1`.

Ported from photostructure/sqlite-vec@f6a3244 by Matthew McEachen.

test_vec0_delete_errors sets a chunk's validity byte to x'02', clearing row
1's bit while row 2's stays set, and expects the delete of row 1 to fail. It
fails on main and passes here. The full suite passes (239 passed, 66
skipped, 204 snapshots).

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