PARTITION KEY support (#122)

* initial pass at PARTITION KEY support.

* unit tests

* gha this PR branch

* fixup tests

* doc internal

* fix tests, KNN/rowids in

* define SQLITE_INDEX_CONSTRAINT_OFFSET

* whoops

* update tests, syrupy, use uv

* un ignore pyproject.toml

* dot

* tests/

* type error?

* win: .exe, update error name

* try fix macos python, paren around expr?

* win bash?

* dbg :(

* explicit error

* op

* dbg win

* win ./tests/.venv/Scripts/python.exe

* block UPDATEs on partition key values for now
This commit is contained in:
Alex Garcia 2024-11-20 00:02:04 -08:00 committed by GitHub
parent ee3654701f
commit 6658624172
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 1522 additions and 245 deletions

View file

@ -81,7 +81,7 @@ def connect(ext, path=":memory:", extra_entrypoint=None):
db = connect(EXT_PATH)
def explain_query_plan(sql):
def explain_query_plan(sql, db=db):
return db.execute("explain query plan " + sql).fetchone()["detail"]
@ -1497,6 +1497,13 @@ def test_vec0_text_pk():
]
if SUPPORTS_VTAB_IN:
assert re.match(
("SCAN (TABLE )?t VIRTUAL TABLE INDEX 0:3{___}___\[___"),
explain_query_plan(
"select t_id, distance from t where aaa match '' and k = 3 and t_id in ('t_2', 't_3')",
db=db,
),
)
assert execute_all(
db,
"select t_id, distance from t where aaa match ? and k = 3 and t_id in ('t_2', 't_3')",
@ -1939,20 +1946,6 @@ def test_vec0_create_errors():
db.execute("create virtual table t1 using vec0(a float[1])")
db.set_authorizer(None)
db.set_authorizer(authorizer_deny_on(sqlite3.SQLITE_INSERT, "t1_chunks"))
with _raises(
"Could not create create an initial chunk",
):
db.execute("create virtual table t1 using vec0(a float[1])")
db.set_authorizer(None)
db.set_authorizer(authorizer_deny_on(sqlite3.SQLITE_INSERT, "t1_vector_chunks00"))
with _raises(
"Could not create create an initial chunk",
):
db.execute("create virtual table t1 using vec0(a float[1])")
db.set_authorizer(None)
# EVIDENCE-OF: V21406_05476 vec0 init raises error on 'latest chunk' init error
db.execute("BEGIN")
db.set_authorizer(authorizer_deny_on(sqlite3.SQLITE_READ, "t1_chunks", ""))
@ -2231,32 +2224,34 @@ def test_smoke():
},
]
chunk = db.execute("select * from vec_xyz_chunks").fetchone()
assert chunk["chunk_id"] == 1
assert chunk["validity"] == bytearray(int(1024 / 8))
assert chunk["rowids"] == bytearray(int(1024 * 8))
vchunk = db.execute("select * from vec_xyz_vector_chunks00").fetchone()
assert vchunk["rowid"] == 1
assert vchunk["vectors"] == bytearray(int(1024 * 4 * 2))
# as of TODO, no initial row is inside the chunks table
assert chunk is None
# assert chunk["chunk_id"] == 1
# assert chunk["validity"] == bytearray(int(1024 / 8))
# assert chunk["rowids"] == bytearray(int(1024 * 8))
# vchunk = db.execute("select * from vec_xyz_vector_chunks00").fetchone()
# assert vchunk["rowid"] == 1
# assert vchunk["vectors"] == bytearray(int(1024 * 4 * 2))
assert re.match(
"SCAN (TABLE )?vec_xyz VIRTUAL TABLE INDEX 0:knn:",
"SCAN (TABLE )?vec_xyz VIRTUAL TABLE INDEX 0:3{___}___",
explain_query_plan(
"select * from vec_xyz where a match X'' and k = 10 order by distance"
),
)
if SUPPORTS_VTAB_LIMIT:
assert re.match(
"SCAN (TABLE )?vec_xyz VIRTUAL TABLE INDEX 0:knn:",
"SCAN (TABLE )?vec_xyz VIRTUAL TABLE INDEX 0:3{___}___",
explain_query_plan(
"select * from vec_xyz where a match X'' order by distance limit 10"
),
)
assert re.match(
"SCAN (TABLE )?vec_xyz VIRTUAL TABLE INDEX 0:fullscan",
"SCAN (TABLE )?vec_xyz VIRTUAL TABLE INDEX 0:1",
explain_query_plan("select * from vec_xyz"),
)
assert re.match(
"SCAN (TABLE )?vec_xyz VIRTUAL TABLE INDEX 3:point",
"SCAN (TABLE )?vec_xyz VIRTUAL TABLE INDEX 3:2",
explain_query_plan("select * from vec_xyz where rowid = 4"),
)