]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Continuing refinements of the logic to take WHERE clause terms not used for
authordrh <drh@noemail.net>
Sat, 7 Sep 2013 00:29:06 +0000 (00:29 +0000)
committerdrh <drh@noemail.net>
Sat, 7 Sep 2013 00:29:06 +0000 (00:29 +0000)
indexing into account when computing the number of output rows from each
table.

FossilOrigin-Name: b65dc53415f42d8402d0ec7f4bedf59d7b39b486

manifest
manifest.uuid
src/resolve.c
src/sqliteInt.h
src/where.c

index af8be5bcd5399a8c7ea5151776797811ec0fa988..55164884ee08fd7a181c9195f5d887eb94487f51 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Enhance\sthe\splan\ssolver\sto\stake\sinto\saccount\sthe\snumber\sof\soutput\srows\swhen\ncomputing\sthe\sset\sof\spaths\sto\sretain\sfor\sthe\snext\scycle.
-D 2013-09-06T17:45:42.446
+C Continuing\srefinements\sof\sthe\slogic\sto\stake\sWHERE\sclause\sterms\snot\sused\sfor\nindexing\sinto\saccount\swhen\scomputing\sthe\snumber\sof\soutput\srows\sfrom\seach\ntable.
+D 2013-09-07T00:29:06.736
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -214,14 +214,14 @@ F src/pragma.c 3aa3d8c8623b7b71c5b1bfb72dcc31fb0c25665f
 F src/prepare.c fa6988589f39af8504a61731614cd4f6ae71554f
 F src/printf.c da9119eb31a187a4b99f60aa4a225141c0ebb74b
 F src/random.c 0b2dbc37fdfbfa6bd455b091dfcef5bdb32dba68
-F src/resolve.c 8a2b6b9a6487e6e5a23b8de571131ccce62a1ce0
+F src/resolve.c 594725ba98cbe0e7de9da75c9915dc589d92bcd4
 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0
 F src/select.c 9239586282bd146ec5843a2cde7d54cd7816cf78
 F src/shell.c d920a891ca09b8bd262cced7fb0ab9d723f7a747
 F src/sqlite.h.in ec40aa958a270416fb04b4f72210357bf163d2c5
 F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0
 F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc
-F src/sqliteInt.h fd9005fab1cd063f5c4e76a2120efc080b43750a
+F src/sqliteInt.h ac21b3aeb0251a4096a21a0750277f5701adfe0c
 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
 F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158
 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
@@ -290,7 +290,7 @@ F src/vtab.c 5a423b042eb1402ef77697d03d6a67378d97bc8d
 F src/wal.c 7dc3966ef98b74422267e7e6e46e07ff6c6eb1b4
 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
 F src/walker.c 4fa43583d0a84b48f93b1e88f11adf2065be4e73
-F src/where.c ce16c689b9a199ffffd63745405214912e941e6f
+F src/where.c 613cfc35baebc4aa10b54c15e31745327b057232
 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
 F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6
@@ -1111,7 +1111,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae
 F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
-P 036fc37a034093a4c6fc190633bd41c2b7230d77
-R 3890bf7553bc1077426fb2f0e0259279
+P 1a46a7242313da96420985fa52e1de3f84533e5b
+R eafbf9bd5dba867073722599ec249697
 U drh
-Z 80a7432df4b498524e527dd8f32c240f
+Z 0382b063215f6bbc8f334bae45df8ffd
index b05ebc1a7567a1592e418f7897d4f5587987ed38..24110c517fa5155272f3bd208a6265285f81762f 100644 (file)
@@ -1 +1 @@
-1a46a7242313da96420985fa52e1de3f84533e5b
\ No newline at end of file
+b65dc53415f42d8402d0ec7f4bedf59d7b39b486
\ No newline at end of file
index ec6fe90716df2d66e72c26b270a40e97d7f36cd2..ab318be8e24b77091fdb8a564cc67a838a785bed 100644 (file)
@@ -705,7 +705,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
               pNC->nErr++;
             }
           }else{
-            pExpr->iTable = 75;
+            pExpr->iTable = 75;  /* TUNING:  Default 2nd arg to unlikely() is 0.075 */
           }             
         }
       }
