tursodatabase / libsql

libSQL is a fork of SQLite that is both Open Source, and Open Contributions.
https://turso.tech/libsql
MIT License
9.54k stars 252 forks source link

vector search: fix delete of rows with NULL vector value #1660

Closed sivukhin closed 1 month ago

sivukhin commented 1 month ago

Context

Current code fails to delete row from vector index if it had NULL vector value before:

$> CREATE TABLE t_null( v FLOAT32(3));
$> CREATE INDEX t_null_idx ON t_null( libsql_vector_idx(v) );
$> INSERT INTO t_null VALUES(NULL);
$> DELETE FROM t_null WHERE rowid = 1;
Runtime error: vector index(delete): failed to create blob for node row (233)

This is because vectorIndexDelete expects to always find corresponding row in the shadow table but since we are ignoring NULL values during inserts this invariant violated in such scenario.

This PR fixes this issue by simply ignoring such cases and exit silently if no row in shadow table were found during vectorIndexDelete operation