/ Check-in [87a9fc50]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Use an OP_NotFound opcode to cancel futile IN operators early. The current implementation is suboptimal because it always runs teh OP_NotFound. This still needs to be enhanced to only do the OP_NotFound if no results have been seen on the current loop.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | multikey-opt-idea
Files: files | file ages | folders
SHA3-256: 87a9fc504f9a78caf7a7949cc7ada0a19d61bfab51bb49a00a1607194c116212
User & Date: drh 2018-06-05 15:16:25
Context
2018-06-05
20:45
Add the OP_IfNoHope and OP_SeekHit opcodes used to reduce the number of unnecessary sqlite3BtreeMovetoUnpacked() calls when checking for an early exit on IN-operator loops. Futher optimizations are likely possible here. check-in: 6bf251af user: drh tags: multikey-opt-idea
15:16
Use an OP_NotFound opcode to cancel futile IN operators early. The current implementation is suboptimal because it always runs teh OP_NotFound. This still needs to be enhanced to only do the OP_NotFound if no results have been seen on the current loop. check-in: 87a9fc50 user: drh tags: multikey-opt-idea
13:54
Merge trunk changes. check-in: 047295c5 user: drh tags: multikey-opt-idea
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/where.c.

  5080   5080         struct InLoop *pIn;
  5081   5081         int j;
  5082   5082         sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
  5083   5083         for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
  5084   5084           sqlite3VdbeJumpHere(v, pIn->addrInTop+1);
  5085   5085           if( pIn->eEndLoopOp!=OP_Noop ){
  5086   5086             if( pIn->nPrefix ){
  5087         -            sqlite3VdbeAddOp3(v, OP_Noop, pLevel->iIdxCur,
         5087  +            sqlite3VdbeAddOp4Int(v, OP_NotFound, pLevel->iIdxCur,
         5088  +                              sqlite3VdbeCurrentAddr(v)+2,
  5088   5089                                 pIn->iBase, pIn->nPrefix);
         5090  +            VdbeCoverage(v);
  5089   5091             }
  5090   5092             sqlite3VdbeAddOp2(v, pIn->eEndLoopOp, pIn->iCur, pIn->addrInTop);
  5091   5093             VdbeCoverage(v);
  5092   5094             VdbeCoverageIf(v, pIn->eEndLoopOp==OP_PrevIfOpen);
  5093   5095             VdbeCoverageIf(v, pIn->eEndLoopOp==OP_NextIfOpen);
  5094   5096           }
  5095   5097           sqlite3VdbeJumpHere(v, pIn->addrInTop-1);

Changes to src/wherecode.c.

   588    588               int iCol = aiMap ? aiMap[iMap++] : 0;
   589    589               pIn->addrInTop = sqlite3VdbeAddOp3(v,OP_Column,iTab, iCol, iOut);
   590    590             }
   591    591             sqlite3VdbeAddOp1(v, OP_IsNull, iOut); VdbeCoverage(v);
   592    592             if( i==iEq ){
   593    593               pIn->iCur = iTab;
   594    594               pIn->eEndLoopOp = bRev ? OP_PrevIfOpen : OP_NextIfOpen;
   595         -            pIn->iBase = iReg - i;
   596         -            pIn->nPrefix = i;
          595  +            if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 ){
          596  +              pIn->iBase = iReg - i;
          597  +              pIn->nPrefix = i;
          598  +            }else{
          599  +              pIn->nPrefix = 0;
          600  +            }
   597    601             }else{
   598    602               pIn->eEndLoopOp = OP_Noop;
   599    603             }
   600    604             pIn++;
   601    605           }
   602    606         }
   603    607       }else{