diff options
author | drh <drh@noemail.net> | 2020-09-01 01:52:03 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2020-09-01 01:52:03 +0000 |
commit | fa17e134b2a006b4f5463743a72ab720502a5ecc (patch) | |
tree | 05781124d66d4be49a24583027e5c6aa26586e4e /src/wherecode.c | |
parent | d321b6f4ad264a47c56fe752158ca528e679994d (diff) | |
download | sqlite-fa17e134b2a006b4f5463743a72ab720502a5ecc.tar.gz sqlite-fa17e134b2a006b4f5463743a72ab720502a5ecc.zip |
Improvements to the IN-early-out optimization so that it works more
efficiently when there are two or more indexed IN clauses on a single table.
FossilOrigin-Name: 35505c68c1945c35babd2496e02bc4907a15c8e7b8d77f05f230bd0e9d4891d7
Diffstat (limited to 'src/wherecode.c')
-rw-r--r-- | src/wherecode.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/wherecode.c b/src/wherecode.c index 145b6fa5f..591f267e8 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -570,6 +570,9 @@ static int codeEqualityTerm( if( pLevel->u.in.nIn==0 ){ pLevel->addrNxt = sqlite3VdbeMakeLabel(pParse); } + if( iEq>0 ){ + pLoop->wsFlags |= WHERE_IN_EARLYOUT; + } i = pLevel->u.in.nIn; pLevel->u.in.nIn += nEq; @@ -596,7 +599,6 @@ static int codeEqualityTerm( if( iEq>0 ){ pIn->iBase = iReg - i; pIn->nPrefix = i; - pLoop->wsFlags |= WHERE_IN_EARLYOUT; }else{ pIn->nPrefix = 0; } @@ -606,6 +608,9 @@ static int codeEqualityTerm( pIn++; } } + if( iEq>0 ){ + sqlite3VdbeAddOp3(v, OP_SeekHit, pLevel->iIdxCur, 0, iEq); + } }else{ pLevel->u.in.nIn = 0; } @@ -1789,9 +1794,6 @@ Bitmask sqlite3WhereCodeOneLoopStart( ** above has already left the cursor sitting on the correct row, ** so no further seeking is needed */ }else{ - if( pLoop->wsFlags & WHERE_IN_EARLYOUT ){ - sqlite3VdbeAddOp1(v, OP_SeekHit, iIdxCur); - } if( regBignull ){ sqlite3VdbeAddOp2(v, OP_Integer, 1, regBignull); VdbeComment((v, "NULL-scan pass ctr")); @@ -1902,7 +1904,7 @@ Bitmask sqlite3WhereCodeOneLoopStart( } if( pLoop->wsFlags & WHERE_IN_EARLYOUT ){ - sqlite3VdbeAddOp2(v, OP_SeekHit, iIdxCur, 1); + sqlite3VdbeAddOp3(v, OP_SeekHit, iIdxCur, nEq, nEq); } /* Seek the table cursor, if required */ |