/ Check-in [10f125f5]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Bug fix and enhancements to the improved wheretrace logic that shows the constraint expressions.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 10f125f5da55eca15e68c74d62ab7d37bbbbfb5f
User & Date: drh 2013-10-28 19:03:21
Context
2013-10-28
19:59
More wheretrace debugging support: Show a listing of all WHERE clause terms (on wheretrace bit 0x100) and include important flags such as TERM_VIRTUAL, WO_EQUIV, and EP_FromJoin. check-in: 92ccd705 user: drh tags: trunk
19:03
Bug fix and enhancements to the improved wheretrace logic that shows the constraint expressions. check-in: 10f125f5 user: drh tags: trunk
14:34
Improved "wheretrace" capabilities: Show the constraint expression if the wheretrace flag has the 0x100 bit set and if compiled with SQLITE_ENABLE_TREE_EXPLAIN. check-in: 710a18ac user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/where.c.

  3889   3889     return pLevel->notReady;
  3890   3890   }
  3891   3891   
  3892   3892   #ifdef WHERETRACE_ENABLED
  3893   3893   /*
  3894   3894   ** Print a WhereLoop object for debugging purposes
  3895   3895   */
  3896         -static void whereLoopPrint(WhereLoop *p, WhereInfo *pWInfo){
         3896  +static void whereLoopPrint(WhereLoop *p, WhereClause *pWC){
         3897  +  WhereInfo *pWInfo = pWC->pWInfo;
  3897   3898     int nb = 1+(pWInfo->pTabList->nSrc+7)/8;
  3898   3899     struct SrcList_item *pItem = pWInfo->pTabList->a + p->iTab;
  3899   3900     Table *pTab = pItem->pTab;
  3900   3901     sqlite3DebugPrintf("%c%2d.%0*llx.%0*llx", p->cId,
  3901   3902                        p->iTab, nb, p->maskSelf, nb, p->prereq);
  3902   3903     sqlite3DebugPrintf(" %12s",
  3903   3904                        pItem->zAlias ? pItem->zAlias : pTab->zName);
  3904   3905     if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
  3905         -    if( p->u.btree.pIndex ){
  3906         -      const char *zName = p->u.btree.pIndex->zName;
  3907         -      if( zName==0 ) zName = "ipk";
         3906  +     const char *zName;
         3907  +     if( p->u.btree.pIndex && (zName = p->u.btree.pIndex->zName)!=0 ){
  3908   3908         if( strncmp(zName, "sqlite_autoindex_", 17)==0 ){
  3909   3909           int i = sqlite3Strlen30(zName) - 1;
  3910   3910           while( zName[i]!='_' ) i--;
  3911   3911           zName += i;
  3912   3912         }
  3913   3913         sqlite3DebugPrintf(".%-16s %2d", zName, p->u.btree.nEq);
  3914   3914       }else{
................................................................................
  3932   3932     ** expressions in the WhereLoop.aLTerm[] array.
  3933   3933     */
  3934   3934     if( p->nLTerm && (sqlite3WhereTrace & 0x100)!=0 ){  /* WHERETRACE 0x100 */
  3935   3935       int i;
  3936   3936       Vdbe *v = pWInfo->pParse->pVdbe;
  3937   3937       sqlite3ExplainBegin(v);
  3938   3938       for(i=0; i<p->nLTerm; i++){
  3939         -      sqlite3ExplainPrintf(v, "  (%d) ", i+1);
         3939  +      WhereTerm *pTerm = p->aLTerm[i];
         3940  +      sqlite3ExplainPrintf(v, "  (%d) #%d ", i+1, (int)(pTerm-pWC->a));
         3941  +      if( (pTerm->wtFlags & (TERM_ORINFO|TERM_ANDINFO))==0 ){
         3942  +        sqlite3ExplainPrintf(v, "lhs=%-2d ", pTerm->u.leftColumn);
         3943  +      }
  3940   3944         sqlite3ExplainPush(v);
  3941         -      sqlite3ExplainExpr(v, p->aLTerm[i]->pExpr);
         3945  +      sqlite3ExplainExpr(v, pTerm->pExpr);
  3942   3946         sqlite3ExplainPop(v);
  3943   3947         sqlite3ExplainNL(v);
  3944   3948       }
  3945         -    sqlite3DebugPrintf("%s", sqlite3VdbeExplanation(v));
  3946   3949       sqlite3ExplainFinish(v);
         3950  +    sqlite3DebugPrintf("%s", sqlite3VdbeExplanation(v));
  3947   3951     }
  3948   3952   #endif
  3949   3953   }
  3950   3954   #endif
  3951   3955   
  3952   3956   /*
  3953   3957   ** Convert bulk memory into a valid WhereLoop that can be passed
................................................................................
  4084   4088       int x =
  4085   4089   #endif
  4086   4090       whereOrInsert(pBuilder->pOrSet, pTemplate->prereq, pTemplate->rRun,
  4087   4091                                       pTemplate->nOut);
  4088   4092   #if WHERETRACE_ENABLED /* 0x8 */
  4089   4093       if( sqlite3WhereTrace & 0x8 ){
  4090   4094         sqlite3DebugPrintf(x?"   or-%d:  ":"   or-X:  ", n);
  4091         -      whereLoopPrint(pTemplate, pWInfo);
         4095  +      whereLoopPrint(pTemplate, pBuilder->pWC);
  4092   4096       }
  4093   4097   #endif
  4094   4098       return SQLITE_OK;
  4095   4099     }
  4096   4100   
  4097   4101     /* Search for an existing WhereLoop to overwrite, or which takes
  4098   4102     ** priority over pTemplate.
................................................................................
  4158   4162     ** with pTemplate[] if p[] exists, or if p==NULL then allocate a new
  4159   4163     ** WhereLoop and insert it.
  4160   4164     */
  4161   4165   #if WHERETRACE_ENABLED /* 0x8 */
  4162   4166     if( sqlite3WhereTrace & 0x8 ){
  4163   4167       if( p!=0 ){
  4164   4168         sqlite3DebugPrintf("ins-del:  ");
  4165         -      whereLoopPrint(p, pWInfo);
         4169  +      whereLoopPrint(p, pBuilder->pWC);
  4166   4170       }
  4167   4171       sqlite3DebugPrintf("ins-new:  ");
  4168         -    whereLoopPrint(pTemplate, pWInfo);
         4172  +    whereLoopPrint(pTemplate, pBuilder->pWC);
  4169   4173     }
  4170   4174   #endif
  4171   4175     if( p==0 ){
  4172   4176       p = sqlite3DbMallocRaw(db, sizeof(WhereLoop));
  4173   4177       if( p==0 ) return SQLITE_NOMEM;
  4174   4178       whereLoopInit(p);
  4175   4179     }
................................................................................
  4185   4189     return SQLITE_OK;
  4186   4190   
  4187   4191     /* Jump here if the insert is a no-op */
  4188   4192   whereLoopInsert_noop:
  4189   4193   #if WHERETRACE_ENABLED /* 0x8 */
  4190   4194     if( sqlite3WhereTrace & 0x8 ){
  4191   4195       sqlite3DebugPrintf("ins-noop: ");
  4192         -    whereLoopPrint(pTemplate, pWInfo);
         4196  +    whereLoopPrint(pTemplate, pBuilder->pWC);
  4193   4197     }
  4194   4198   #endif
  4195   4199     return SQLITE_OK;  
  4196   4200   }
  4197   4201   
  4198   4202   /*
  4199   4203   ** Adjust the WhereLoop.nOut value downward to account for terms of the
................................................................................
  5844   5848       if( sqlite3WhereTrace ){
  5845   5849         WhereLoop *p;
  5846   5850         int i;
  5847   5851         static char zLabel[] = "0123456789abcdefghijklmnopqrstuvwyxz"
  5848   5852                                          "ABCDEFGHIJKLMNOPQRSTUVWYXZ";
  5849   5853         for(p=pWInfo->pLoops, i=0; p; p=p->pNextLoop, i++){
  5850   5854           p->cId = zLabel[i%sizeof(zLabel)];
  5851         -        whereLoopPrint(p, pWInfo);
         5855  +        whereLoopPrint(p, sWLB.pWC);
  5852   5856         }
  5853   5857       }
  5854   5858   #endif
  5855   5859     
  5856   5860       wherePathSolver(pWInfo, 0);
  5857   5861       if( db->mallocFailed ) goto whereBeginError;
  5858   5862       if( pWInfo->pOrderBy ){
................................................................................
  5885   5889         case WHERE_DISTINCT_UNORDERED: {
  5886   5890           sqlite3DebugPrintf("  DISTINCT=unordered");
  5887   5891           break;
  5888   5892         }
  5889   5893       }
  5890   5894       sqlite3DebugPrintf("\n");
  5891   5895       for(ii=0; ii<pWInfo->nLevel; ii++){
  5892         -      whereLoopPrint(pWInfo->a[ii].pWLoop, pWInfo);
         5896  +      whereLoopPrint(pWInfo->a[ii].pWLoop, sWLB.pWC);
  5893   5897       }
  5894   5898     }
  5895   5899   #endif
  5896   5900     /* Attempt to omit tables from the join that do not effect the result */
  5897   5901     if( pWInfo->nLevel>=2
  5898   5902      && pResultSet!=0
  5899   5903      && OptimizationEnabled(db, SQLITE_OmitNoopJoin)