From: drh Date: Sat, 20 Sep 2014 18:18:33 +0000 (+0000) Subject: Enable SELECT query planning tracing when compiled with X-Git-Tag: version-3.8.7~86^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=abd4c72357435db2f4a46d0acf8455ba2ed98fcc;p=thirdparty%2Fsqlite.git Enable SELECT query planning tracing when compiled with SQLITE_ENABLE_SELECTTRACE and either SQLITE_DEBUG or SQLITE_TEST. FossilOrigin-Name: cbe0cf9ddf46f0a678c85d49bfa74e3b7712e1a1 --- diff --git a/manifest b/manifest index 34532191e9..fd7616c7ee 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\susage\sof\sthe\s_GNU_SOURCE\sand\s_BSD_SOURCE\smacros\sin\sthe\smain\ninternal\sheader\sfile,\ssqliteInt.h.\s\sSet\sHAVE_STRCHRNUL\sto\s1\sby\sdefault\son\nLinux\sonly. -D 2014-09-20T00:35:05.099 +C Enable\sSELECT\squery\splanning\stracing\swhen\scompiled\swith\s\nSQLITE_ENABLE_SELECTTRACE\sand\seither\sSQLITE_DEBUG\sor\sSQLITE_TEST. +D 2014-09-20T18:18:33.584 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in cf57f673d77606ab0f2d9627ca52a9ba1464146a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -216,7 +216,7 @@ F src/os_win.c 0a4042ef35f322e86fa01f6c8884c5e645b911e7 F src/os_win.h 09e751b20bbc107ffbd46e13555dc73576d88e21 F src/pager.c caab007743821d96752597c9cfd7351654697b06 F src/pager.h ffd5607f7b3e4590b415b007a4382f693334d428 -F src/parse.y 22d6a074e5f5a7258947a1dc55a9bf946b765dd0 +F src/parse.y 1976d28f168c63c6c14008e9a896620e0c76c25e F src/pcache.c 4121a0571c18581ee9f82f086d5e2030051ebd6a F src/pcache.h 9b559127b83f84ff76d735c8262f04853be0c59a F src/pcache1.c dab8ab930d4a73b99768d881185994f34b80ecaa @@ -226,12 +226,12 @@ F src/printf.c 3a47f526b173813d9a7f4e7044007771ba68cde1 F src/random.c d10c1f85b6709ca97278428fd5db5bbb9c74eece F src/resolve.c a3466128b52a86c466e47ac1a19e2174f7b5cf89 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c 0cd6706fd52ae5db229e9041094db6ec27195335 -F src/shell.c c00220cdd7f2027780bc25b78376c16dc24e4b7d +F src/select.c 4e00e042994ae38e60576921f78e45311eead49e +F src/shell.c dad23987c34faddb061a339da3e92e05ccc6935e F src/sqlite.h.in 8b018219ce988913e5977d5de9ab4beb33be23b6 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d -F src/sqliteInt.h 6fd801cac974d310949ddefd6a6c6982c9778f3f +F src/sqliteInt.h 59b0796cd2fa201510ae9850b3b407fa9f997512 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 2e99ef7ef16187e17033d9398dc962ce22dab5cb @@ -1198,8 +1198,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 544664cadfb4e504bc0b321c865d1ecb8a831e20 0fac2c045f47c7735af4eb68ced81d8b43622a1f -R 8acbfeff4e0806bab5948d89d293bcf4 -T +closed 0fac2c045f47c7735af4eb68ced81d8b43622a1f +P 59e2c9df02d7e988c5ad44c560ead1e5288b12e7 +R e5319fc7a5c9cf5efe2dc73e6ab8c7e0 U drh -Z 03e6ed8cf11426837aa81912fc8917d5 +Z 7cccf9f838c01602cd52161c3ac81285 diff --git a/manifest.uuid b/manifest.uuid index 299d8934f2..d3fdcfe339 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -59e2c9df02d7e988c5ad44c560ead1e5288b12e7 \ No newline at end of file +cbe0cf9ddf46f0a678c85d49bfa74e3b7712e1a1 \ No newline at end of file diff --git a/src/parse.y b/src/parse.y index dbc129ce63..45e6fae6ad 100644 --- a/src/parse.y +++ b/src/parse.y @@ -459,9 +459,33 @@ multiselect_op(A) ::= UNION(OP). {A = @OP;} multiselect_op(A) ::= UNION ALL. {A = TK_ALL;} multiselect_op(A) ::= EXCEPT|INTERSECT(OP). {A = @OP;} %endif SQLITE_OMIT_COMPOUND_SELECT -oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y) +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). { A = sqlite3SelectNew(pParse,W,X,Y,P,Q,Z,D,L.pLimit,L.pOffset); +#if SELECTTRACE_ENABLED + /* Populate the Select.zSelLabel[] string that is used to help with + ** query planner debugging, to differentiate between multiple Select + ** objects in a complex query. + ** + ** If the SELECT keyword is immediately followed by a C-style comment + ** then extract the first few alphanumeric characters from within that + ** comment to be the zSelLabel value. Otherwise, the label is #N where + ** is an integer that is incremented with each SELECT statement seen. + */ + if( A!=0 ){ + const char *z = S.z+6; + int i; + sqlite3_snprintf(sizeof(A->zSelLabel), A->zSelLabel, "#%d", + ++pParse->nSelect); + while( z[0]==' ' ) z++; + if( z[0]=='/' && z[1]=='*' ){ + z += 2; + while( z[0]==' ' ) z++; + for(i=0; sqlite3Isalnum(z[i]); i++){} + sqlite3_snprintf(sizeof(A->zSelLabel), A->zSelLabel, "%.*s", i, z); + } + } +#endif /* SELECTRACE_ENABLED */ } oneselect(A) ::= values(X). {A = X;} diff --git a/src/select.c b/src/select.c index d3ffaf451a..a0f6f35a7f 100644 --- a/src/select.c +++ b/src/select.c @@ -14,6 +14,17 @@ */ #include "sqliteInt.h" +/* +** Trace output macros +*/ +#if SELECTTRACE_ENABLED +/***/ int sqlite3SelectTrace = 0; +# define SELECTTRACE(K,X) if(sqlite3SelectTrace&(K)) sqlite3DebugPrintf X +#else +# define SELECTTRACE(K,X) +#endif + + /* ** An instance of the following object is used to record information about ** how to process the DISTINCT keyword, to simplify passing that information @@ -3355,6 +3366,8 @@ static int flattenSubquery( } /***** If we reach this point, flattening is permitted. *****/ + SELECTTRACE(1, ("flatten %s (term %d) into %s\n", + pSub->zSelLabel, iFrom, p->zSelLabel)); /* Authorize the subquery */ pParse->zAuthContext = pSubitem->zName; diff --git a/src/shell.c b/src/shell.c index ec83b13910..9745e0ff25 100644 --- a/src/shell.c +++ b/src/shell.c @@ -3101,6 +3101,15 @@ static int do_meta_command(char *zLine, ShellState *p){ } }else + +#if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_SELECTTRACE) + if( c=='s' && n==11 && strncmp(azArg[0], "selecttrace", n)==0 ){ + extern int sqlite3SelectTrace; + sqlite3SelectTrace = nArg>=2 ? booleanValue(azArg[1]) : 0xff; + }else +#endif + + #ifdef SQLITE_DEBUG /* Undocumented commands for internal testing. Subject to change ** without notice. */ diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 75cfeefa0d..2d63228edd 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -706,6 +706,17 @@ extern const int sqlite3one; # undef SQLITE_ENABLE_STAT3_OR_STAT4 #endif +/* +** SELECTTRACE_ENABLED will be either 1 or 0 depending on whether or not +** the Select query generator tracing logic is turned on. +*/ +#if defined(SQLITE_DEBUG) \ + && (defined(SQLITE_TEST) || defined(SQLITE_ENABLE_SELECTTRACE)) +# define SELECTTRACE_ENABLED 1 +#else +# define SELECTTRACE_ENABLED 0 +#endif + /* ** An instance of the following structure is used to store the busy-handler ** callback for a given sqlite handle. @@ -2300,6 +2311,9 @@ struct Select { u8 op; /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */ u16 selFlags; /* Various SF_* values */ int iLimit, iOffset; /* Memory registers holding LIMIT & OFFSET counters */ +#if SELECTTRACE_ENABLED + char zSelLabel[12]; /* Text in comment following SELECT keyword */ +#endif int addrOpenEphm[2]; /* OP_OpenEphem opcodes related to this select */ u64 nSelectRow; /* Estimated number of result rows */ SrcList *pSrc; /* The FROM clause */ @@ -2558,6 +2572,9 @@ struct Parse { int regRowid; /* Register holding rowid of CREATE TABLE entry */ int regRoot; /* Register holding root page number for new objects */ int nMaxArg; /* Max args passed to user function by sub-program */ +#if SELECTTRACE_ENABLED + int nSelect; /* Number of SELECT statements seen */ +#endif #ifndef SQLITE_OMIT_SHARED_CACHE int nTableLock; /* Number of locks in aTableLock */ TableLock *aTableLock; /* Required table locks for shared-cache mode */