Repository navigation
fix(libsql-sqlite3): mark vector index internal tables as shadow - #2339
Open
viliamgonda wants to merge 1 commit into
Open
viliamgonda wants to merge 1 commit into
viliamgonda wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Fixes #2329.
Cause
sqlite3ShadowTableNameonly checks virtual tables (IsVirtual), so vector index internal tables (libsql_vector_meta_shadowand<index>_shadow) never receiveTF_Shadowandpragma_table_listreports both withtype = 'table'. When reopening an existing database from disk,<index>_shadowis also parsed fromsqlite_schemabefore itsCREATE INDEXstatement.Fix
libsql-sqlite3/src/build.c:sqlite3ShadowTableNameto recognizelibsql_vector_meta_shadow(VECTOR_INDEX_GLOBAL_META_TABLE) and<index>_shadowtables backed by a vector index (IsVectorIndex(pIdx)).sqlite3CreateIndex, after settingpIndex->idxIsVector = 1, mark an existing ordinary<index>_shadowtable inpIndex->pSchema->tblHashwithTF_Shadowso reopening from disk also tags it.libsql-sqlite3/src/vectorIndex.c:SQLITE_DefensivearoundvectorIndexCreateandvectorIndexDrop(matchingvtab.c) so internal vector index creation and teardown continue working whenSQLITE_DBCONFIG_DEFENSIVEis enabled, while direct SQL writes/drops/renames against the shadow tables are blocked in defensive mode.libsql-ffi/bundled/src/sqlite3.candlibsql-ffi/bundled/SQLite3MultipleCiphers/src/sqlite3.c.Testing
Added regression tests in
libsql-sqlite3/test/libsql_vector_index.testcoveringpragma_table_liston fresh databases, reopened databases, attached databases, afterDROP INDEX, non-vector*_shadowuser tables (kept astable), andDEFENSIVEmode protection.Ran locally on macOS arm64:
./testfixture test/libsql_vector_index.test: all 54 tests pass (Ok)./testfixture test/pragma4.test: 0 errors out of 105 tests./testfixture test/altertab.test: 0 errors out of 120 tests./testfixture test/vacuum.test: 0 errors out of 44 tests./testfixture test/trigger2.test: 0 errors out of 112 tests./testfixture test/delete.test: 0 errors out of 68 testscargo test -p libsql-ffiandcargo test -p libsql --test integration_tests: 31 passed, 0 failed, 1 ignored (vector_fuzz_test)