]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Enhance whereLoopCheaperProperSubset(X,Y) so that it does not report true
authordrh <drh@noemail.net>
Wed, 5 Nov 2014 13:13:13 +0000 (13:13 +0000)
committerdrh <drh@noemail.net>
Wed, 5 Nov 2014 13:13:13 +0000 (13:13 +0000)
if X uses skip-scan less than Y, since in that case X might
deserve to be cheaper even if it is a proper subset.

FossilOrigin-Name: c106b755369c1f8546e897ecd2ac56fd09d6e885

manifest
manifest.uuid
src/where.c

index 29e1d31cf280d5cbf2e4a47875d550e58df3d3de..8e0066d70e48a55533c5b648ad1bb3f3d304f3e0 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\sthe\s".scanstats\son"\scommand\sto\sthe\sshell\stool.\sExecuting\sthis\scommand\scauses\sthe\sshell\stool\sto\sprint\svalues\sfrom\ssqlite3_stmt_scanstatus()\safter\seach\squery\sis\srun.
-D 2014-11-05T09:07:28.365
+C Enhance\swhereLoopCheaperProperSubset(X,Y)\sso\sthat\sit\sdoes\snot\sreport\strue\nif\sX\suses\sskip-scan\sless\sthan\sY,\ssince\sin\sthat\scase\sX\smight\ndeserve\sto\sbe\scheaper\seven\sif\sit\sis\sa\sproper\ssubset.
+D 2014-11-05T13:13:13.983
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in cf57f673d77606ab0f2d9627ca52a9ba1464146a
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -302,7 +302,7 @@ F src/vtab.c 2a30791bbd7926b589401bd09c3abb33de563793
 F src/wal.c 825c948066c7604a07d56e67958cdab210749016
 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804
-F src/where.c d5fa1081bf7cb70478ed06489e063695c92ee1e1
+F src/where.c 240961041f35862ebcafd260587c79a1ab7347f8
 F src/whereInt.h d3633e9b592103241b74b0ec76185f3e5b8b62e0
 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
@@ -1211,7 +1211,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 7df82c46da437bc743576358c25e758280067df8
-R f4931dcb1177b970d566df3dbaa382ec
-U dan
-Z 44baa22d0450fc9fcacf5946d93d71c5
+P 7974c0ed10ffdc960a43fed89845c2bed428958d
+R 418c93fe7ac7140cffa87d5f3271cb48
+U drh
+Z 68c42aaa0a73598a09ed4215a5cfd466
index ccd696efe4f1634bf02ae34c7e4d41064cad5b53..da46c6359a88e00a47ca35cfc5c783bf9665875a 100644 (file)
@@ -1 +1 @@
-7974c0ed10ffdc960a43fed89845c2bed428958d
\ No newline at end of file
+c106b755369c1f8546e897ecd2ac56fd09d6e885
\ No newline at end of file
index d7966fdfbc3cd23115b48453cca1c67cf806895e..34614e6bb32c1d0a44d1f49298ff5a1220446317 100644 (file)
@@ -4012,10 +4012,11 @@ static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
 }
 
 /*
-** Return TRUE if both of the following are true:
+** Return TRUE if all of the following are true:
 **
 **   (1)  X has the same or lower cost that Y
 **   (2)  X is a proper subset of Y
+**   (3)  X skips at least as many columns as Y
 **
 ** By "proper subset" we mean that X uses fewer WHERE clause terms
 ** than Y and that every WHERE clause term used by X is also used
@@ -4023,7 +4024,9 @@ static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
 **
 ** If X is a proper subset of Y then Y is a better choice and ought
 ** to have a lower cost.  This routine returns TRUE when that cost 
-** relationship is inverted and needs to be adjusted.
+** relationship is inverted and needs to be adjusted.  The third rule
+** was added because if X uses skip-scan less than Y it still might
+** deserve a lower cost even if it is a proper subset of Y.
 */
 static int whereLoopCheaperProperSubset(
   const WhereLoop *pX,       /* First WhereLoop to compare */
@@ -4033,6 +4036,7 @@ static int whereLoopCheaperProperSubset(
   if( pX->nLTerm-pX->nSkip >= pY->nLTerm-pY->nSkip ){
     return 0; /* X is not a subset of Y */
   }
+  if( pY->nSkip > pX->nSkip ) return 0;
   if( pX->rRun >= pY->rRun ){
     if( pX->rRun > pY->rRun ) return 0;    /* X costs more than Y */
     if( pX->nOut > pY->nOut ) return 0;    /* X costs more than Y */
@@ -4068,9 +4072,7 @@ static void whereLoopAdjustCost(const WhereLoop *p, WhereLoop *pTemplate){
     if( (p->wsFlags & WHERE_INDEXED)==0 ) continue;
     if( whereLoopCheaperProperSubset(p, pTemplate) ){
       /* Adjust pTemplate cost downward so that it is cheaper than its 
-      ** subset p.  Except, do not adjust the cost estimate downward for
-      ** a loop that skips more columns. */
-      if( pTemplate->nSkip>p->nSkip ) continue;
+      ** subset p. */
       WHERETRACE(0x80,("subset cost adjustment %d,%d to %d,%d\n",
                        pTemplate->rRun, pTemplate->nOut, p->rRun, p->nOut-1));
       pTemplate->rRun = p->rRun;