]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Bug fixes in the ORDER BY optimizer.
authordrh <drh@noemail.net>
Mon, 8 Oct 2012 19:41:38 +0000 (19:41 +0000)
committerdrh <drh@noemail.net>
Mon, 8 Oct 2012 19:41:38 +0000 (19:41 +0000)
FossilOrigin-Name: 301bbee4045aa169e29fb4fb75743b71eb4760a1

manifest
manifest.uuid
src/where.c

index ff4e46d0cb2428ac8d4c9cc5e7c5d3a0023033b8..a505a09dff2169341bc79b9160f90cc6cfb53ab1 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Continued\srefactoring\sof\sthe\sORDER\sBY\soptimization\slogic.\s\sThis\scheck-in\nis\sclose\sto\sworking,\sbut\sit\sstill\shas\sissues.\s\sA\sfew\stest\scases\sfail.
-D 2012-10-08T18:23:51.612
+C Bug\sfixes\sin\sthe\sORDER\sBY\soptimizer.
+D 2012-10-08T19:41:38.447
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 5f4f26109f9d80829122e0e09f9cda008fa065fb
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -249,7 +249,7 @@ F src/vtab.c d8020c0a0e8ccc490ca449d7e665311b6e9f3ba9
 F src/wal.c e1fe8f92a0ea0fef8faa87ec43a127a478589d22
 F src/wal.h 29c197540b19044e6cd73487017e5e47a1d3dac6
 F src/walker.c 3d75ba73de15e0f8cd0737643badbeb0e002f07b
-F src/where.c 968bea256016bdc32de4051fc2e921771ed945e6
+F src/where.c d4a39bc7ea96ac2580b662df73c16d5ddacd9723
 F test/8_3_names.test 631ea964a3edb091cf73c3b540f6bcfdb36ce823
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
 F test/aggnested.test 0be144b453e0622a085fae8665c32f5676708e00
@@ -1018,7 +1018,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
 F tool/win/sqlite.vsix 67d8a99aceb56384a81b3f30d6c71743146d2cc9
-P 8f4487450be1a2b0371f8251a967cbe341b2dea1
-R b898c44fee2dd1d4ef226b8a2707fa76
+P adbdc663f3d22ff03f21040a811d585cf2218626
+R 3f2fb8221173011002c406e4b1569bb1
 U drh
-Z cd5853ba0dbcfea98f0be88905f219b5
+Z 5a939ce30180c1cb84b0892ff09f4ab1
index 9a42175bcfd0865739fdff3503ac6a5e3c009037..1996a19ef249930f193e203284387764406fe9cc 100644 (file)
@@ -1 +1 @@
-adbdc663f3d22ff03f21040a811d585cf2218626
\ No newline at end of file
+301bbee4045aa169e29fb4fb75743b71eb4760a1
\ No newline at end of file
index c309b456f089278c1f74a7e13e4f590ab3570bb4..2701bbda08ac3222f62e1d5c8ef182389efdbb75 100644 (file)
@@ -2803,17 +2803,30 @@ static int isSortingIndex(
   sqlite3 *db = pParse->db;     /* Database connection */
   int nPriorSat;                /* ORDER BY terms satisfied by outer loops */
   int seenRowid = 0;            /* True if an ORDER BY rowid term is seen */
-  int uniqueNotNull = 1;        /* pIdx is UNIQUE with all terms are NOT NULL */
+  int uniqueNotNull;            /* pIdx is UNIQUE with all terms are NOT NULL */
 
   if( p->i==0 ){
     nPriorSat = 0;
   }else{
     nPriorSat = p->aLevel[p->i-1].plan.nOBSat;
-    if( OptimizationDisabled(db, SQLITE_OrderByIdxJoin) ) return nPriorSat;
+    if( (p->aLevel[p->i-1].plan.wsFlags & WHERE_ORDERED)==0 ){
+      /* This loop cannot be ordered unless the next outer loop is
+      ** also ordered */
+      return nPriorSat;
+    }
+    if( OptimizationDisabled(db, SQLITE_OrderByIdxJoin) ){
+      /* Only look at the outer-most loop if the OrderByIdxJoin
+      ** optimization is disabled */
+      return nPriorSat;
+    }
   }
   pOrderBy = p->pOrderBy;
   assert( pOrderBy!=0 );
-  if( pIdx->bUnordered ) return nPriorSat;
+  if( pIdx->bUnordered ){
+    /* Hash indices (indicated by the "unordered" tag on sqlite_stat1) cannot
+    ** be used for sorting */
+    return nPriorSat;
+  }
   nTerm = pOrderBy->nExpr;
   uniqueNotNull = pIdx->onError!=OE_None;
   assert( nTerm>0 );
@@ -2936,6 +2949,12 @@ static int isSortingIndex(
       uniqueNotNull = 0;
     }
   }
+
+  /* If we have not found at least one ORDER BY term that matches the
+  ** index, then show no progress. */
+  if( pOBItem==&pOrderBy->a[nPriorSat] ) return nPriorSat;
+
+  /* Return the necessary scan order back to the caller */
   *pbRev = sortOrder & 1;
 
   /* If there was an "ORDER BY rowid" term that matched, or it is only