]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Bring some comments up to date in the query planner, and especially the
authordrh <drh@noemail.net>
Tue, 9 Oct 2012 09:26:28 +0000 (09:26 +0000)
committerdrh <drh@noemail.net>
Tue, 9 Oct 2012 09:26:28 +0000 (09:26 +0000)
ORDER BY optimizer.  Also add testcase() macros.

FossilOrigin-Name: bb5c0f1c92b48631d4a12cd4f321b53cd07885c8

manifest
manifest.uuid
src/where.c

index 87603bebec6ee55f3cce07380da4de65ba5f9e2b..b5e839254a459774d566cecf070fb6fb2e5c67b1 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Remove\san\sunused\svariable.\s\sFix\scode\sthat\soccurs\sbefore\sa\svariable\ndeclaration.
-D 2012-10-09T01:39:25.125
+C Bring\ssome\scomments\sup\sto\sdate\sin\sthe\squery\splanner,\sand\sespecially\sthe\nORDER\sBY\soptimizer.\s\sAlso\sadd\stestcase()\smacros.
+D 2012-10-09T09:26:28.770
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 5f4f26109f9d80829122e0e09f9cda008fa065fb
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -249,7 +249,7 @@ F src/vtab.c c7671587d07b76582c495d9305b35c0172cad5d3
 F src/wal.c e1fe8f92a0ea0fef8faa87ec43a127a478589d22
 F src/wal.h 29c197540b19044e6cd73487017e5e47a1d3dac6
 F src/walker.c 3d75ba73de15e0f8cd0737643badbeb0e002f07b
-F src/where.c 7d24dda2b2e8cf62c74e4f5f38bab160596ad658
+F src/where.c 410017c604713ab6c010a9e3731a7688a0c7a059
 F test/8_3_names.test 631ea964a3edb091cf73c3b540f6bcfdb36ce823
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
 F test/aggnested.test 0be144b453e0622a085fae8665c32f5676708e00
@@ -1019,7 +1019,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 981b9943e4b2b660690ec1ac145abdd3c74f8dd2
-R 14bbf14e4e201d652ae4e981e1902683
+P 01dc032b5bbd9c9ebb1965f176ca5d732cda85ea
+R 321fa7d1d84b8152f712a4c09dc171f1
 U drh
-Z 22e61519cc26696da476a58e182c0b3a
+Z b6de6b5036402a601a629813c2656e44
index 7ec1865ca4124a44a9d3f0f4b1f5bb013205b603..181f486db319dce91f179bd06a6db966b792ac8d 100644 (file)
@@ -1 +1 @@
-01dc032b5bbd9c9ebb1965f176ca5d732cda85ea
\ No newline at end of file
+bb5c0f1c92b48631d4a12cd4f321b53cd07885c8
\ No newline at end of file
index f9deb3d418dd8419c01cf59b3431a64cb8d4b670..7a994943cd5e3cc96b797472413c596a58ec9c04 100644 (file)
@@ -2771,14 +2771,6 @@ static int isOrderedColumn(
 ** The table being queried has a cursor number of "base".  pIdx is the
 ** index that is postulated for use to access the table.
 **
-** nEqCol is the number of columns of pIdx that are used as equality
-** constraints and where the other side of the == is an ordered column
-** or constant.  An "order column" in the previous sentence means a column
-** in table from an outer loop whose values will always appear in the 
-** correct order due to othre index, or because the outer loop generates
-** a unique result.  Any of the first nEqCol columns of pIdx may be missing
-** from the ORDER BY clause and the match can still be a success.
-**
 ** The *pbRev value is set to 0 order 1 depending on whether or not
 ** pIdx should be run in the forward order or in reverse order.
 */
@@ -2894,6 +2886,8 @@ static int isSortingIndex(
     /* termSortOrder is 0 or 1 for whether or not the access loop should
     ** run forward or backwards (respectively) in order to satisfy this 
     ** term of the ORDER BY clause. */
+    assert( pOBItem->sortOrder==0 || pOBItem->sortOrder==1 );
+    assert( iSortOrder==0 || iSortOrder==1 );
     termSortOrder = iSortOrder ^ pOBItem->sortOrder;
 
     /* If X is the column in the index and ORDER BY clause, check to see
@@ -2903,12 +2897,15 @@ static int isSortingIndex(
     if( pConstraint==0 ){
       isEq = 0;
     }else if( pConstraint->eOperator==WO_IN ){
+      /* Constraints of the form: "X IN ..." cannot be used with an ORDER BY
+      ** because we do not know in what order the values on the RHS of the IN
+      ** operator will occur. */
       break;
     }else if( pConstraint->eOperator==WO_ISNULL ){
       uniqueNotNull = 0;
-      isEq = 1;
+      isEq = 1;  /* "X IS NULL" means X has only a single value */
     }else if( pConstraint->prereqRight==0 ){
-      isEq = 1;
+      isEq = 1;  /* Constraint "X=constant" means X has only a single value */
     }else{
       Expr *pRight = pConstraint->pExpr->pRight;
       if( pRight->op==TK_COLUMN ){
@@ -2916,15 +2913,19 @@ static int isSortingIndex(
                     pRight->iTable, pRight->iColumn));
         isEq = isOrderedColumn(p, pRight->iTable, pRight->iColumn);
         WHERETRACE((" -> isEq=%d\n", isEq));
+
+        /* If the constraint is of the form X=Y where Y is an ordered value
+        ** in an outer loop, then make sure the sort order of Y matches the
+        ** sort order required for X. */
         if( isMatch && isEq>=2 && isEq!=pOBItem->sortOrder+2 ){
+          testcase( isEq==2 );
+          testcase( isEq==3 );
           break;
         }
       }else{
-        isEq = 0;
+        isEq = 0;  /* "X=expr" places no ordering constraints on X */
       }
     }
-    assert( pOBItem->sortOrder==0 || pOBItem->sortOrder==1 );
-    assert( iSortOrder==0 || iSortOrder==1 );
     if( !isMatch ){
       if( isEq==0 ){
         break;
@@ -2943,7 +2944,10 @@ static int isSortingIndex(
     if( iColumn<0 ){
       seenRowid = 1;
       break;
-    }else if( pTab->aCol[iColumn].notNull==0 && isEq==0 ){
+    }else if( pTab->aCol[iColumn].notNull==0 && isEq!=1 ){
+      testcase( isEq==0 );
+      testcase( isEq==2 );
+      testcase( isEq==3 );
       uniqueNotNull = 0;
     }
   }