index d8ed4eb04e56d9e53688b7b63abcd8ee7f910d62..268fef36fee2c491ae57b0d56861d44c5f8bace4 100644 (file)
@@ -1032,6 +1032,7 @@ struct sqlite3 {
 #define SQLITE_Transitive     0x0200   /* Transitive constraints */
 #define SQLITE_OmitNoopJoin   0x0400   /* Omit unused tables in joins */
 #define SQLITE_Stat3          0x0800   /* Use the SQLITE_STAT3 table */
+#define SQLITE_AdjustOutEst   0x1000   /* Adjust output estimates using WHERE */
 #define SQLITE_AllOpts        0xffff   /* All optimizations */
 
 /*
index e4485ac7d4147acdd06cfbd8c60238b736ac3ce8..ded80e23c365b7e5e15fc270cfc67ee766351b43 100644 (file)
@@ -688,7 +688,9 @@ static int whereClauseInsert(WhereClause *pWC, Expr *p, u8 wtFlags){
     pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]);
   }
   pTerm = &pWC->a[idx = pWC->nTerm++];
-  if( p && ExprHasAnyProperty(p, EP_Hint) ){
+  if( wtFlags & TERM_VIRTUAL ){
+    pTerm->truthProb = 0;
+  }else if( p && ExprHasAnyProperty(p, EP_Hint) ){
     pTerm->truthProb = whereCost(p->iTable) - 99;
   }else{
     pTerm->truthProb = -1;
@@ -4198,9 +4200,9 @@ static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){
       assert( p->rSetup==pTemplate->rSetup );
       if( p->prereq==pTemplate->prereq
        && p->nLTerm<pTemplate->nLTerm
-       && (p->wsFlags & WHERE_INDEXED)!=0
-       && (pTemplate->wsFlags & WHERE_INDEXED)!=0
-       && p->u.btree.pIndex==pTemplate->u.btree.pIndex
+       && (p->wsFlags & pTemplate->wsFlags & WHERE_INDEXED)!=0
+       && (p->u.btree.pIndex==pTemplate->u.btree.pIndex
+           || p->u.btree.pIndex->nColumn>=pTemplate->u.btree.pIndex->nColumn)
       ){
         /* Overwrite an existing WhereLoop with an similar one that uses
         ** more terms of the index */
@@ -4215,12 +4217,12 @@ static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){
     if( (p->prereq & pTemplate->prereq)==pTemplate->prereq
      && p->rRun>=pTemplate->rRun
      && p->nOut>=pTemplate->nOut
-     && ALWAYS(p->rSetup>=pTemplate->rSetup) /* See SETUP-INVARIANT above */
     ){
       /* Overwrite an existing WhereLoop with a better one: one that is
       ** better at one of (1) dependencies, (2) setup-cost, (3) run-cost
       ** or (4) number of output rows, and is no worse in any of those
       ** categories. */
+      assert( p->rSetup>=pTemplate->rSetup ); /* SETUP-INVARIANT above */
       pNext = p->pNextLoop;
       break;
     }
@@ -4281,6 +4283,10 @@ static void whereLoopOutputAdjust(WhereClause *pWC, WhereLoop *pLoop, int iCur){
   Bitmask notAllowed = ~(pLoop->prereq|pLoop->maskSelf);
   int x = 0;
   int i;
+
+  if( !OptimizationEnabled(pWC->pWInfo->pParse->db, SQLITE_AdjustOutEst) ){
+    return;
+  }
   for(i=pWC->nTerm, pTerm=pWC->a; i>0; i--, pTerm++){
     if( (pTerm->wtFlags & TERM_VIRTUAL)!=0 ) continue;
     if( (pTerm->prereqAll & pLoop->maskSelf)==0 ) continue;