Repository navigation
Conversation
ivf_create_shadow_tables() indexed _ivf_cellsNN by centroid with CREATE INDEX "<table>_ivf_cellsNN_centroid", which ALTER TABLE RENAME leaves under the old table's name, and xRename cannot drop it (DROP INDEX there fails with "database table is locked"). After a rename, creating an IVF table under the old name failed with "Could not create IVF shadow tables for column 0". The cells table now declares cell_id as its rowid and UNIQUE (centroid_id, cell_id), whose index SQLite renames with the table and which serves the same lookups by centroid. Every statement on the cells names its columns, so tables created before this open as they did.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After an IVF table is renamed, another IVF table cannot be created under its old name.
ivf_create_shadow_tables()indexes_ivf_cellsNNby centroid withCREATE INDEX "<table>_ivf_cellsNN_centroid".vec0Rename()renames the shadow tables, but ALTER TABLE RENAME leaves an index's name as it was, and the index cannot be dropped and recreated from inside xRename: aDROP INDEXthere fails with "database table is locked". The new table'sCREATE INDEXthen collides with the old one.The cells table now declares
cell_id INTEGER PRIMARY KEY, the rowid every statement already addresses cells by, andUNIQUE (centroid_id, cell_id). SQLite names that constraint's index after its table and renames it with the table, and the index serves the lookups by centroid as the old one did (the same query plans). Every statement on the cells names its columns, so a table created before this change opens and works here, and one created here opens and works on main. A table created before this change keeps its old index after a rename, but that index no longer blocks a new table, which creates none.Test:
test_rename_ivf_then_create_under_old_namein test-ivf-rename.py checks that no index on the renamed table's shadows is named for the old table, then creates a new table under the old name and reads each table's rows back. It fails on main and passes here. The Python suite passes (with-DSQLITE_VEC_EXPERIMENTAL_IVF_ENABLE=1, 302 passed, 4 skipped; without it, 239 passed, 67 skipped), under ASan and UBSan as well, and both builds' warnings are main's.It merges cleanly with every open PR that touches the IVF code, #313, #343, #347 and #349 to #351 included.
Origin. Found in the IVF port to photostructure/sqlite-vec, photostructure#12 (65817f4), which lists it among the port's differences from upstream, with the same
UNIQUE (centroid_id, cell_id)constraint; the change and its test are written here for asg017's main. No open or closed PR or issue here makes the same change.