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.
This commit is contained in:
Rolf Rando 2026-05-17 22:56:52 -07:00 committed by GitHub
parent 5778fecfeb
commit 8105eee61e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 3 deletions

View file

@ -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)")