]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Simplifications to the NGQP. Add the queryplantest makefile target. Add
authordrh <drh@noemail.net>
Mon, 17 Jun 2013 18:20:48 +0000 (18:20 +0000)
committerdrh <drh@noemail.net>
Mon, 17 Jun 2013 18:20:48 +0000 (18:20 +0000)
testcase() macros in the NGQP.

FossilOrigin-Name: eaf1f1b405ec2c498092527fae00e5dbe9e176c1

main.mk
manifest
manifest.uuid
src/select.c
src/where.c

diff --git a/main.mk b/main.mk
index 845df4beaa470f064846006a08cd7d6b8877387e..d8c4c2916810bb8bae08334c882026306ace1845 100644 (file)
--- a/main.mk
+++ b/main.mk
@@ -593,6 +593,9 @@ soaktest:   testfixture$(EXE) sqlite3$(EXE)
 fulltestonly:  testfixture$(EXE) sqlite3$(EXE)
        ./testfixture$(EXE) $(TOP)/test/full.test
 
+queryplantest: testfixture$(EXE) sqlite3$(EXE)
+       ./testfixture$(EXE) $(TOP)/test/permutations.test queryplanner
+
 test:  testfixture$(EXE) sqlite3$(EXE)
        ./testfixture$(EXE) $(TOP)/test/veryquick.test
 
index c2a22a6d6ee4333df2c147a7006ef348f779ad85..9a336de116b6b03c69206976f4fe55516f4ecb49 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Use\sautomatic\sindices\son\ssubqueries\sof\sthe\sFROM\sclause\swhen\sappropriate.
-D 2013-06-17T14:18:21.734
+C Simplifications\sto\sthe\sNGQP.\s\sAdd\sthe\squeryplantest\smakefile\starget.\s\sAdd\ntestcase()\smacros\sin\sthe\sNGQP.
+D 2013-06-17T18:20:48.993
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -138,7 +138,7 @@ F ext/rtree/viewrtree.tcl eea6224b3553599ae665b239bd827e182b466024
 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x
 F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8
 F magic.txt f2b23a6bde8f1c6e86b957e4d94eab0add520b0d
-F main.mk e536751ac719806209c51f5dc63022a5dd40c631
+F main.mk c4335dbdb004d37e00e23d6ff226e55df0db5b21
 F mkdll.sh 7d09b23c05d56532e9d44a50868eb4b12ff4f74a
 F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f
 F mkextw.sh 4123480947681d9b434a5e7b1ee08135abe409ac
@@ -215,7 +215,7 @@ F src/printf.c bff529ed47657098c55c9910b9c69b1b3b1a1353
 F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50
 F src/resolve.c 89f9003e8316ee3a172795459efc2a0274e1d5a8
 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0
-F src/select.c 94a755b3d3788cf171c98064f2fa0ce6350fd6ca
+F src/select.c d5a1b9bc3fb451e68ce907df253c6ac17e7310f7
 F src/shell.c ab6eea968c8745be3aa74e45fedb37d057b4cd0d
 F src/sqlite.h.in 5b390ca5d94e09e56e7fee6a51ddde4721b89f8e
 F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0
@@ -289,7 +289,7 @@ F src/vtab.c b05e5f1f4902461ba9f5fc49bb7eb7c3a0741a83
 F src/wal.c 436bfceb141b9423c45119e68e444358ee0ed35d
 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
 F src/walker.c 4fa43583d0a84b48f93b1e88f11adf2065be4e73
-F src/where.c 74ecd744a5a9d18cc8e66f4c234bdac11c472eee
+F src/where.c 74627cb9415ad421004de574cfafe6ed0359554b
 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
 F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6
@@ -1096,7 +1096,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae
 F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
-P 3e8ac46918c68723bd199dbec8b0901457d524a9
-R cb395ca086e8d43cd185b18cda8198f7
+P e8f124284ee0d0e373dc4431668630f1e17015c1
+R 5f6127cf4cee34c1f05fd60f463f5e2a
 U drh
