]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Allow tracing of whereLoopInsert() when the 0x8 bit is set on ".wheretrace".
authordrh <drh@noemail.net>
Fri, 31 May 2013 15:18:46 +0000 (15:18 +0000)
committerdrh <drh@noemail.net>
Fri, 31 May 2013 15:18:46 +0000 (15:18 +0000)
Remove the use of sqlite_query_plan from where2.test.  Fix a bug in the
code generator for OR clause optimizations.

FossilOrigin-Name: 707f0323264c35be14847a6adc49a0dc5eaf4ad2

manifest
manifest.uuid
src/where.c
test/where2.test

index b3d407069ef93b3b0bcce9f4d45a72570ec61d9a..535b2266fec596d2c60579436d97f38ec8a1f855 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Enhance\sthe\sshell\sto\sprovide\smore\sflexibility\swhen\sentering\snumeric\sarguments\non\sdot-commands.\s\sIn\sparticular,\sallow\shex\sarguments\sto\s.wheretrace.
-D 2013-05-31T14:31:11.784
+C Allow\stracing\sof\swhereLoopInsert()\swhen\sthe\s0x8\sbit\sis\sset\son\s".wheretrace".\nRemove\sthe\suse\sof\ssqlite_query_plan\sfrom\swhere2.test.\s\sFix\sa\sbug\sin\sthe\ncode\sgenerator\sfor\sOR\sclause\soptimizations.
+D 2013-05-31T15:18:46.709
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -289,7 +289,7 @@ F src/vtab.c b05e5f1f4902461ba9f5fc49bb7eb7c3a0741a83
 F src/wal.c 436bfceb141b9423c45119e68e444358ee0ed35d
 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
 F src/walker.c 4fa43583d0a84b48f93b1e88f11adf2065be4e73
-F src/where.c 8e9922815b07290982cfc826497d128115ce358c
+F src/where.c e120e28cb55cea658589ec2eca5764dcfa0396c2
 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
 F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6
@@ -1029,7 +1029,7 @@ F test/walshared.test 6dda2293880c300baf5d791c307f653094585761
 F test/walslow.test e7be6d9888f83aa5d3d3c7c08aa9b5c28b93609a
 F test/walthread.test de8dbaf6d9e41481c460ba31ca61e163d7348f8e
 F test/where.test 054a6b6f7933c5a5f50d0bcd650b5eccb450cc81
-F test/where2.test 399b3178289925a0aa976b3d60ef139740540ecd
+F test/where2.test f902f62d60f20b0257dd700f0c4a2945527fca8e
 F test/where3.test 667e75642102c97a00bf9b23d3cb267db321d006
 F test/where4.test e9b9e2f2f98f00379e6031db6a6fca29bae782a2
 F test/where5.test fdf66f96d29a064b63eb543e28da4dfdccd81ad2
@@ -1093,7 +1093,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 d8efa5f8b60bc4c8df8bfad077f87f76f7ee9bf6
-R cab66f9edd3249c76db6815f19ee5773
+P b9578c371ee569dca6a0964019959a93407c8ef9
+R 10e84b9c96bf0dc4179bf10aeea4849d
 U drh
