]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Make sure the virtual tables that take advantage of IN operators sort the
authordrh <drh@noemail.net>
Fri, 8 Feb 2013 20:39:02 +0000 (20:39 +0000)
committerdrh <drh@noemail.net>
Fri, 8 Feb 2013 20:39:02 +0000 (20:39 +0000)
RHS of the IN operator in the correct order according to the ORDER BY
clause.

FossilOrigin-Name: b016b7546d6fbfba06019398b9ac239b0cbe9086

manifest
manifest.uuid
src/where.c

index 3637f1e54124de8c0d17f36ac77a34e89f80e178..990aaddfef5f5de5354616a4b1d8ed6145b56db4 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Loop\sthrough\sthe\selements\son\sthe\sRHS\sof\san\sIN\soperator\sin\sreverse\sorder\swhen\nthe\sORDER\sBY\sclauses\sspecifies\sDESC.
-D 2013-02-08T18:48:23.501
+C Make\ssure\sthe\svirtual\stables\sthat\stake\sadvantage\sof\sIN\soperators\ssort\sthe\nRHS\sof\sthe\sIN\soperator\sin\sthe\scorrect\sorder\saccording\sto\sthe\sORDER\sBY\nclause.
+D 2013-02-08T20:39:02.391
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in a48faa9e7dd7d556d84f5456eabe5825dd8a6282
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -252,7 +252,7 @@ F src/vtab.c b05e5f1f4902461ba9f5fc49bb7eb7c3a0741a83
 F src/wal.c f5c7b5027d0ed0e9bc9afeb4a3a8dfea762ec7d2
 F src/wal.h 29c197540b19044e6cd73487017e5e47a1d3dac6
 F src/walker.c 3d75ba73de15e0f8cd0737643badbeb0e002f07b
-F src/where.c 36370580f2e3f805df161db44288bfb7d9ac007a
+F src/where.c df3f8f610746165066bd029f24f35739b5d0a21f
 F test/8_3_names.test 631ea964a3edb091cf73c3b540f6bcfdb36ce823
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
 F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6
@@ -1034,7 +1034,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 a917c1f09254b54e03e31b119cc49c551269d82e
-R f8ff7e2997f1e9085eb15a7df82507fc
+P f78395c8896666bb1359b83fbcd58d5e3dbc39d3
+R 080d4548a7ca8008fc94adcb8a7a49c2
 U drh
-Z d65a74f3ef1f6a5ee91ecd28380ca50d
+Z 0d4d8d5d423c9c5e6216d31dab1445d7
index 8b749ce569bb337c08c779d3fd9c651eb9d06455..84f9305d6373fd37a4581847349a6a2f91d62dd4 100644 (file)
@@ -1 +1 @@
-f78395c8896666bb1359b83fbcd58d5e3dbc39d3
\ No newline at end of file
+b016b7546d6fbfba06019398b9ac239b0cbe9086
\ No newline at end of file
index a3c5e24d39751d857142b95d7fae9519e7bb095b..c513c28b808806ae83c47e14bfd704605b21ca91 100644 (file)
@@ -2270,8 +2270,9 @@ static void bestVirtualIndex(WhereBestIdx *p){
   struct sqlite3_index_constraint *pIdxCons;
   struct sqlite3_index_constraint_usage *pUsage;
   WhereTerm *pTerm;
-  int i, j;
+  int i, j, k;
   int nOrderBy;
+  int sortOrder;                  /* Sort order for IN clauses */
   int bAllowIN;                   /* Allow IN optimizations */
   double rCost;
 
@@ -2370,18 +2371,27 @@ static void bestVirtualIndex(WhereBestIdx *p){
       return;
     }
   
+    sortOrder = SQLITE_SO_ASC;
     pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint;
     for(i=0; i<pIdxInfo->nConstraint; i++, pIdxCons++){
       if( pUsage[i].argvIndex>0 ){
         j = pIdxCons->iTermOffset;
         pTerm = &pWC->a[j];
         p->cost.used |= pTerm->prereqRight;
-        if( (pTerm->eOperator & WO_IN)!=0 && pUsage[i].omit==0 ){
-          /* Do not attempt to use an IN constraint if the virtual table
-          ** says that the equivalent EQ constraint cannot be safely omitted.
-          ** If we do attempt to use such a constraint, some rows might be
-          ** repeated in the output. */
-          break;
+        if( (pTerm->eOperator & WO_IN)!=0 ){
+          if( pUsage[i].omit==0 ){
+            /* Do not attempt to use an IN constraint if the virtual table
+            ** says that the equivalent EQ constraint cannot be safely omitted.
+            ** If we do attempt to use such a constraint, some rows might be
+            ** repeated in the output. */
+            break;
+          }
+          for(k=0; k<pIdxInfo->nOrderBy; k++){
+            if( pIdxInfo->aOrderBy[k].iColumn==pIdxCons->iColumn ){
+              sortOrder = pIdxInfo->aOrderBy[k].desc;
+              break;
+            }
+          }
         }
       }
     }
@@ -2411,7 +2421,8 @@ static void bestVirtualIndex(WhereBestIdx *p){
   }
   p->cost.plan.u.pVtabIdx = pIdxInfo;
   if( pIdxInfo->orderByConsumed ){
-    p->cost.plan.wsFlags |= WHERE_ORDERED;
+    assert( sortOrder==0 || sortOrder==1 );
+    p->cost.plan.wsFlags |= WHERE_ORDERED + sortOrder*WHERE_REVERSE;
     p->cost.plan.nOBSat = nOrderBy;
   }else{
     p->cost.plan.nOBSat = p->i ? p->aLevel[p->i-1].plan.nOBSat : 0;