-Z 602d1da2f8b38f776a1f4f76f4cb8197
+Z 08d0c98ccbb424b49a424bc18bdd25d5
index b46fbe65502ab99c277b58dbbb59a23a6398c1cc..2d08ee9b9237fee0b0ae66633f63960bd840ebbc 100644 (file)
@@ -1 +1 @@
-e8f124284ee0d0e373dc4431668630f1e17015c1
\ No newline at end of file
+eaf1f1b405ec2c498092527fae00e5dbe9e176c1
\ No newline at end of file
index 0c706bdbc2f2933401d8696c4961402eaeab9219..40b7ec86f083fccdf98f657021cb135ff5f446ca 100644 (file)
@@ -4401,7 +4401,8 @@ int sqlite3Select(
       ** in the right order to begin with.
       */
       sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
-      pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, 0, 0, 0);
+      pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, 0, 
+                                 WHERE_GROUPBY, 0);
       if( pWInfo==0 ) goto select_end;
       if( sqlite3WhereIsOrdered(pWInfo) ){
         /* The optimizer is able to deliver rows in group by order so
index 0977dbea8d917539c529d91cfc4366ec0cbe0731..cf55858f7e0a30fd0124abb9a18d95caa9992e32 100644 (file)
@@ -4321,6 +4321,8 @@ static int whereLoopAddBtreeIndex(
     if( pNew->u.btree.nEq==1 && pProbe->nSample ){
       tRowcnt nOut = 0;
       if( (pTerm->eOperator & (WO_EQ|WO_ISNULL))!=0 ){
+        testcase( pTerm->eOperator & WO_EQ );
+        testcase( pTerm->eOperator & WO_ISNULL );
         rc = whereEqualScanEst(pParse, pProbe, pTerm->pExpr->pRight, &nOut);
       }else if( (pTerm->eOperator & WO_IN)
              &&  !ExprHasProperty(pTerm->pExpr, EP_xIsSelect)  ){
@@ -4861,7 +4863,6 @@ static int wherePathSatisfiesOrderBy(
   WherePath *pPath,     /* The WherePath to check */
   u16 wctrlFlags,       /* Might contain WHERE_GROUPBY or WHERE_DISTINCTBY */
   u16 nLoop,            /* Number of entries in pPath->aLoop[] */
-  u8 isLastLoop,        /* True if pLast is the inner-most loop */
   WhereLoop *pLast,     /* Add this WhereLoop to the end of pPath->aLoop[] */
   Bitmask *pRevMask     /* OUT: Mask of WhereLoops to run in reverse order */
 ){
@@ -4946,6 +4947,8 @@ static int wherePathSatisfiesOrderBy(
       pTerm = findTerm(&pWInfo->sWC, iCur, pOBExpr->iColumn,
                        ~ready, WO_EQ|WO_ISNULL, 0);
       if( pTerm==0 ) continue;
+      testcase( pTerm->eOperator & WO_EQ );
+      testcase( pTerm->eOperator & WO_ISNULL );
       if( pOBExpr->iColumn>=0 ){
         const char *z1, *z2;
         pColl = sqlite3ExprCollSeq(pWInfo->pParse, pOrderBy->a[i].pExpr);
@@ -4970,30 +4973,6 @@ static int wherePathSatisfiesOrderBy(
         isOrderDistinct = pIndex->onError!=OE_None;
       }
 
-      /* For every term of the index that is constrained by == or IS NULL,
-      ** mark off corresponding ORDER BY terms wherever they occur
-      ** in the ORDER BY clause.
-      */
-      for(i=0; i<pLoop->u.btree.nEq; i++){
-        pTerm = pLoop->aLTerm[i];
-        if( (pTerm->eOperator & (WO_EQ|WO_ISNULL))==0 ) continue;
-        iColumn = pTerm->u.leftColumn;
-        for(j=0; j<nOrderBy; j++){
-          if( MASKBIT(j) & obSat ) continue;
-          pOBExpr = sqlite3ExprSkipCollate(pOrderBy->a[j].pExpr);
-          if( pOBExpr->op!=TK_COLUMN ) continue;
-          if( pOBExpr->iTable!=iCur ) continue;
-          if( pOBExpr->iColumn!=iColumn ) continue;
-          if( iColumn>=0 ){
-            pColl = sqlite3ExprCollSeq(pWInfo->pParse, pOrderBy->a[j].pExpr);
-            if( !pColl ) pColl = db->pDfltColl;
-            if( sqlite3StrICmp(pColl->zName, pIndex->azColl[i])!=0 ) continue;
-          }
-          obSat |= MASKBIT(j);
-        }
-        if( obSat==obDone ) return 1;
-      }
-
       /* Loop through all columns of the index and deal with the ones
       ** that are not constrained by == or IN.
       */
@@ -5043,6 +5022,8 @@ static int wherePathSatisfiesOrderBy(
         for(i=0; bOnce && i<nOrderBy; i++){
           if( MASKBIT(i) & obSat ) continue;
           pOBExpr = sqlite3ExprSkipCollate(pOrderBy->a[i].pExpr);
+          testcase( wctrlFlags & WHERE_GROUPBY );
+          testcase( wctrlFlags & WHERE_DISTINCTBY );
           if( (wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY))==0 ) bOnce = 0;
           if( pOBExpr->op!=TK_COLUMN ) continue;
           if( pOBExpr->iTable!=iCur ) continue;
@@ -5093,7 +5074,6 @@ static int wherePathSatisfiesOrderBy(
   } /* End the loop over all WhereLoops from outer-most down to inner-most */
   if( obSat==obDone ) return 1;
   if( !isOrderDistinct ) return 0;
-  if( isLastLoop ) return 1;
   return -1;
 }
 
@@ -5200,7 +5180,7 @@ static int wherePathSolver(WhereInfo *pWInfo, WhereCost nRowEst){
         if( !isOrderedValid ){
           switch( wherePathSatisfiesOrderBy(pWInfo,
                        pWInfo->pOrderBy, pFrom, pWInfo->wctrlFlags,
-                       iLoop, iLoop==nLoop-1, pWLoop, &revMask) ){
+                       iLoop, pWLoop, &revMask) ){
             case 1:  /* Yes.  pFrom+pWLoop does satisfy the ORDER BY clause */
               isOrdered = 1;
               isOrderedValid = 1;
@@ -5326,9 +5306,12 @@ static int wherePathSolver(WhereInfo *pWInfo, WhereCost nRowEst){
   
   /* Find the lowest cost path.  pFrom will be left pointing to that path */
   pFrom = aFrom;
+  assert( nFrom==1 );
+#if 0 /* The following is needed if nFrom is ever more than 1 */
   for(ii=1; ii<nFrom; ii++){
     if( pFrom->rCost>aFrom[ii].rCost ) pFrom = &aFrom[ii];
   }
+#endif
   assert( pWInfo->nLevel==nLoop );
   /* Load the lowest cost path into pWInfo */
   for(iLoop=0; iLoop<nLoop; iLoop++){
@@ -5343,7 +5326,7 @@ static int wherePathSolver(WhereInfo *pWInfo, WhereCost nRowEst){
   ){
     Bitmask notUsed;
     int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pDistinct, pFrom,
-                 WHERE_DISTINCTBY, nLoop-1, 1, pFrom->aLoop[nLoop-1], &notUsed);
+                 WHERE_DISTINCTBY, nLoop-1, pFrom->aLoop[nLoop-1], &notUsed);
     if( rc==1 ) pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
   }
   if( pFrom->isOrdered ){