Skip to content

Add vec0 optimize command: compact sparse chunks after deletions#269

Draft
asg017 wants to merge 1 commit intoasg017/delete-clear-implfrom
asg017/optimize-impl
Draft

Add vec0 optimize command: compact sparse chunks after deletions#269
asg017 wants to merge 1 commit intoasg017/delete-clear-implfrom
asg017/optimize-impl

Conversation

@asg017
Copy link
Owner

@asg017 asg017 commented Mar 3, 2026

Depends on #268

Adds a FTS5-style 'optimize' command to vec0 virtual tables.

Vectors in vec0 tables are stored in contiguous blocks next to each other. When vectors are deleted, their validity bit and data are zero'ed on.

On future inserts, sometimes vec0 will re-fill that space with new data, but not always. Meaning, a vec0 table can be larger than it needs to be, with "holes" across various chunks.

The new 'optimize' command allows a developer to start an "optimize" procedure on a specific vec0 table. It will re-arrange vectors/chunks to compact space (a defragmenter, if you will).

I'm a little less sure of this change. Updating/deleting data is super important so I want to make sure I get this right.

Implements FTS5-style INSERT INTO v(v) VALUES ('optimize') command that
packs live entries from newer/sparser chunks into free slots of older
chunks, then deletes emptied chunks. Adds hidden command column to vtab
schema, command dispatcher in xUpdate, and two-pointer compaction
algorithm that handles vectors, all metadata types, and partitioned tables.

Includes 16 Python tests, 7 C unit tests, and a libFuzzer target.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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