From d6adbc9f56f2dff2c7ba9fd0e606c170a965fbbc Mon Sep 17 00:00:00 2001 From: Alex Garcia Date: Wed, 13 Nov 2024 15:01:43 -0800 Subject: [PATCH] drop aux shadow table on destroy --- TODO | 12 ++++++------ sqlite-vec.c | 12 ++++++++++++ tests/__snapshots__/test-auxiliary.ambr | 14 ++++++++++++++ tests/test-auxiliary.py | 5 +++++ 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/TODO b/TODO index 4f948bd..179b290 100644 --- a/TODO +++ b/TODO @@ -7,10 +7,10 @@ # auxiliary columns -- DELETE and UPDATE support -- in xBestIndex, ensure there are no constraints on any aux column - enforce column types, ie STRICT? -- NOT NULL? -- drop aux shadow table on xDestroy -- perf: INSERT stmt should be cached on vec0_vtab -- perf: LEFT JOIN aux table to rowids query in vec0_cursor for rowid/point stmts, to avoid N lookup queries +- in xBestIndex, ensure there are no constraints on any aux column +- DELETE and UPDATE support +- later: + - NOT NULL? + - perf: INSERT stmt should be cached on vec0_vtab + - perf: LEFT JOIN aux table to rowids query in vec0_cursor for rowid/point stmts, to avoid N lookup queries diff --git a/sqlite-vec.c b/sqlite-vec.c index e8425be..172a270 100644 --- a/sqlite-vec.c +++ b/sqlite-vec.c @@ -4835,6 +4835,18 @@ static int vec0Destroy(sqlite3_vtab *pVtab) { } sqlite3_finalize(stmt); } + + if(p->numAuxiliaryColumns > 0) { + zSql = sqlite3_mprintf("DROP TABLE " VEC0_SHADOW_AUXILIARY_NAME, p->schemaName, p->tableName); + rc = sqlite3_prepare_v2(p->db, zSql, -1, &stmt, 0); + sqlite3_free((void *)zSql); + if ((rc != SQLITE_OK) || (sqlite3_step(stmt) != SQLITE_DONE)) { + rc = SQLITE_ERROR; + goto done; + } + sqlite3_finalize(stmt); + } + stmt = NULL; rc = SQLITE_OK; diff --git a/tests/__snapshots__/test-auxiliary.ambr b/tests/__snapshots__/test-auxiliary.ambr index 30bb223..e706f6a 100644 --- a/tests/__snapshots__/test-auxiliary.ambr +++ b/tests/__snapshots__/test-auxiliary.ambr @@ -91,6 +91,20 @@ }), }) # --- +# name: test_normal[sqlite_master post drop] + OrderedDict({ + 'sql': 'select * from sqlite_master order by name', + 'rows': list([ + OrderedDict({ + 'type': 'table', + 'name': 'sqlite_sequence', + 'tbl_name': 'sqlite_sequence', + 'rootpage': 3, + 'sql': 'CREATE TABLE sqlite_sequence(name,seq)', + }), + ]), + }) +# --- # name: test_normal[sqlite_master] OrderedDict({ 'sql': 'select * from sqlite_master order by name', diff --git a/tests/test-auxiliary.py b/tests/test-auxiliary.py index edb52aa..8e210a0 100644 --- a/tests/test-auxiliary.py +++ b/tests/test-auxiliary.py @@ -29,6 +29,11 @@ def test_normal(db, snapshot): assert exec(db, "select * from v") == snapshot() assert vec0_shadow_table_contents(db, "v") == snapshot() + db.execute("drop table v;") + assert exec(db, "select * from sqlite_master order by name") == snapshot( + name="sqlite_master post drop" + ) + def test_types(db, snapshot): pass