Skip to content

fix(libsql-sqlite3): mark vector index internal tables as shadow - #2339

Open
viliamgonda wants to merge 1 commit into
tursodatabase:mainfrom
viliamgonda:fix/vector-shadow-table-list
Open

viliamgonda wants to merge 1 commit into
tursodatabase:mainfrom
viliamgonda:fix/vector-shadow-table-list

Conversation

@viliamgonda

Copy link
Copy Markdown

Fixes #2329.

Cause

sqlite3ShadowTableName only checks virtual tables (IsVirtual), so vector index internal tables (libsql_vector_meta_shadow and <index>_shadow) never receive TF_Shadow and pragma_table_list reports both with type = 'table'. When reopening an existing database from disk, <index>_shadow is also parsed from sqlite_schema before its CREATE INDEX statement.

Fix

  • In libsql-sqlite3/src/build.c:
    • Update sqlite3ShadowTableName to recognize libsql_vector_meta_shadow (VECTOR_INDEX_GLOBAL_META_TABLE) and <index>_shadow tables backed by a vector index (IsVectorIndex(pIdx)).
    • In sqlite3CreateIndex, after setting pIndex->idxIsVector = 1, mark an existing ordinary <index>_shadow table in pIndex->pSchema->tblHash with TF_Shadow so reopening from disk also tags it.
  • In libsql-sqlite3/src/vectorIndex.c:
    • Temporarily clear and restore SQLITE_Defensive around vectorIndexCreate and vectorIndexDrop (matching vtab.c) so internal vector index creation and teardown continue working when SQLITE_DBCONFIG_DEFENSIVE is enabled, while direct SQL writes/drops/renames against the shadow tables are blocked in defensive mode.
  • Regenerated the amalgamations in libsql-ffi/bundled/src/sqlite3.c and libsql-ffi/bundled/SQLite3MultipleCiphers/src/sqlite3.c.

Testing

Added regression tests in libsql-sqlite3/test/libsql_vector_index.test covering pragma_table_list on fresh databases, reopened databases, attached databases, after DROP INDEX, non-vector *_shadow user tables (kept as table), and DEFENSIVE mode 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 tests
  • cargo test -p libsql-ffi and cargo test -p libsql --test integration_tests: 31 passed, 0 failed, 1 ignored (vector_fuzz_test)

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.

Vector index tables are reported as user tables by pragma_table_list

1 participant