Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions sqlite-vec.c
Original file line number Diff line number Diff line change
Expand Up @@ -10435,9 +10435,13 @@ static int vec0Rename(sqlite3_vtab *pVtab, const char *zNew) {

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

#if SQLITE_VEC_ENABLE_RESCORE
if (p->shadowRescoreChunksNames[i]) {
Expand Down
29 changes: 29 additions & 0 deletions tests/test-rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,35 @@ def test_rename_with_metadata(db):
assert _shadow_tables(db, "v") == []


def test_rename_diskann(db):
"""Rename should work on DiskANN-indexed tables (no _vector_chunks shadow)."""
db.execute("""
CREATE VIRTUAL TABLE v USING vec0(
a float[8] INDEXED BY diskann(neighbor_quantizer=binary)
)
""")
db.execute("insert into v(rowid, a) values (1, ?)", [_f32([0.1] * 8)])

# DiskANN columns use _vectors / _diskann_nodes / _diskann_buffer instead
# of _vector_chunks; the rename must skip the missing _vector_chunks ALTER.
before = _shadow_tables(db, "v")
assert "v_diskann_nodes00" in before
assert "v_vector_chunks00" not in before

db.execute("ALTER TABLE v RENAME TO v2")

rows = db.execute(
"select rowid from v2 where a match ? and k=10",
[_f32([0.1] * 8)],
).fetchall()
assert rows[0][0] == 1

after = _shadow_tables(db, "v2")
assert "v2_diskann_nodes00" in after
assert "v2_vector_chunks00" not in after
assert _shadow_tables(db, "v") == []


def test_rename_drop_after(db):
"""DROP TABLE should work on a renamed table."""
db.execute("create virtual table v using vec0(a float[2], chunk_size=8)")
Expand Down