Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions libsql-ffi/bundled/SQLite3MultipleCiphers/src/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
** src/btree.h
** src/build.c
** src/callback.c
** src/delete.c
** src/func.c
** src/insert.c
** src/loadext.c
Expand Down Expand Up @@ -131230,6 +131231,20 @@ SQLITE_PRIVATE void sqlite3DeleteFrom(
}
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
assert( pIdx->pSchema==pTab->pSchema );
#ifndef SQLITE_OMIT_VECTOR
/*
* Vector index entries live in the index's shadow table, not in its
* b-tree, so OP_Clear alone leaves them behind. Open the index with
* OPFLAG_FORDELETE, which clears it, as REINDEX does.
*/
if( IsVectorIndex(pIdx) ){
int iVecCur = pParse->nTab++;
sqlite3VdbeAddOp3(v, OP_OpenVectorIdx, iVecCur, pIdx->tnum, iDb);
sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
sqlite3VdbeChangeP5(v, OPFLAG_FORDELETE);
sqlite3VdbeAddOp1(v, OP_Close, iVecCur);
}
#endif
if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
sqlite3VdbeAddOp3(v, OP_Clear, pIdx->tnum, iDb, memCnt ? memCnt : -1);
}else{
Expand Down
15 changes: 15 additions & 0 deletions libsql-ffi/bundled/src/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
** src/btree.h
** src/build.c
** src/callback.c
** src/delete.c
** src/func.c
** src/insert.c
** src/loadext.c
Expand Down Expand Up @@ -131230,6 +131231,20 @@ SQLITE_PRIVATE void sqlite3DeleteFrom(
}
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
assert( pIdx->pSchema==pTab->pSchema );
#ifndef SQLITE_OMIT_VECTOR
/*
* Vector index entries live in the index's shadow table, not in its
* b-tree, so OP_Clear alone leaves them behind. Open the index with
* OPFLAG_FORDELETE, which clears it, as REINDEX does.
*/
if( IsVectorIndex(pIdx) ){
int iVecCur = pParse->nTab++;
sqlite3VdbeAddOp3(v, OP_OpenVectorIdx, iVecCur, pIdx->tnum, iDb);
sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
sqlite3VdbeChangeP5(v, OPFLAG_FORDELETE);
sqlite3VdbeAddOp1(v, OP_Close, iVecCur);
}
#endif
if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
sqlite3VdbeAddOp3(v, OP_Clear, pIdx->tnum, iDb, memCnt ? memCnt : -1);
}else{
Expand Down
14 changes: 14 additions & 0 deletions libsql-sqlite3/src/delete.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,20 @@ void sqlite3DeleteFrom(
}
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
assert( pIdx->pSchema==pTab->pSchema );
#ifndef SQLITE_OMIT_VECTOR
/*
* Vector index entries live in the index's shadow table, not in its
* b-tree, so OP_Clear alone leaves them behind. Open the index with
* OPFLAG_FORDELETE, which clears it, as REINDEX does.
*/
if( IsVectorIndex(pIdx) ){
int iVecCur = pParse->nTab++;
sqlite3VdbeAddOp3(v, OP_OpenVectorIdx, iVecCur, pIdx->tnum, iDb);
sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
sqlite3VdbeChangeP5(v, OPFLAG_FORDELETE);
sqlite3VdbeAddOp1(v, OP_Close, iVecCur);
}
#endif
if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
sqlite3VdbeAddOp3(v, OP_Clear, pIdx->tnum, iDb, memCnt ? memCnt : -1);
}else{
Expand Down
11 changes: 11 additions & 0 deletions libsql-sqlite3/test/libsql_vector_index.test
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ do_execsql_test vector-delete {
SELECT rowid FROM vector_top_k('t_delete_idx', vector('[1,1,1]'), 1);
} {10 20}

do_execsql_test vector-delete-all {
CREATE TABLE t_delete_all( id INTEGER PRIMARY KEY, v FLOAT32(3) );
CREATE INDEX t_delete_all_idx ON t_delete_all( libsql_vector_idx(v) );
INSERT INTO t_delete_all VALUES (1, vector('[1,1,1]'));
INSERT INTO t_delete_all VALUES (2, vector('[-1,-1,-1]'));
DELETE FROM t_delete_all;
SELECT count(*) FROM t_delete_all_idx_shadow;
INSERT INTO t_delete_all VALUES (1, vector('[1,1,1]'));
SELECT rowid FROM vector_top_k('t_delete_all_idx', vector('[-1,-1,-1]'), 2);
} {0 1}

do_execsql_test vector-update {
CREATE TABLE t_update( id INTEGER PRIMARY KEY, v FLOAT32(3) );
CREATE INDEX t_update_idx ON t_update( libsql_vector_idx(v) );
Expand Down
Loading