]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Futher enhancements to the ORDER BY optimizer.
authordrh <drh@noemail.net>
Fri, 31 May 2013 13:36:32 +0000 (13:36 +0000)
committerdrh <drh@noemail.net>
Fri, 31 May 2013 13:36:32 +0000 (13:36 +0000)
FossilOrigin-Name: d8efa5f8b60bc4c8df8bfad077f87f76f7ee9bf6

manifest
manifest.uuid
src/where.c

index edf228f8725483937c75ab560f54b053cdc92f38..24f702b1fb49c26d1cf87c78c6f85f5d90247757 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Improved\sdetection\sof\sunnecessary\sORDER\sBY\sclauses.
-D 2013-05-31T12:43:55.143
+C Futher\senhancements\sto\sthe\sORDER\sBY\soptimizer.
+D 2013-05-31T13:36:32.993
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -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 0e1c41804f89dbfd48fbe8dfa68adc6b6d682a75
+F src/where.c 8e9922815b07290982cfc826497d128115ce358c
 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
 F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6
@@ -1093,7 +1093,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
 F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
-P 5e1e61399513b4a95fd93df2377a2603f1670063
-R 17288f799b200fcc6199a08359305634
+P 58805eb36b9975706e2c4e382689519454e9a504
+R d753e9381f16048231d3d54f23e54ee3
 U drh
-Z 9542ccfa5fa5ec11248b1f41f8b389ee
+Z 2bef9deff008e88de89f5b60b513bb1c
index ec86401b40781f1e06bb3aa39a122f2529edf72a..0e1ff8e72f43d5d73a6f17780fcc94f8f27bdc64 100644 (file)
@@ -1 +1 @@
-58805eb36b9975706e2c4e382689519454e9a504
\ No newline at end of file
+d8efa5f8b60bc4c8df8bfad077f87f76f7ee9bf6
\ No newline at end of file
index 249cc724b1cb01e87ae3067ae82c689cc4f2f66c..d4f9a714414bcc6ecb75dc1b20ffa3f513fcd75f 100644 (file)
@@ -4510,6 +4510,7 @@ static int wherePathSatisfiesOrderBy(
   WhereInfo *pWInfo,    /* The WHERE clause */
   WherePath *pPath,     /* The WherePath to check */
   int nLoop,            /* Number of entries in pPath->aLoop[] */
+  int isLastLoop,       /* True for the very last loop */
   WhereLoop *pLast,     /* Add this WhereLoop to the end of pPath->aLoop[] */
   Bitmask *pRevMask     /* Mask of WhereLoops to run in reverse order */
 ){
@@ -4569,10 +4570,12 @@ static int wherePathSatisfiesOrderBy(
   /* Sorting is always required if any term of the ORDER BY is not a 
   ** column reference */
   nOrderBy = pOrderBy->nExpr;
+#if 0
   for(i=0; i<nOrderBy; i++){
     pOBExpr = sqlite3ExprSkipCollate(pOrderBy->a[i].pExpr);
     if( pOBExpr->op!=TK_COLUMN ) return 0;
   }
+#endif
     
   for(i=0; i<=nLoop && nUsed<nOrderBy; i++){
     pLoop = i<nLoop ? pPath->aLoop[i] : pLast;
@@ -4604,7 +4607,7 @@ static int wherePathSatisfiesOrderBy(
     for(j=0; j<=nColumn && nUsed<nOrderBy; j++, nUsed++){
       int skipable;
       pOBExpr = sqlite3ExprSkipCollate(pOrderBy->a[nUsed].pExpr);
-      assert( pOBExpr->op==TK_COLUMN );
+      if( pOBExpr->op!=TK_COLUMN ) return 0;
       if( pOBExpr->iTable!=iCur ) break;
       if( isOneRow ){ j--; continue; }
       if( j<nColumn ){
@@ -4637,11 +4640,15 @@ static int wherePathSatisfiesOrderBy(
           revSet = 1;
         }
       }
-      if( j>=nColumn-1 && isUniqueIdx ){ j--; isOneRow = 1; }
+      if( j>=nColumn-1 && isUniqueIdx ){
+        if( isLastLoop && i==nLoop ) break;
+        j--;
+        isOneRow = 1;
+      }
     }
     if( rev ) revMask |= ((Bitmask)1)<<i;
   }
-  if( nUsed==nOrderBy ){
+  if( isLastLoop || nUsed==nOrderBy ){
     *pRevMask = revMask;
     return 1;
   }
@@ -4743,7 +4750,7 @@ static int wherePathSolver(WhereInfo *pWInfo, double nRowEst){
         rCost = pWLoop->rSetup + pWLoop->rRun*pFrom->nRow + pFrom->rCost;
         maskNew = pFrom->maskLoop | pWLoop->maskSelf;
         if( !isOrderedValid ){
-          switch( wherePathSatisfiesOrderBy(pWInfo, pFrom, iLoop,
+          switch( wherePathSatisfiesOrderBy(pWInfo, pFrom, iLoop, iLoop==nLoop-1,
                                             pWLoop, &revMask) ){
             case 1:  /* Yes.  pFrom+pWLoop does satisfy the ORDER BY clause */
               isOrdered = 1;