Skip to content

Commit 8105eee

Browse files
authored
Skip _vector_chunks rename for non-FLAT vec0 columns (#294)
vec0Rename emits an unconditional ALTER TABLE on `<name>_vector_chunks%02d` for every vector column, but non-FLAT columns (rescore, IVF, DiskANN) don't create that shadow table — so ALTER TABLE RENAME on a DiskANN-indexed (or rescore/IVF) vec0 table fails with `no such table` and leaves any cached prepared statements still referencing the old name. Mirror the guard already used at create time in vec0_init around VEC0_SHADOW_VECTOR_N_CREATE: only rename `_vector_chunks` when the column's index_type is VEC0_INDEX_TYPE_FLAT. Adds a regression test exercising rename on a DiskANN-indexed table.
1 parent 5778fec commit 8105eee

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

sqlite-vec.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10435,9 +10435,13 @@ static int vec0Rename(sqlite3_vtab *pVtab, const char *zNew) {
1043510435

1043610436
// Per-vector-column shadow tables
1043710437
for (int i = 0; i < p->numVectorColumns; i++) {
10438-
sqlite3_str_appendf(s,
10439-
"ALTER TABLE \"%w\".\"%w_vector_chunks%02d\" RENAME TO \"%w_vector_chunks%02d\";",
10440-
p->schemaName, p->tableName, i, zNew, i);
10438+
// Non-FLAT columns (rescore, IVF, DiskANN) don't create _vector_chunks
10439+
// (mirror the guard in vec0_init around VEC0_SHADOW_VECTOR_N_CREATE).
10440+
if (p->vector_columns[i].index_type == VEC0_INDEX_TYPE_FLAT) {
10441+
sqlite3_str_appendf(s,
10442+
"ALTER TABLE \"%w\".\"%w_vector_chunks%02d\" RENAME TO \"%w_vector_chunks%02d\";",
10443+
p->schemaName, p->tableName, i, zNew, i);
10444+
}
1044110445

1044210446
#if SQLITE_VEC_ENABLE_RESCORE
1044310447
if (p->shadowRescoreChunksNames[i]) {

tests/test-rename.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,35 @@ def test_rename_with_metadata(db):
162162
assert _shadow_tables(db, "v") == []
163163

164164

165+
def test_rename_diskann(db):
166+
"""Rename should work on DiskANN-indexed tables (no _vector_chunks shadow)."""
167+
db.execute("""
168+
CREATE VIRTUAL TABLE v USING vec0(
169+
a float[8] INDEXED BY diskann(neighbor_quantizer=binary)
170+
)
171+
""")
172+
db.execute("insert into v(rowid, a) values (1, ?)", [_f32([0.1] * 8)])
173+
174+
# DiskANN columns use _vectors / _diskann_nodes / _diskann_buffer instead
175+
# of _vector_chunks; the rename must skip the missing _vector_chunks ALTER.
176+
before = _shadow_tables(db, "v")
177+
assert "v_diskann_nodes00" in before
178+
assert "v_vector_chunks00" not in before
179+
180+
db.execute("ALTER TABLE v RENAME TO v2")
181+
182+
rows = db.execute(
183+
"select rowid from v2 where a match ? and k=10",
184+
[_f32([0.1] * 8)],
185+
).fetchall()
186+
assert rows[0][0] == 1
187+
188+
after = _shadow_tables(db, "v2")
189+
assert "v2_diskann_nodes00" in after
190+
assert "v2_vector_chunks00" not in after
191+
assert _shadow_tables(db, "v") == []
192+
193+
165194
def test_rename_drop_after(db):
166195
"""DROP TABLE should work on a renamed table."""
167196
db.execute("create virtual table v using vec0(a float[2], chunk_size=8)")

0 commit comments

Comments
 (0)