1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-12 13:01:09 +03:00

Improved ".selecttrace" output.

FossilOrigin-Name: c0b61f7092a7fd2c5f51db26ce7a7a5c75c227fe
This commit is contained in:
drh
2014-09-21 00:27:26 +00:00
parent 7c0a4720ca
commit eb9b884c2d
6 changed files with 59 additions and 25 deletions

View File

@@ -1,5 +1,5 @@
C Candidate\sfix\sfor\s[d11a6e908f]. C Improved\s".selecttrace"\soutput.
D 2014-09-20T20:38:48.213 D 2014-09-21T00:27:26.734
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in cf57f673d77606ab0f2d9627ca52a9ba1464146a F Makefile.in cf57f673d77606ab0f2d9627ca52a9ba1464146a
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -180,7 +180,7 @@ F src/complete.c 535183afb3c75628b78ce82612931ac7cdf26f14
F src/ctime.c 16cd19215d9fd849ee2b7509b092f2e0bbd6a958 F src/ctime.c 16cd19215d9fd849ee2b7509b092f2e0bbd6a958
F src/date.c 57a7f9ba9f6b4d5268f5e411739066a611f99036 F src/date.c 57a7f9ba9f6b4d5268f5e411739066a611f99036
F src/delete.c fae81cc2eb14b75267d4f47d3cfc9ae02aae726f F src/delete.c fae81cc2eb14b75267d4f47d3cfc9ae02aae726f
F src/expr.c 51dfaa60c0ec9db231535c98ae9ad5ab1409fd88 F src/expr.c 4f101c8ddc6d5a22303c88278069f5261562a9a8
F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
F src/fkey.c da985ae673efef2c712caef825a5d2edb087ead7 F src/fkey.c da985ae673efef2c712caef825a5d2edb087ead7
F src/func.c 1629ccdd8ef3f19d7accc9d9287190489469ff81 F src/func.c 1629ccdd8ef3f19d7accc9d9287190489469ff81
@@ -216,7 +216,7 @@ F src/os_win.c 0a4042ef35f322e86fa01f6c8884c5e645b911e7
F src/os_win.h 09e751b20bbc107ffbd46e13555dc73576d88e21 F src/os_win.h 09e751b20bbc107ffbd46e13555dc73576d88e21
F src/pager.c caab007743821d96752597c9cfd7351654697b06 F src/pager.c caab007743821d96752597c9cfd7351654697b06
F src/pager.h ffd5607f7b3e4590b415b007a4382f693334d428 F src/pager.h ffd5607f7b3e4590b415b007a4382f693334d428
F src/parse.y 1976d28f168c63c6c14008e9a896620e0c76c25e F src/parse.y b98772da2bb5415970085b707203f92569400aa8
F src/pcache.c 4121a0571c18581ee9f82f086d5e2030051ebd6a F src/pcache.c 4121a0571c18581ee9f82f086d5e2030051ebd6a
F src/pcache.h 9b559127b83f84ff76d735c8262f04853be0c59a F src/pcache.h 9b559127b83f84ff76d735c8262f04853be0c59a
F src/pcache1.c dab8ab930d4a73b99768d881185994f34b80ecaa F src/pcache1.c dab8ab930d4a73b99768d881185994f34b80ecaa
@@ -226,12 +226,12 @@ F src/printf.c 3a47f526b173813d9a7f4e7044007771ba68cde1
F src/random.c d10c1f85b6709ca97278428fd5db5bbb9c74eece F src/random.c d10c1f85b6709ca97278428fd5db5bbb9c74eece
F src/resolve.c a3466128b52a86c466e47ac1a19e2174f7b5cf89 F src/resolve.c a3466128b52a86c466e47ac1a19e2174f7b5cf89
F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e
F src/select.c 3108c73dff614eb8771cd251bed41e3fa5dfe33f F src/select.c a83ed8bc2a31c131e3addb6f0488b68334085e7b
F src/shell.c dad23987c34faddb061a339da3e92e05ccc6935e F src/shell.c dad23987c34faddb061a339da3e92e05ccc6935e
F src/sqlite.h.in 8b018219ce988913e5977d5de9ab4beb33be23b6 F src/sqlite.h.in 8b018219ce988913e5977d5de9ab4beb33be23b6
F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad
F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d
F src/sqliteInt.h 1020906859d2c369d214fd43f52c94385bbd38cc F src/sqliteInt.h 5ecde2191721a94cdce0d5248e26a373e0b17a70
F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158
F src/table.c 2e99ef7ef16187e17033d9398dc962ce22dab5cb F src/table.c 2e99ef7ef16187e17033d9398dc962ce22dab5cb
@@ -1198,7 +1198,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P f1ba68f131d2f03e4a7bc50cde23a7609d384279 P 89398880bcfff96e91d2a9c45774f5fb3209ffc1
R 9363b1bc0cd8b39c47583b734f41ef37 R 279ae11a33db61e53f043e359f81738d
U dan U drh
Z 365a1de296dc4c896c5c2cb92f759a75 Z f68417c1797c667ad48e7e326a25e63f

View File

@@ -1 +1 @@
89398880bcfff96e91d2a9c45774f5fb3209ffc1 c0b61f7092a7fd2c5f51db26ce7a7a5c75c227fe

View File

@@ -1069,9 +1069,7 @@ Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
pNew->addrOpenEphm[1] = -1; pNew->addrOpenEphm[1] = -1;
pNew->nSelectRow = p->nSelectRow; pNew->nSelectRow = p->nSelectRow;
pNew->pWith = withDup(db, p->pWith); pNew->pWith = withDup(db, p->pWith);
#if SELECTTRACE_ENABLED sqlite3SelectSetName(pNew, p->zSelName);
memcpy(pNew->zSelLabel, p->zSelLabel, sizeof(p->zSelLabel));
#endif
return pNew; return pNew;
} }
#else #else

View File

@@ -463,26 +463,26 @@ oneselect(A) ::= SELECT(S) distinct(D) selcollist(W) from(X) where_opt(Y)
groupby_opt(P) having_opt(Q) orderby_opt(Z) limit_opt(L). { groupby_opt(P) having_opt(Q) orderby_opt(Z) limit_opt(L). {
A = sqlite3SelectNew(pParse,W,X,Y,P,Q,Z,D,L.pLimit,L.pOffset); A = sqlite3SelectNew(pParse,W,X,Y,P,Q,Z,D,L.pLimit,L.pOffset);
#if SELECTTRACE_ENABLED #if SELECTTRACE_ENABLED
/* Populate the Select.zSelLabel[] string that is used to help with /* Populate the Select.zSelName[] string that is used to help with
** query planner debugging, to differentiate between multiple Select ** query planner debugging, to differentiate between multiple Select
** objects in a complex query. ** objects in a complex query.
** **
** If the SELECT keyword is immediately followed by a C-style comment ** If the SELECT keyword is immediately followed by a C-style comment
** then extract the first few alphanumeric characters from within that ** then extract the first few alphanumeric characters from within that
** comment to be the zSelLabel value. Otherwise, the label is #N where ** comment to be the zSelName value. Otherwise, the label is #N where
** is an integer that is incremented with each SELECT statement seen. ** is an integer that is incremented with each SELECT statement seen.
*/ */
if( A!=0 ){ if( A!=0 ){
const char *z = S.z+6; const char *z = S.z+6;
int i; int i;
sqlite3_snprintf(sizeof(A->zSelLabel), A->zSelLabel, "#%d", sqlite3_snprintf(sizeof(A->zSelName), A->zSelName, "#%d",
++pParse->nSelect); ++pParse->nSelect);
while( z[0]==' ' ) z++; while( z[0]==' ' ) z++;
if( z[0]=='/' && z[1]=='*' ){ if( z[0]=='/' && z[1]=='*' ){
z += 2; z += 2;
while( z[0]==' ' ) z++; while( z[0]==' ' ) z++;
for(i=0; sqlite3Isalnum(z[i]); i++){} for(i=0; sqlite3Isalnum(z[i]); i++){}
sqlite3_snprintf(sizeof(A->zSelLabel), A->zSelLabel, "%.*s", i, z); sqlite3_snprintf(sizeof(A->zSelName), A->zSelName, "%.*s", i, z);
} }
} }
#endif /* SELECTRACE_ENABLED */ #endif /* SELECTRACE_ENABLED */

View File

@@ -19,9 +19,12 @@
*/ */
#if SELECTTRACE_ENABLED #if SELECTTRACE_ENABLED
/***/ int sqlite3SelectTrace = 0; /***/ int sqlite3SelectTrace = 0;
# define SELECTTRACE(K,X) if(sqlite3SelectTrace&(K)) sqlite3DebugPrintf X # define SELECTTRACE(K,P,S,X) \
if(sqlite3SelectTrace&(K)) \
sqlite3DebugPrintf("%*s%s.%p: ",(P)->nSelectIndent*2-2,"",(S)->zSelName,(S)),\
sqlite3DebugPrintf X
#else #else
# define SELECTTRACE(K,X) # define SELECTTRACE(K,P,S,X)
#endif #endif
@@ -137,6 +140,18 @@ Select *sqlite3SelectNew(
return pNew; return pNew;
} }
#if SELECTTRACE_ENABLED
/*
** Set the name of a Select object
*/
void sqlite3SelectSetName(Select *p, const char *zName){
if( p && zName ){
sqlite3_snprintf(sizeof(p->zSelName), p->zSelName, "%s", zName);
}
}
#endif
/* /*
** Delete the given Select structure and all of its substructures. ** Delete the given Select structure and all of its substructures.
*/ */
@@ -3366,8 +3381,8 @@ static int flattenSubquery(
} }
/***** If we reach this point, flattening is permitted. *****/ /***** If we reach this point, flattening is permitted. *****/
SELECTTRACE(1, ("flatten %s (term %d) into %s\n", SELECTTRACE(1,pParse,p,("flatten %s.%p from term %d\n",
pSub->zSelLabel, iFrom, p->zSelLabel)); pSub->zSelName, pSub, iFrom));
/* Authorize the subquery */ /* Authorize the subquery */
pParse->zAuthContext = pSubitem->zName; pParse->zAuthContext = pSubitem->zName;
@@ -3420,6 +3435,7 @@ static int flattenSubquery(
p->pLimit = 0; p->pLimit = 0;
p->pOffset = 0; p->pOffset = 0;
pNew = sqlite3SelectDup(db, p, 0); pNew = sqlite3SelectDup(db, p, 0);
sqlite3SelectSetName(pNew, pSub->zSelName);
p->pOffset = pOffset; p->pOffset = pOffset;
p->pLimit = pLimit; p->pLimit = pLimit;
p->pOrderBy = pOrderBy; p->pOrderBy = pOrderBy;
@@ -3432,6 +3448,9 @@ static int flattenSubquery(
if( pPrior ) pPrior->pNext = pNew; if( pPrior ) pPrior->pNext = pNew;
pNew->pNext = p; pNew->pNext = p;
p->pPrior = pNew; p->pPrior = pNew;
SELECTTRACE(2,pParse,p,
("compound-subquery flattener creates %s.%p as peer\n",
pNew->zSelName, pNew));
} }
if( db->mallocFailed ) return 1; if( db->mallocFailed ) return 1;
} }
@@ -4093,6 +4112,7 @@ static int selectExpander(Walker *pWalker, Select *p){
if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort; if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort;
assert( pFrom->pSelect==0 ); assert( pFrom->pSelect==0 );
pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0); pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0);
sqlite3SelectSetName(pFrom->pSelect, pTab->zName);
sqlite3WalkSelect(pWalker, pFrom->pSelect); sqlite3WalkSelect(pWalker, pFrom->pSelect);
} }
#endif #endif
@@ -4627,7 +4647,10 @@ int sqlite3Select(
} }
if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1; if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;
memset(&sAggInfo, 0, sizeof(sAggInfo)); memset(&sAggInfo, 0, sizeof(sAggInfo));
SELECTTRACE(1, ("begin processing %s\n", p->zSelLabel)); #if SELECTTRACE_ENABLED
pParse->nSelectIndent++;
SELECTTRACE(1,pParse,p, ("begin processing\n"));
#endif
assert( p->pOrderBy==0 || pDest->eDest!=SRT_DistFifo ); assert( p->pOrderBy==0 || pDest->eDest!=SRT_DistFifo );
assert( p->pOrderBy==0 || pDest->eDest!=SRT_Fifo ); assert( p->pOrderBy==0 || pDest->eDest!=SRT_Fifo );
@@ -4784,6 +4807,10 @@ int sqlite3Select(
if( p->pPrior ){ if( p->pPrior ){
rc = multiSelect(pParse, p, pDest); rc = multiSelect(pParse, p, pDest);
explainSetInteger(pParse->iSelectId, iRestoreSelectId); explainSetInteger(pParse->iSelectId, iRestoreSelectId);
#if SELECTTRACE_ENABLED
SELECTTRACE(1,pParse,p,("end compound-select processing\n"));
pParse->nSelectIndent--;
#endif
return rc; return rc;
} }
#endif #endif
@@ -5383,7 +5410,10 @@ select_end:
sqlite3DbFree(db, sAggInfo.aCol); sqlite3DbFree(db, sAggInfo.aCol);
sqlite3DbFree(db, sAggInfo.aFunc); sqlite3DbFree(db, sAggInfo.aFunc);
SELECTTRACE(1, ("end processing %s\n", p->zSelLabel)); #if SELECTTRACE_ENABLED
SELECTTRACE(1,pParse,p,("end processing\n"));
pParse->nSelectIndent--;
#endif
return rc; return rc;
} }