-Z 93073f371b16237bef628d122f206ede
+Z 1f5041366a1e7c65f32184b30b5b84bc
index 277db05743aa530f513cdf62ff029c12592d1a3e..f519953e679983e0052101c35b7acf300c0bf445 100644 (file)
@@ -1 +1 @@
-b9578c371ee569dca6a0964019959a93407c8ef9
\ No newline at end of file
+707f0323264c35be14847a6adc49a0dc5eaf4ad2
\ No newline at end of file
index d4f9a714414bcc6ecb75dc1b20ffa3f513fcd75f..6b4521b40a45ba224c4e6424565e18d132c41adf 100644 (file)
@@ -3758,6 +3758,7 @@ static void whereLoopPrint(WhereLoop *p, SrcList *pTabList){
   if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
     if( p->u.btree.pIndex ){
       const char *zName = p->u.btree.pIndex->zName;
+      if( zName==0 ) zName = "ipk";
       if( strncmp(zName, "sqlite_autoindex_", 17)==0 ){
         int i = sqlite3Strlen30(zName) - 1;
         while( zName[i]!='_' ) i--;
@@ -3865,16 +3866,22 @@ static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){
   if( (p = pBuilder->pBest)!=0 ){
     if( p->maskSelf!=0 ){
       if( p->rRun+p->rSetup < pTemplate->rRun+pTemplate->rSetup ){
-        return SQLITE_OK;
+        goto whereLoopInsert_noop;
       }
       if( p->rRun+p->rSetup == pTemplate->rRun+pTemplate->rSetup
        && p->prereq <= pTemplate->prereq ){
-        return SQLITE_OK;
+        goto whereLoopInsert_noop;
       }
     }
     *p = *pTemplate;
     p->aTerm = 0;
     p->u.vtab.needFree = 0;
+#if WHERETRACE_ENABLED
+    if( sqlite3WhereTrace & 0x8 ){
+      sqlite3DebugPrintf("ins-best: ");
+      whereLoopPrint(pTemplate, pBuilder->pTabList);
+    }
+#endif
     return SQLITE_OK;
   }
 
@@ -3901,7 +3908,7 @@ static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){
     ){
       /* Already holding an equal or better WhereLoop.
       ** Return without changing or adding anything */
-      return SQLITE_OK;
+      goto whereLoopInsert_noop;
     }
     if( (p->prereq & pTemplate->prereq)==pTemplate->prereq
      && p->rSetup>=pTemplate->rSetup
@@ -3918,6 +3925,16 @@ static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){
   ** with pTemplate[] if p[] exists, or if p==NULL then allocate a new
   ** WhereLoop and insert it.
   */
+#if WHERETRACE_ENABLED
+  if( sqlite3WhereTrace & 0x8 ){
+    if( p!=0 ){
+      sqlite3DebugPrintf("ins-del:  ");
+      whereLoopPrint(p, pBuilder->pTabList);
+    }
+    sqlite3DebugPrintf("ins-new:  ");
+    whereLoopPrint(pTemplate, pBuilder->pTabList);
+  }
+#endif
   if( p==0 ){
     p = pToFree = sqlite3DbMallocRaw(db, sizeof(WhereLoop));
     if( p==0 ) return SQLITE_NOMEM;
@@ -3945,6 +3962,16 @@ static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){
     pTemplate->u.vtab.needFree = 0;
   }
   return SQLITE_OK;
+
+  /* Jump here if the insert is a no-op */
+whereLoopInsert_noop:
+#if WHERETRACE_ENABLED
+  if( sqlite3WhereTrace & 0x8 ){
+    sqlite3DebugPrintf("ins-noop: ");
+    whereLoopPrint(pTemplate, pBuilder->pTabList);
+  }
+#endif
+  return SQLITE_OK;  
 }
 
 /*
@@ -4156,7 +4183,7 @@ static int whereLoopAddBtree(
         pNew->u.btree.pIndex = 0;
         pNew->nTerm = 1;
         pNew->aTerm[0] = pTerm;
-        pNew->rSetup = 2*rLogSize*pSrc->pTab->nRowEst;
+        pNew->rSetup = 20*rLogSize*pSrc->pTab->nRowEst;
         pNew->nOut = (double)10;
         pNew->rRun = rLogSize + pNew->nOut;
         pNew->wsFlags = WHERE_TEMP_INDEX;
@@ -4773,8 +4800,8 @@ static int wherePathSolver(WhereInfo *pWInfo, double nRowEst){
         }
         if( jj>=nTo ){
           if( nTo>=mxChoice && rCost>=mxCost ){
-#ifdef WHERETRACE_ENABLE
-            if( sqlite3WhereTrace>=3 ){
+#ifdef WHERETRACE_ENABLED
+            if( sqlite3WhereTrace&0x4 ){
               sqlite3DebugPrintf("Skip   %s cost=%-7.2g order=%c\n",
                   wherePathName(pFrom, iLoop, pWLoop), rCost,
                   isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
@@ -4792,7 +4819,7 @@ static int wherePathSolver(WhereInfo *pWInfo, double nRowEst){
           }
           pTo = &aTo[jj];
 #ifdef WHERETRACE_ENABLED
-          if( sqlite3WhereTrace>=3 ){
+          if( sqlite3WhereTrace&0x4 ){
             sqlite3DebugPrintf("New    %s cost=%-7.2g order=%c\n",
                 wherePathName(pFrom, iLoop, pWLoop), rCost,
                 isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
@@ -4801,7 +4828,7 @@ static int wherePathSolver(WhereInfo *pWInfo, double nRowEst){
         }else{
           if( pTo->rCost<=rCost ){
 #ifdef WHERETRACE_ENABLED
-            if( sqlite3WhereTrace>=3 ){
+            if( sqlite3WhereTrace&0x4 ){
               sqlite3DebugPrintf(
                   "Skip   %s cost=%-7.2g order=%c",
                   wherePathName(pFrom, iLoop, pWLoop), rCost,
@@ -4815,7 +4842,7 @@ static int wherePathSolver(WhereInfo *pWInfo, double nRowEst){
           }
           /* A new and better score for a previously created equivalent path */
 #ifdef WHERETRACE_ENABLED
-          if( sqlite3WhereTrace>=3 ){
+          if( sqlite3WhereTrace&0x4 ){
             sqlite3DebugPrintf(
                 "Update %s cost=%-7.2g order=%c",
                 wherePathName(pFrom, iLoop, pWLoop), rCost,
@@ -5239,9 +5266,8 @@ WhereInfo *sqlite3WhereBegin(
     if( pLoop->u.btree.pIndex!=0 ){
       Index *pIx = pLoop->u.btree.pIndex;
       KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIx);
-      /* FIXME:  Might need to be the iIdxCur parameter.  As an optimization
-      ** use pTabItem->iCursor if WHERE_IDX_ONLY */
-      int iIndexCur = pLevel->iIdxCur = pParse->nTab++;
+      /* FIXME:  As an optimization use pTabItem->iCursor if WHERE_IDX_ONLY */
+      int iIndexCur = pLevel->iIdxCur = iIdxCur ? iIdxCur : pParse->nTab++;
       assert( pIx->pSchema==pTab->pSchema );
       assert( iIndexCur>=0 );
       sqlite3VdbeAddOp4(v, OP_OpenRead, iIndexCur, pIx->tnum, iDb,
index e8c2f3613f99cea37fd8b256e8dfbf4103777efe..60937adcc5de93f8506e7447502f2f83a095636b 100644 (file)
@@ -73,7 +73,18 @@ proc queryplan {sql} {
   set data [execsql $sql]
   if {$::sqlite_sort_count} {set x sort} {set x nosort}
   lappend data $x
-  return [concat $data $::sqlite_query_plan]
+  set eqp [execsql "EXPLAIN QUERY PLAN $sql"]
+  # puts eqp=$eqp
+  foreach {a b c x} $eqp {
+    if {[regexp { TABLE (\w+ AS )?(\w+) USING.* INDEX (\w+)\W} \
+        $x all as tab idx]} {
+      lappend data $tab $idx
+    } elseif {[regexp { TABLE (\w+ AS )?(\w+)\W} $x all as tab]} {
+      lappend data $tab *
+    }
+  }
+  return $data   
+  # return [concat $data $::sqlite_query_plan]
 }