Add release cached stmts command to flush DiskANN prepared statements without disconnect#295
Open
rolf-moz wants to merge 2 commits intoasg017:mainfrom
Open
Add release cached stmts command to flush DiskANN prepared statements without disconnect#295rolf-moz wants to merge 2 commits intoasg017:mainfrom
rolf-moz wants to merge 2 commits intoasg017:mainfrom
Conversation
Hosts that embed sqlite-vec sometimes need to finalize vec0's cached
prepared statements without renaming or destroying the table. The cache
(stmtRowidsInsertRowid, stmtDiskannNodeRead, stmtVectorsInsert, etc.) is
otherwise only finalized in xDisconnect / xDestroy / xRename, which is
too late or too heavy for some use cases.
Concrete motivating case: Firefox's mozStorage calls sqlite3_close() on
shutdown, which fails (and asserts in debug builds) while any
sqlite3_stmt* is still alive on the connection — including vec0's. The
existing workarounds are either an ALTER TABLE rename pair (bumps the
schema cookie and writes to shadow tables) or closing/reopening the
connection (heavy hammer).
Adds a new index-type-agnostic command dispatched via the existing
FTS5-style command column:
INSERT INTO vec_history(vec_history) VALUES('release-cached-stmts');
This calls vec0_free_resources(p) directly. Cached statements are
re-prepared lazily on next use.
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.
@asg017 I'm seeing some errors with Diskann because there are some prepared statements pending when we are closing the connection.
Is it advisable to have a flush command, or should I suppress these errors?
Attached is a flush implementation. As with my other patch, I heavily relied on Claude code since I don't know this codebase well.
Summary
Adds a new index-type-agnostic command dispatched via the existing FTS5-style
command column on vec0: