/ Check-in [92e0b4bd]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Show tree diagrams of data structures in the debugging output when the 0x100 bit is set on sqlite3WhereTrace or sqlite3SelectTrace.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 92e0b4bd4d75e8b000586e51a07b3e181d9af20b
User & Date: drh 2014-09-30 13:46:49
Context
2014-09-30
14:14
Enhanced debug output for OR-logic in the query loop optimizer. check-in: 2e375eae user: drh tags: trunk
13:46
Show tree diagrams of data structures in the debugging output when the 0x100 bit is set on sqlite3WhereTrace or sqlite3SelectTrace. check-in: 92e0b4bd user: drh tags: trunk
12:33
Remove the SQLITE_ENABLE_TREE_EXPLAIN compile-time option. Add alternative debugging display routines: sqlite3TreeViewExpr(), sqlite3TreeViewExprList(), and sqlite3TreeViewSelect(). check-in: 4ff51325 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/select.c.

  3637   3637       }
  3638   3638     }
  3639   3639   
  3640   3640     /* Finially, delete what is left of the subquery and return
  3641   3641     ** success.
  3642   3642     */
  3643   3643     sqlite3SelectDelete(db, pSub1);
         3644  +
         3645  +#if SELECTTRACE_ENABLED
         3646  +  if( sqlite3SelectTrace & 0x100 ){
         3647  +    sqlite3DebugPrintf("After flattening:\n");
         3648  +    sqlite3TreeViewSelect(0, p, 0);
         3649  +  }
         3650  +#endif
  3644   3651   
  3645   3652     return 1;
  3646   3653   }
  3647   3654   #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
  3648   3655   
  3649   3656   /*
  3650   3657   ** Based on the contents of the AggInfo structure indicated by the first
................................................................................
  4645   4652     if( p==0 || db->mallocFailed || pParse->nErr ){
  4646   4653       return 1;
  4647   4654     }
  4648   4655     if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;
  4649   4656     memset(&sAggInfo, 0, sizeof(sAggInfo));
  4650   4657   #if SELECTTRACE_ENABLED
  4651   4658     pParse->nSelectIndent++;
  4652         -  SELECTTRACE(1,pParse,p, ("begin processing\n"));
         4659  +  SELECTTRACE(1,pParse,p, ("begin processing:\n"));
         4660  +  if( sqlite3SelectTrace & 0x100 ){
         4661  +    sqlite3TreeViewSelect(0, p, 0);
         4662  +  }
  4653   4663   #endif
  4654   4664   
  4655   4665     assert( p->pOrderBy==0 || pDest->eDest!=SRT_DistFifo );
  4656   4666     assert( p->pOrderBy==0 || pDest->eDest!=SRT_Fifo );
  4657   4667     assert( p->pOrderBy==0 || pDest->eDest!=SRT_DistQueue );
  4658   4668     assert( p->pOrderBy==0 || pDest->eDest!=SRT_Queue );
  4659   4669     if( IgnorableOrderby(pDest) ){

Changes to src/where.c.

  3751   3751         sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
  3752   3752         pTerm->wtFlags |= TERM_CODED;
  3753   3753       }
  3754   3754     }
  3755   3755   
  3756   3756     return pLevel->notReady;
  3757   3757   }
         3758  +
         3759  +#ifdef WHERETRACE_ENABLED
         3760  +/*
         3761  +** Print the content of a WhereTerm object
         3762  +*/
         3763  +static void whereTermPrint(WhereTerm *pTerm, int iTerm){
         3764  +  char zType[4];
         3765  +  memcpy(zType, "...", 4);
         3766  +  if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V';
         3767  +  if( pTerm->eOperator & WO_EQUIV  ) zType[1] = 'E';
         3768  +  if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) zType[2] = 'L';
         3769  +  sqlite3DebugPrintf("TERM-%-3d %p %s cursor=%-3d prob=%-3d op=0x%03x\n", iTerm,
         3770  +                     pTerm, zType, pTerm->leftCursor, pTerm->truthProb,
         3771  +                     pTerm->eOperator);
         3772  +  sqlite3TreeViewExpr(0, pTerm->pExpr, 0);
         3773  +}
         3774  +#endif
  3758   3775   
  3759   3776   #ifdef WHERETRACE_ENABLED
  3760   3777   /*
  3761   3778   ** Print a WhereLoop object for debugging purposes
  3762   3779   */
  3763   3780   static void whereLoopPrint(WhereLoop *p, WhereClause *pWC){
  3764   3781     WhereInfo *pWInfo = pWC->pWInfo;
................................................................................
  3794   3811     }
  3795   3812     if( p->wsFlags & WHERE_SKIPSCAN ){
  3796   3813       sqlite3DebugPrintf(" f %05x %d-%d", p->wsFlags, p->nLTerm,p->u.btree.nSkip);
  3797   3814     }else{
  3798   3815       sqlite3DebugPrintf(" f %05x N %d", p->wsFlags, p->nLTerm);
  3799   3816     }
  3800   3817     sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
         3818  +  if( p->nLTerm && (sqlite3WhereTrace & 0x100)!=0 ){
         3819  +    int i;
         3820  +    for(i=0; i<p->nLTerm; i++){
         3821  +      WhereTerm *pTerm = p->aLTerm[i];
         3822  +      if( pTerm==0 ) continue;
         3823  +      whereTermPrint(pTerm, i);
         3824  +    }
         3825  +  }
  3801   3826   }
  3802   3827   #endif
  3803   3828   
  3804   3829   /*
  3805   3830   ** Convert bulk memory into a valid WhereLoop that can be passed
  3806   3831   ** to whereLoopClear harmlessly.
  3807   3832   */
................................................................................
  6126   6151         pWInfo->wctrlFlags |= WHERE_DISTINCTBY;
  6127   6152         pWInfo->pOrderBy = pResultSet;
  6128   6153       }
  6129   6154     }
  6130   6155   
  6131   6156     /* Construct the WhereLoop objects */
  6132   6157     WHERETRACE(0xffff,("*** Optimizer Start ***\n"));
         6158  +#if defined(WHERETRACE_ENABLED)
         6159  +  /* Display all terms of the WHERE clause */
         6160  +  if( sqlite3WhereTrace & 0x100 ){
         6161  +    int i;
         6162  +    for(i=0; i<sWLB.pWC->nTerm; i++){
         6163  +      whereTermPrint(&sWLB.pWC->a[i], i);
         6164  +    }
         6165  +  }
         6166  +#endif
         6167  +
  6133   6168     if( nTabList!=1 || whereShortCut(&sWLB)==0 ){
  6134   6169       rc = whereLoopAddAll(&sWLB);
  6135   6170       if( rc ) goto whereBeginError;
  6136   6171     
  6137   6172       /* Display all of the WhereLoop objects if wheretrace is enabled */
  6138   6173   #ifdef WHERETRACE_ENABLED /* !=0 */
  6139   6174       if( sqlite3WhereTrace ){