mirror of
https://github.com/asg017/sqlite-vec.git
synced 2026-05-18 13:55:18 +02:00
Finalize all cached vec0 stmts on commit (fixes #295)
vec0Sync only finalized stmtLatestChunk and the four stmtRowids* stmts. The IVF/DiskANN/vectors stmts persisted on the vtab until xDisconnect, which blocked sqlite3_close() (non-v2) with SQLITE_BUSY — the original mozStorage case from #295. The same leak also broke VACUUM with "SQL statements in progress" after any DiskANN operation. Switch vec0Sync to call vec0_free_resources, which already finalizes the full cache. Also fix a latent bug: the DiskANN block in vec0_free_resources was nested inside #if SQLITE_VEC_EXPERIMENTAL_IVF_ENABLE, so in the default build (DiskANN on, IVF off) those finalizes were unreachable even from xDisconnect/xDestroy. Split into two independent #if guards. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
8b81f40d1e
commit
fe941716ad
2 changed files with 38 additions and 23 deletions
27
sqlite-vec.c
27
sqlite-vec.c
|
|
@ -3695,13 +3695,15 @@ void vec0_free_resources(vec0_vtab *p) {
|
|||
sqlite3_finalize(p->stmtIvfRowidMapLookup[i]); p->stmtIvfRowidMapLookup[i] = NULL;
|
||||
sqlite3_finalize(p->stmtIvfRowidMapDelete[i]); p->stmtIvfRowidMapDelete[i] = NULL;
|
||||
sqlite3_finalize(p->stmtIvfCentroidsAll[i]); p->stmtIvfCentroidsAll[i] = NULL;
|
||||
}
|
||||
#endif
|
||||
#if SQLITE_VEC_ENABLE_DISKANN
|
||||
for (int i = 0; i < VEC0_MAX_VECTOR_COLUMNS; i++) {
|
||||
sqlite3_finalize(p->stmtDiskannNodeRead[i]); p->stmtDiskannNodeRead[i] = NULL;
|
||||
sqlite3_finalize(p->stmtDiskannNodeWrite[i]); p->stmtDiskannNodeWrite[i] = NULL;
|
||||
sqlite3_finalize(p->stmtDiskannNodeInsert[i]); p->stmtDiskannNodeInsert[i] = NULL;
|
||||
sqlite3_finalize(p->stmtVectorsRead[i]); p->stmtVectorsRead[i] = NULL;
|
||||
sqlite3_finalize(p->stmtVectorsInsert[i]); p->stmtVectorsInsert[i] = NULL;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
@ -10370,28 +10372,7 @@ static int vec0Begin(sqlite3_vtab *pVTab) {
|
|||
return SQLITE_OK;
|
||||
}
|
||||
static int vec0Sync(sqlite3_vtab *pVTab) {
|
||||
UNUSED_PARAMETER(pVTab);
|
||||
vec0_vtab *p = (vec0_vtab *)pVTab;
|
||||
if (p->stmtLatestChunk) {
|
||||
sqlite3_finalize(p->stmtLatestChunk);
|
||||
p->stmtLatestChunk = NULL;
|
||||
}
|
||||
if (p->stmtRowidsInsertRowid) {
|
||||
sqlite3_finalize(p->stmtRowidsInsertRowid);
|
||||
p->stmtRowidsInsertRowid = NULL;
|
||||
}
|
||||
if (p->stmtRowidsInsertId) {
|
||||
sqlite3_finalize(p->stmtRowidsInsertId);
|
||||
p->stmtRowidsInsertId = NULL;
|
||||
}
|
||||
if (p->stmtRowidsUpdatePosition) {
|
||||
sqlite3_finalize(p->stmtRowidsUpdatePosition);
|
||||
p->stmtRowidsUpdatePosition = NULL;
|
||||
}
|
||||
if (p->stmtRowidsGetChunkPosition) {
|
||||
sqlite3_finalize(p->stmtRowidsGetChunkPosition);
|
||||
p->stmtRowidsGetChunkPosition = NULL;
|
||||
}
|
||||
vec0_free_resources((vec0_vtab *)pVTab);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
static int vec0Commit(sqlite3_vtab *pVTab) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue