Skip to content

Commit cea8725

Browse files
committed
fix DELETE from vector index as there can be no row due to the NULL value of the vector
1 parent a5db99b commit cea8725

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

libsql-sqlite3/src/vectordiskann.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,11 @@ int diskAnnDelete(
16331633
DiskAnnTrace(("diskAnnDelete started: rowid=%lld\n", nodeRowid));
16341634

16351635
rc = blobSpotCreate(pIndex, &pNodeBlob, nodeRowid, pIndex->nBlockSize, DISKANN_BLOB_WRITABLE);
1636-
if( rc != SQLITE_OK ){
1636+
if( rc == DISKANN_ROW_NOT_FOUND ){
1637+
// we omit rows with NULL values so it can be the case that there is nothing to delete in the index while row exists in the base table
1638+
rc = SQLITE_OK;
1639+
goto out;
1640+
}else if( rc != SQLITE_OK ){
16371641
*pzErrMsg = sqlite3_mprintf("vector index(delete): failed to create blob for node row");
16381642
goto out;
16391643
}

libsql-sqlite3/test/libsql_vector_index.test

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,19 @@ do_execsql_test vector-null {
135135
CREATE INDEX t_null_idx ON t_null( libsql_vector_idx(v) );
136136
INSERT INTO t_null VALUES(vector('[1,2,3]'));
137137
INSERT INTO t_null VALUES(NULL);
138-
INSERT INTO t_null VALUES(vector('[2,3,4]'));
138+
INSERT INTO t_null VALUES(vector('[3,4,5]'));
139139
SELECT * FROM vector_top_k('t_null_idx', '[1,2,3]', 2);
140-
} {1 3}
140+
UPDATE t_null SET v = vector('[2,3,4]') WHERE rowid = 2;
141+
SELECT rowid FROM vector_top_k('t_null_idx', vector('[2,3,4]'), 3);
142+
UPDATE t_null SET v = NULL WHERE rowid = 3;
143+
SELECT rowid FROM vector_top_k('t_null_idx', vector('[2,3,4]'), 3);
144+
UPDATE t_null SET v = NULL;
145+
SELECT rowid FROM vector_top_k('t_null_idx', vector('[2,3,4]'), 3);
146+
} {
147+
1 3
148+
2 3 1
149+
2 1
150+
}
141151

142152
do_execsql_test vector-sql {
143153
CREATE TABLE t_sql( v FLOAT32(3));

0 commit comments

Comments
 (0)