Skip to content

Commit 4587da3

Browse files
committed
make sqlite planner to not user vector index for any optimizations
1 parent 0c19b79 commit 4587da3

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

libsql-sqlite3/src/build.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4345,11 +4345,6 @@ void sqlite3CreateIndex(
43454345
goto exit_create_index;
43464346
}
43474347
if( vectorIdxRc >= 1 ){
4348-
/*
4349-
* SQLite can use B-Tree indices in some optimizations (like SELECT COUNT(*) can use any full B-Tree index instead of PK index)
4350-
* But, SQLite pretty conservative about usage of unordered indices - that's what we need here
4351-
*/
4352-
pIndex->bUnordered = 1;
43534348
pIndex->idxIsVector = 1;
43544349
}
43554350
if( vectorIdxRc == 1 ){

libsql-sqlite3/src/select.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8423,6 +8423,7 @@ int sqlite3Select(
84238423
if( pIdx->bUnordered==0
84248424
&& pIdx->szIdxRow<pTab->szTabRow
84258425
&& pIdx->pPartIdxWhere==0
8426+
&& pIdx->idxIsVector==0
84268427
&& (!pBest || pIdx->szIdxRow<pBest->szIdxRow)
84278428
){
84288429
pBest = pIdx;

libsql-sqlite3/src/where.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2973,9 +2973,10 @@ static int whereLoopAddBtreeIndex(
29732973
assert( pNew->u.btree.nBtm==0 );
29742974
opMask = WO_EQ|WO_IN|WO_GT|WO_GE|WO_LT|WO_LE|WO_ISNULL|WO_IS;
29752975
}
2976-
if( pProbe->bUnordered || pProbe->bLowQual ){
2976+
if( pProbe->bUnordered || pProbe->bLowQual || pProbe->idxIsVector ){
29772977
if( pProbe->bUnordered ) opMask &= ~(WO_GT|WO_GE|WO_LT|WO_LE);
29782978
if( pProbe->bLowQual ) opMask &= ~(WO_EQ|WO_IN|WO_IS);
2979+
if( pProbe->idxIsVector ) opMask = 0;
29792980
}
29802981

29812982
assert( pNew->u.btree.nEq<pProbe->nColumn );
@@ -3357,7 +3358,7 @@ static int indexMightHelpWithOrderBy(
33573358
ExprList *aColExpr;
33583359
int ii, jj;
33593360

3360-
if( pIndex->bUnordered ) return 0;
3361+
if( pIndex->bUnordered || pIndex->idxIsVector ) return 0;
33613362
if( (pOB = pBuilder->pWInfo->pOrderBy)==0 ) return 0;
33623363
for(ii=0; ii<pOB->nExpr; ii++){
33633364
Expr *pExpr = sqlite3ExprSkipCollateAndLikely(pOB->a[ii].pExpr);
@@ -3526,6 +3527,9 @@ static SQLITE_NOINLINE u32 whereIsCoveringIndex(
35263527
** if pIdx is covering. Assume it is not. */
35273528
return 0;
35283529
}
3530+
if( pIdx->idxIsVector==1 ){
3531+
return 0;
3532+
}
35293533
if( pIdx->bHasExpr==0 ){
35303534
for(i=0; i<pIdx->nColumn; i++){
35313535
if( pIdx->aiColumn[i]>=BMS-1 ) break;
@@ -3814,6 +3818,9 @@ static int whereLoopAddBtree(
38143818
testcase( pNew->iTab!=pSrc->iCursor ); /* See ticket [98d973b8f5] */
38153819
continue; /* Partial index inappropriate for this query */
38163820
}
3821+
if( pProbe->idxIsVector!=0 ){
3822+
continue; /* Vector index inappropriate for this query */
3823+
}
38173824
if( pProbe->bNoQuery ) continue;
38183825
rSize = pProbe->aiRowLogEst[0];
38193826
pNew->u.btree.nEq = 0;
@@ -4817,7 +4824,7 @@ static i8 wherePathSatisfiesOrderBy(
48174824
pIndex = 0;
48184825
nKeyCol = 0;
48194826
nColumn = 1;
4820-
}else if( (pIndex = pLoop->u.btree.pIndex)==0 || pIndex->bUnordered ){
4827+
}else if( (pIndex = pLoop->u.btree.pIndex)==0 || pIndex->bUnordered || pIndex->idxIsVector ){
48214828
return 0;
48224829
}else{
48234830
nKeyCol = pIndex->nKeyCol;

0 commit comments

Comments
 (0)