1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-16 23:02:26 +03:00

This is an attempt to address the OP_SeekScan performance issue identified by

[forum:/forumpost/b4fcb8a598|forum post b4fcb8a598].

FossilOrigin-Name: d58efb3f21a4150b8136197e43837c7b646c42d492a7c24ddc7591dba415a2c8
This commit is contained in:
drh
2021-06-02 12:44:26 +00:00
parent f9ac1ab1e7
commit b034a24140
4 changed files with 29 additions and 17 deletions

View File

@@ -2597,7 +2597,7 @@ static int whereLoopAddBtreeIndex(
nIn = sqlite3LogEst(pExpr->x.pList->nExpr);
}
if( pProbe->hasStat1 && rLogSize>=10 ){
LogEst M, logK, safetyMargin;
LogEst M, logK, x;
/* Let:
** N = the total number of rows in the table
** K = the number of entries on the RHS of the IN operator
@@ -2620,16 +2620,25 @@ static int whereLoopAddBtreeIndex(
*/
M = pProbe->aiRowLogEst[saved_nEq];
logK = estLog(nIn);
safetyMargin = 10; /* TUNING: extra weight for indexed IN */
if( M + logK + safetyMargin < nIn + rLogSize ){
/* TUNING v----- 10 to bias toward indexed IN */
x = M + logK + 10 - (nIn + rLogSize);
if( x>=0 ){
WHERETRACE(0x40,
("Scan preferred over IN operator on column %d of \"%s\" (%d<%d)\n",
saved_nEq, pProbe->zName, M+logK+10, nIn+rLogSize));
("IN operator (N=%d M=%d logK=%d nIn=%d rLogSize=%d x=%d) "
"prefers indexed lookup\n",
saved_nEq, M, logK, nIn, rLogSize, x));
}else if( x < -nInMul ){
WHERETRACE(0x40,
("IN operator (N=%d M=%d logK=%d nIn=%d rLogSize=%d x=%d"
" nInMul=%d) prefers skip-scan\n",
saved_nEq, M, logK, nIn, rLogSize, x, nInMul));
pNew->wsFlags |= WHERE_IN_SEEKSCAN;
}else{
WHERETRACE(0x40,
("IN operator preferred on column %d of \"%s\" (%d>=%d)\n",
saved_nEq, pProbe->zName, M+logK+10, nIn+rLogSize));
("IN operator (N=%d M=%d logK=%d nIn=%d rLogSize=%d x=%d"
" nInMul=%d) prefers normal scan\n",
saved_nEq, M, logK, nIn, rLogSize, x, nInMul));
continue;
}
}
pNew->wsFlags |= WHERE_COLUMN_IN;