Additional corner-case fixes for the in-scan-vs-index or OP_SeekScan

optimization.

FossilOrigin-Name: ad5ab24ebd557e7af1d92ab3fbcb3747c04da5ad4ed779fb6391dc94042687dd
This commit is contained in:
drh
2020-10-02 13:48:57 +00:00
parent 64208b50ce
commit 7d14ffe4e1
4 changed files with 12 additions and 16 deletions
+3 -2
View File
@@ -2536,7 +2536,7 @@ static int whereLoopAddBtreeIndex(
/* "x IN (value, value, ...)" */
nIn = sqlite3LogEst(pExpr->x.pList->nExpr);
}
if( pProbe->hasStat1 ){
if( pProbe->hasStat1 && rLogSize>=10 ){
LogEst M, logK, safetyMargin;
/* Let:
** N = the total number of rows in the table
@@ -2555,7 +2555,8 @@ static int whereLoopAddBtreeIndex(
** a safety margin of 2 (LogEst: 10) that favors using the IN operator
** with the index, as using an index has better worst-case behavior.
** If we do not have real sqlite_stat1 data, always prefer to use
** the index.
** the index. Do not bother with this optimization on very small
** tables (less than 2 rows) as it is pointless in that case.
*/
M = pProbe->aiRowLogEst[saved_nEq];
logK = estLog(nIn);
+1 -6
View File
@@ -1809,12 +1809,7 @@ Bitmask sqlite3WhereCodeOneLoopStart(
op = aStartOp[(start_constraints<<2) + (startEq<<1) + bRev];
assert( op!=0 );
assert( op==OP_SeekGE
|| (pLoop->wsFlags & WHERE_IN_SEEKSCAN)==0
|| (db->flags & SQLITE_ReverseOrder)!=0 );
if( (pLoop->wsFlags & WHERE_IN_SEEKSCAN)!=0
&& op==OP_SeekGE /* OP_SeekScan only does forward scans */
){
if( (pLoop->wsFlags & WHERE_IN_SEEKSCAN)!=0 && op==OP_SeekGE ){
assert( regBignull==0 );
/* TUNING: The OP_SeekScan opcode seeks to reduce the number
** of expensive seek operations by replacing a single seek with