Skip to content

Commit bd3e0d6

Browse files
authored
Merge pull request #1687 from tursodatabase/vector-search-fix-integrity-check
vector search: fix integrity check
2 parents 2f15a0e + eff638e commit bd3e0d6

5 files changed

Lines changed: 22 additions & 14 deletions

File tree

libsql-ffi/bundled/SQLite3MultipleCiphers/src/sqlite3.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137030,10 +137030,11 @@ SQLITE_PRIVATE int sqlite3OpenTableAndIndices(
137030137030
* As vector index creates empty B-tree index - it's safe to issue
137031137031
* OP_OpenRead command for it
137032137032
*
137033-
* TODO: with current implementation, integrity_check will output error
137034-
* for vector index as rows will be missed in it
137035-
* It's better to remove this error in future - but for now it's unclear
137036-
* how to do that with minimal code changes
137033+
* In order to not produce integrity check errors we skip vector indices
137034+
* from integrity checks in pragma.c implementation
137035+
*
137036+
* Note, that it's dangerous to skip some indices in this code as sqlite3 rely
137037+
* on the fact that cursors will be opened for every index in order
137037137038
*/
137038137039
#ifndef SQLITE_OMIT_VECTOR
137039137040
if( IsVectorIndex(pIdx) && op == OP_OpenWrite ){
@@ -142035,6 +142036,7 @@ SQLITE_PRIVATE void sqlite3Pragma(
142035142036
int kk;
142036142037
int ckUniq = sqlite3VdbeMakeLabel(pParse);
142037142038
if( pPk==pIdx ) continue;
142039+
if( IsVectorIndex(pIdx) ) continue;
142038142040
r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
142039142041
pPrior, r1);
142040142042
pPrior = pIdx;
@@ -142119,6 +142121,7 @@ SQLITE_PRIVATE void sqlite3Pragma(
142119142121
sqlite3VdbeLoadString(v, 2, "wrong # of entries in index ");
142120142122
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
142121142123
if( pPk==pIdx ) continue;
142124+
if( IsVectorIndex(pIdx) ) continue;
142122142125
sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
142123142126
addr = sqlite3VdbeAddOp3(v, OP_Eq, 8+j, 0, 3); VdbeCoverage(v);
142124142127
sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);

libsql-ffi/bundled/src/sqlite3.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137030,10 +137030,11 @@ SQLITE_PRIVATE int sqlite3OpenTableAndIndices(
137030137030
* As vector index creates empty B-tree index - it's safe to issue
137031137031
* OP_OpenRead command for it
137032137032
*
137033-
* TODO: with current implementation, integrity_check will output error
137034-
* for vector index as rows will be missed in it
137035-
* It's better to remove this error in future - but for now it's unclear
137036-
* how to do that with minimal code changes
137033+
* In order to not produce integrity check errors we skip vector indices
137034+
* from integrity checks in pragma.c implementation
137035+
*
137036+
* Note, that it's dangerous to skip some indices in this code as sqlite3 rely
137037+
* on the fact that cursors will be opened for every index in order
137037137038
*/
137038137039
#ifndef SQLITE_OMIT_VECTOR
137039137040
if( IsVectorIndex(pIdx) && op == OP_OpenWrite ){
@@ -142035,6 +142036,7 @@ SQLITE_PRIVATE void sqlite3Pragma(
142035142036
int kk;
142036142037
int ckUniq = sqlite3VdbeMakeLabel(pParse);
142037142038
if( pPk==pIdx ) continue;
142039+
if( IsVectorIndex(pIdx) ) continue;
142038142040
r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
142039142041
pPrior, r1);
142040142042
pPrior = pIdx;
@@ -142119,6 +142121,7 @@ SQLITE_PRIVATE void sqlite3Pragma(
142119142121
sqlite3VdbeLoadString(v, 2, "wrong # of entries in index ");
142120142122
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
142121142123
if( pPk==pIdx ) continue;
142124+
if( IsVectorIndex(pIdx) ) continue;
142122142125
sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
142123142126
addr = sqlite3VdbeAddOp3(v, OP_Eq, 8+j, 0, 3); VdbeCoverage(v);
142124142127
sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);

libsql-sqlite3/src/insert.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2699,10 +2699,11 @@ int sqlite3OpenTableAndIndices(
26992699
* As vector index creates empty B-tree index - it's safe to issue
27002700
* OP_OpenRead command for it
27012701
*
2702-
* TODO: with current implementation, integrity_check will output error
2703-
* for vector index as rows will be missed in it
2704-
* It's better to remove this error in future - but for now it's unclear
2705-
* how to do that with minimal code changes
2702+
* In order to not produce integrity check errors we skip vector indices
2703+
* from integrity checks in pragma.c implementation
2704+
*
2705+
* Note, that it's dangerous to skip some indices in this code as sqlite3 rely
2706+
* on the fact that cursors will be opened for every index in order
27062707
*/
27072708
#ifndef SQLITE_OMIT_VECTOR
27082709
if( IsVectorIndex(pIdx) && op == OP_OpenWrite ){

libsql-sqlite3/src/pragma.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,6 +2023,7 @@ void sqlite3Pragma(
20232023
int kk;
20242024
int ckUniq = sqlite3VdbeMakeLabel(pParse);
20252025
if( pPk==pIdx ) continue;
2026+
if( IsVectorIndex(pIdx) ) continue;
20262027
r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
20272028
pPrior, r1);
20282029
pPrior = pIdx;
@@ -2107,6 +2108,7 @@ void sqlite3Pragma(
21072108
sqlite3VdbeLoadString(v, 2, "wrong # of entries in index ");
21082109
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
21092110
if( pPk==pIdx ) continue;
2111+
if( IsVectorIndex(pIdx) ) continue;
21102112
sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
21112113
addr = sqlite3VdbeAddOp3(v, OP_Eq, 8+j, 0, 3); VdbeCoverage(v);
21122114
sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);

libsql-sqlite3/test/libsql_vector_index.test

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ do_execsql_test vector-pragmas {
3737
PRAGMA integrity_check;
3838
PRAGMA index_list='t_pragmas';
3939
} {
40-
{row 1 missing from index t_pragmas_idx}
41-
{wrong # of entries in index t_pragmas_idx}
40+
{ok}
4241
0 t_pragmas_idx 0 c 0
4342
}
4443

0 commit comments

Comments
 (0)