View File

@@ -2311,7 +2311,7 @@ struct Select {
u16 selFlags; /* Various SF_* values */ u16 selFlags; /* Various SF_* values */
int iLimit, iOffset; /* Memory registers holding LIMIT & OFFSET counters */ int iLimit, iOffset; /* Memory registers holding LIMIT & OFFSET counters */
#if SELECTTRACE_ENABLED #if SELECTTRACE_ENABLED
char zSelLabel[12]; /* Text in comment following SELECT keyword */ char zSelName[12]; /* Symbolic name of this SELECT use for debugging */
#endif #endif
int addrOpenEphm[2]; /* OP_OpenEphem opcodes related to this select */ int addrOpenEphm[2]; /* OP_OpenEphem opcodes related to this select */
u64 nSelectRow; /* Estimated number of result rows */ u64 nSelectRow; /* Estimated number of result rows */
@@ -2573,6 +2573,7 @@ struct Parse {
int nMaxArg; /* Max args passed to user function by sub-program */ int nMaxArg; /* Max args passed to user function by sub-program */
#if SELECTTRACE_ENABLED #if SELECTTRACE_ENABLED
int nSelect; /* Number of SELECT statements seen */ int nSelect; /* Number of SELECT statements seen */
int nSelectIndent; /* How far to indent SELECTTRACE() output */
#endif #endif
#ifndef SQLITE_OMIT_SHARED_CACHE #ifndef SQLITE_OMIT_SHARED_CACHE
int nTableLock; /* Number of locks in aTableLock */ int nTableLock; /* Number of locks in aTableLock */
@@ -3308,6 +3309,11 @@ ExprList *sqlite3ExprListDup(sqlite3*,ExprList*,int);
SrcList *sqlite3SrcListDup(sqlite3*,SrcList*,int); SrcList *sqlite3SrcListDup(sqlite3*,SrcList*,int);
IdList *sqlite3IdListDup(sqlite3*,IdList*); IdList *sqlite3IdListDup(sqlite3*,IdList*);
Select *sqlite3SelectDup(sqlite3*,Select*,int); Select *sqlite3SelectDup(sqlite3*,Select*,int);
#if SELECTTRACE_ENABLED
void sqlite3SelectSetName(Select*,const char*);
#else
# define sqlite3SelectSetName(A,B)
#endif
void sqlite3FuncDefInsert(FuncDefHash*, FuncDef*); void sqlite3FuncDefInsert(FuncDefHash*, FuncDef*);
FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,u8); FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,u8);
void sqlite3RegisterBuiltinFunctions(sqlite3*); void sqlite3RegisterBuiltinFunctions(sqlite3*);