Improved "wheretrace" capabilities: Show the constraint expression if the
wheretrace flag has the 0x100 bit set and if compiled with SQLITE_ENABLE_TREE_EXPLAIN. FossilOrigin-Name: 710a18ac7916cb688955505d7d461b461f563155
This commit is contained in:
+41
-22
@@ -2550,7 +2550,7 @@ static int whereRangeScanEst(
|
||||
nOut = nNew;
|
||||
}
|
||||
pLoop->nOut = (LogEst)nOut;
|
||||
WHERETRACE(0x100, ("range scan regions: %u..%u est=%d\n",
|
||||
WHERETRACE(0x10, ("range scan regions: %u..%u est=%d\n",
|
||||
(u32)iLower, (u32)iUpper, nOut));
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -2636,7 +2636,7 @@ static int whereEqualScanEst(
|
||||
pBuilder->nRecValid = nEq;
|
||||
|
||||
whereKeyStats(pParse, p, pRec, 0, a);
|
||||
WHERETRACE(0x100,("equality scan regions: %d\n", (int)a[1]));
|
||||
WHERETRACE(0x10,("equality scan regions: %d\n", (int)a[1]));
|
||||
*pnRow = a[1];
|
||||
|
||||
return rc;
|
||||
@@ -2684,7 +2684,7 @@ static int whereInScanEst(
|
||||
if( rc==SQLITE_OK ){
|
||||
if( nRowEst > p->aiRowEst[0] ) nRowEst = p->aiRowEst[0];
|
||||
*pnRow = nRowEst;
|
||||
WHERETRACE(0x100,("IN row estimate: est=%g\n", nRowEst));
|
||||
WHERETRACE(0x10,("IN row estimate: est=%g\n", nRowEst));
|
||||
}
|
||||
assert( pBuilder->nRecValid==nRecValid );
|
||||
return rc;
|
||||
@@ -3893,9 +3893,9 @@ static Bitmask codeOneLoopStart(
|
||||
/*
|
||||
** Print a WhereLoop object for debugging purposes
|
||||
*/
|
||||
static void whereLoopPrint(WhereLoop *p, SrcList *pTabList){
|
||||
int nb = 1+(pTabList->nSrc+7)/8;
|
||||
struct SrcList_item *pItem = pTabList->a + p->iTab;
|
||||
static void whereLoopPrint(WhereLoop *p, WhereInfo *pWInfo){
|
||||
int nb = 1+(pWInfo->pTabList->nSrc+7)/8;
|
||||
struct SrcList_item *pItem = pWInfo->pTabList->a + p->iTab;
|
||||
Table *pTab = pItem->pTab;
|
||||
sqlite3DebugPrintf("%c%2d.%0*llx.%0*llx", p->cId,
|
||||
p->iTab, nb, p->maskSelf, nb, p->prereq);
|
||||
@@ -3927,6 +3927,25 @@ static void whereLoopPrint(WhereLoop *p, SrcList *pTabList){
|
||||
}
|
||||
sqlite3DebugPrintf(" f %04x N %d", p->wsFlags, p->nLTerm);
|
||||
sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
|
||||
#ifdef SQLITE_ENABLE_TREE_EXPLAIN
|
||||
/* If the 0x100 bit of wheretracing is set, then show all of the constraint
|
||||
** expressions in the WhereLoop.aLTerm[] array.
|
||||
*/
|
||||
if( p->nLTerm && (sqlite3WhereTrace & 0x100)!=0 ){ /* WHERETRACE 0x100 */
|
||||
int i;
|
||||
Vdbe *v = pWInfo->pParse->pVdbe;
|
||||
sqlite3ExplainBegin(v);
|
||||
for(i=0; i<p->nLTerm; i++){
|
||||
sqlite3ExplainPrintf(v, " (%d) ", i+1);
|
||||
sqlite3ExplainPush(v);
|
||||
sqlite3ExplainExpr(v, p->aLTerm[i]->pExpr);
|
||||
sqlite3ExplainPop(v);
|
||||
sqlite3ExplainNL(v);
|
||||
}
|
||||
sqlite3DebugPrintf("%s", sqlite3VdbeExplanation(v));
|
||||
sqlite3ExplainFinish(v);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -4066,10 +4085,10 @@ static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){
|
||||
#endif
|
||||
whereOrInsert(pBuilder->pOrSet, pTemplate->prereq, pTemplate->rRun,
|
||||
pTemplate->nOut);
|
||||
#if WHERETRACE_ENABLED
|
||||
#if WHERETRACE_ENABLED /* 0x8 */
|
||||
if( sqlite3WhereTrace & 0x8 ){
|
||||
sqlite3DebugPrintf(x?" or-%d: ":" or-X: ", n);
|
||||
whereLoopPrint(pTemplate, pWInfo->pTabList);
|
||||
whereLoopPrint(pTemplate, pWInfo);
|
||||
}
|
||||
#endif
|
||||
return SQLITE_OK;
|
||||
@@ -4139,14 +4158,14 @@ 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 WHERETRACE_ENABLED /* 0x8 */
|
||||
if( sqlite3WhereTrace & 0x8 ){
|
||||
if( p!=0 ){
|
||||
sqlite3DebugPrintf("ins-del: ");
|
||||
whereLoopPrint(p, pWInfo->pTabList);
|
||||
whereLoopPrint(p, pWInfo);
|
||||
}
|
||||
sqlite3DebugPrintf("ins-new: ");
|
||||
whereLoopPrint(pTemplate, pWInfo->pTabList);
|
||||
whereLoopPrint(pTemplate, pWInfo);
|
||||
}
|
||||
#endif
|
||||
if( p==0 ){
|
||||
@@ -4167,10 +4186,10 @@ static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){
|
||||
|
||||
/* Jump here if the insert is a no-op */
|
||||
whereLoopInsert_noop:
|
||||
#if WHERETRACE_ENABLED
|
||||
#if WHERETRACE_ENABLED /* 0x8 */
|
||||
if( sqlite3WhereTrace & 0x8 ){
|
||||
sqlite3DebugPrintf("ins-noop: ");
|
||||
whereLoopPrint(pTemplate, pWInfo->pTabList);
|
||||
whereLoopPrint(pTemplate, pWInfo);
|
||||
}
|
||||
#endif
|
||||
return SQLITE_OK;
|
||||
@@ -5328,7 +5347,7 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){
|
||||
}
|
||||
if( jj>=nTo ){
|
||||
if( nTo>=mxChoice && rCost>=mxCost ){
|
||||
#ifdef WHERETRACE_ENABLED
|
||||
#ifdef WHERETRACE_ENABLED /* 0x4 */
|
||||
if( sqlite3WhereTrace&0x4 ){
|
||||
sqlite3DebugPrintf("Skip %s cost=%-3d,%3d order=%c\n",
|
||||
wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
|
||||
@@ -5346,7 +5365,7 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){
|
||||
jj = mxI;
|
||||
}
|
||||
pTo = &aTo[jj];
|
||||
#ifdef WHERETRACE_ENABLED
|
||||
#ifdef WHERETRACE_ENABLED /* 0x4 */
|
||||
if( sqlite3WhereTrace&0x4 ){
|
||||
sqlite3DebugPrintf("New %s cost=%-3d,%3d order=%c\n",
|
||||
wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
|
||||
@@ -5355,7 +5374,7 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){
|
||||
#endif
|
||||
}else{
|
||||
if( pTo->rCost<=rCost && pTo->nRow<=nOut ){
|
||||
#ifdef WHERETRACE_ENABLED
|
||||
#ifdef WHERETRACE_ENABLED /* 0x4 */
|
||||
if( sqlite3WhereTrace&0x4 ){
|
||||
sqlite3DebugPrintf(
|
||||
"Skip %s cost=%-3d,%3d order=%c",
|
||||
@@ -5371,7 +5390,7 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){
|
||||
}
|
||||
testcase( pTo->rCost==rCost+1 );
|
||||
/* A new and better score for a previously created equivalent path */
|
||||
#ifdef WHERETRACE_ENABLED
|
||||
#ifdef WHERETRACE_ENABLED /* 0x4 */
|
||||
if( sqlite3WhereTrace&0x4 ){
|
||||
sqlite3DebugPrintf(
|
||||
"Update %s cost=%-3d,%3d order=%c",
|
||||
@@ -5407,7 +5426,7 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WHERETRACE_ENABLED
|
||||
#ifdef WHERETRACE_ENABLED /* >=2 */
|
||||
if( sqlite3WhereTrace>=2 ){
|
||||
sqlite3DebugPrintf("---- after round %d ----\n", iLoop);
|
||||
for(ii=0, pTo=aTo; ii<nTo; ii++, pTo++){
|
||||
@@ -5821,7 +5840,7 @@ WhereInfo *sqlite3WhereBegin(
|
||||
if( rc ) goto whereBeginError;
|
||||
|
||||
/* Display all of the WhereLoop objects if wheretrace is enabled */
|
||||
#ifdef WHERETRACE_ENABLED
|
||||
#ifdef WHERETRACE_ENABLED /* !=0 */
|
||||
if( sqlite3WhereTrace ){
|
||||
WhereLoop *p;
|
||||
int i;
|
||||
@@ -5829,7 +5848,7 @@ WhereInfo *sqlite3WhereBegin(
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWYXZ";
|
||||
for(p=pWInfo->pLoops, i=0; p; p=p->pNextLoop, i++){
|
||||
p->cId = zLabel[i%sizeof(zLabel)];
|
||||
whereLoopPrint(p, pTabList);
|
||||
whereLoopPrint(p, pWInfo);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -5847,7 +5866,7 @@ WhereInfo *sqlite3WhereBegin(
|
||||
if( pParse->nErr || NEVER(db->mallocFailed) ){
|
||||
goto whereBeginError;
|
||||
}
|
||||
#ifdef WHERETRACE_ENABLED
|
||||
#ifdef WHERETRACE_ENABLED /* !=0 */
|
||||
if( sqlite3WhereTrace ){
|
||||
int ii;
|
||||
sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut);
|
||||
@@ -5870,7 +5889,7 @@ WhereInfo *sqlite3WhereBegin(
|
||||
}
|
||||
sqlite3DebugPrintf("\n");
|
||||
for(ii=0; ii<pWInfo->nLevel; ii++){
|
||||
whereLoopPrint(pWInfo->a[ii].pWLoop, pTabList);
|
||||
whereLoopPrint(pWInfo->a[ii].pWLoop, pWInfo);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user