]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Improved comments on the OR-optimization logic in the query planner.
authordrh <drh@noemail.net>
Tue, 27 May 2014 16:41:39 +0000 (16:41 +0000)
committerdrh <drh@noemail.net>
Tue, 27 May 2014 16:41:39 +0000 (16:41 +0000)
FossilOrigin-Name: 77fef5a3987fc16f84a8e755283ca6ec1363013c

manifest
manifest.uuid
src/where.c

index ee6c2106b8a5b20d72a8e93d477659371ffe2515..04ddaf44ca1cb5610d3d84a1b6f4fc49d995b0d3 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Remove\sunused\scode\s(previously\s#ifdef-ed\sout)\sfrom\sbtree.c.
-D 2014-05-27T15:21:42.410
+C Improved\scomments\son\sthe\sOR-optimization\slogic\sin\sthe\squery\splanner.
+D 2014-05-27T16:41:39.846
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in dd2b1aba364ff9b05de41086f74407f285c57670
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -294,7 +294,7 @@ F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd
 F src/wal.c 76e7fc6de229bea8b30bb2539110f03a494dc3a8
 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
 F src/walker.c 11edb74d587bc87b33ca96a5173e3ec1b8389e45
-F src/where.c b5719b11c414874826c676cf8c8455cb2939a30c
+F src/where.c c0d3d347448ce49cce09f6d9c9c77b2e50cb04e8
 F src/whereInt.h 6804c2e5010378568c2bb1350477537755296a46
 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
@@ -1173,7 +1173,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 64a869ad2388d9d62601b93d5139f2dc57f260f7
-R ce6739b7102ff2fcf5c416b0ad7372b3
+P 8bc9737112e2700f337ff377cda040c8ba9d729f
+R c7cb76eccf21aa84ad851897e7d321d9
 U drh
-Z 7d981ef6a78ea000e412f69d3d0c7cf8
+Z 007914f5e44aaaab8e86bcf739f9064c
index ece315d4f22f4bd3efa612d1bdd66bfe0ecf0ad9..7426ad2ba15ceaf27a36723ab0119872f8ac3d1a 100644 (file)
@@ -1 +1 @@
-8bc9737112e2700f337ff377cda040c8ba9d729f
\ No newline at end of file
+77fef5a3987fc16f84a8e755283ca6ec1363013c
\ No newline at end of file
index b74f44987d1ba34184706d657d16144e753e302e..e03f94ba1ab651bb58ea7d95298ee2ca54327f13 100644 (file)
@@ -3401,12 +3401,16 @@ static Bitmask codeOneLoopStart(
       }
     }
 
+    /* Run a separate WHERE clause for each term of the OR clause.  After
+    ** eliminating duplicates from other WHERE clauses, the action for each
+    ** sub-WHERE clause is to to invoke the main loop body as a subroutine.
+    */
     for(ii=0; ii<pOrWc->nTerm; ii++){
       WhereTerm *pOrTerm = &pOrWc->a[ii];
       if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){
-        WhereInfo *pSubWInfo;          /* Info for single OR-term scan */
-        Expr *pOrExpr = pOrTerm->pExpr;
-        int j1 = 0;                    /* Address of jump operation */
+        WhereInfo *pSubWInfo;           /* Info for single OR-term scan */
+        Expr *pOrExpr = pOrTerm->pExpr; /* Current OR clause term */
+        int j1 = 0;                     /* Address of jump operation */
         if( pAndExpr && !ExprHasProperty(pOrExpr, EP_FromJoin) ){
           pAndExpr->pLeft = pOrExpr;
           pOrExpr = pAndExpr;
@@ -3421,6 +3425,11 @@ static Bitmask codeOneLoopStart(
           explainOneScan(
               pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0
           );
+          /* This is the sub-WHERE clause body.  First skip over
+          ** duplicate rows from prior sub-WHERE clauses, and record the
+          ** rowid (or PRIMARY KEY) for the current row so that the same
+          ** row will be skipped in subsequent sub-WHERE clauses.
+          */
           if( (pWInfo->wctrlFlags & WHERE_DUPLICATES_OK)==0 ){
             int r;
             int iSet = ((ii==pOrWc->nTerm-1)?-1:ii);
@@ -3465,7 +3474,12 @@ static Bitmask codeOneLoopStart(
               sqlite3ReleaseTempRange(pParse, r, nPk);
             }
           }
+
+          /* Invoke the main loop body as a subroutine */
           sqlite3VdbeAddOp2(v, OP_Gosub, regReturn, iLoopBody);
+
+          /* Jump here (skipping the main loop body subroutine) if the
+          ** current sub-WHERE row is a duplicate from prior sub-WHEREs. */
           if( j1 ) sqlite3VdbeJumpHere(v, j1);
 
           /* The pSubWInfo->untestedTerms flag means that this OR term