From: drh Date: Fri, 28 Feb 2014 20:47:24 +0000 (+0000) Subject: In the command-line shell add the (undocumented and unsupported) ".eqp" X-Git-Tag: version-3.8.4~39 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=efbf3b1a1066b541123e065c9a1469462b1bec27;p=thirdparty%2Fsqlite.git In the command-line shell add the (undocumented and unsupported) ".eqp" command and -eqp command-line option, to cause EXPLAIN QUERY PLAN to be run on each SQL statement as it is evaluated. Intended use is for analysis of the query planner. FossilOrigin-Name: e6ecf7337658624d664e1e71ba3fc527fd6578c1 --- diff --git a/manifest b/manifest index e1c9e01261..3686379a18 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Provide\san\s#ifdef\sin\sshell.c\sto\swork\saround\sissues\swhen\scross-compiling\nfrom\sUbuntu\sto\swindows. -D 2014-02-28T19:37:45.291 +C In\sthe\scommand-line\sshell\sadd\sthe\s(undocumented\sand\sunsupported)\s".eqp"\ncommand\sand\s-eqp\scommand-line\soption,\sto\scause\sEXPLAIN\sQUERY\sPLAN\sto\sbe\nrun\son\seach\sSQL\sstatement\sas\sit\sis\sevaluated.\s\sIntended\suse\sis\sfor\sanalysis\nof\sthe\squery\splanner. +D 2014-02-28T20:47:24.221 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -217,7 +217,7 @@ F src/random.c d10c1f85b6709ca97278428fd5db5bbb9c74eece F src/resolve.c ca8b99d894164435f5c55cb304c1b8121705c51e F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 F src/select.c 35b07a47fdee9a98e03c4ffb3801026c72114cb7 -F src/shell.c e6d573326f12901df3801777831b48bd80c11dab +F src/shell.c 7bf07bcacb181ecc3fc3ccacfdfeb4084aee67ed F src/sqlite.h.in a2ef671f92747a5a1c8a47bad5c585a8dd9eca80 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc @@ -1152,7 +1152,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P 51ce713c6ee91bdf0126155334dcc800b3daa509 -R f77dc22964f582c1f952cbee70cf06fb +P 0a3579d9b9d2a60bb85a9811bc7936edb88debae +R 195e6e751f71ffa9e9cfd28d6f8e532d U drh -Z 5ee6ba31533a91dba4172ad5a5e2ece1 +Z d48791979092ee78fb00c8a21c663b3b diff --git a/manifest.uuid b/manifest.uuid index 297558a6f1..6108cf5bed 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0a3579d9b9d2a60bb85a9811bc7936edb88debae \ No newline at end of file +e6ecf7337658624d664e1e71ba3fc527fd6578c1 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 0709f6c41e..7ecedfd3c1 100644 --- a/src/shell.c +++ b/src/shell.c @@ -446,6 +446,7 @@ struct previous_mode_data { struct callback_data { sqlite3 *db; /* The database */ int echoOn; /* True to echo input commands */ + int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL statement */ int statsOn; /* True to display memory stats before each finalize */ int cnt; /* Number of records displayed so far */ FILE *out; /* Write results here */ @@ -1302,6 +1303,23 @@ static int shell_exec( fprintf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql); } + /* Show the EXPLAIN QUERY PLAN if .eqp is on */ + if( pArg && pArg->autoEQP ){ + sqlite3_stmt *pExplain; + char *zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s", sqlite3_sql(pStmt)); + rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0); + if( rc==SQLITE_OK ){ + while( sqlite3_step(pExplain)==SQLITE_ROW ){ + fprintf(pArg->out,"--EQP-- %d,", sqlite3_column_int(pExplain, 0)); + fprintf(pArg->out,"%d,", sqlite3_column_int(pExplain, 1)); + fprintf(pArg->out,"%d,", sqlite3_column_int(pExplain, 2)); + fprintf(pArg->out,"%s\n", sqlite3_column_text(pExplain, 3)); + } + } + sqlite3_finalize(pExplain); + sqlite3_free(zEQP); + } + /* Output TESTCTRL_EXPLAIN text of requested */ if( pArg && pArg->mode==MODE_Explain ){ const char *zExplain = 0; @@ -2301,6 +2319,10 @@ static int do_meta_command(char *zLine, struct callback_data *p){ p->echoOn = booleanValue(azArg[1]); }else + if( c=='e' && strncmp(azArg[0], "eqp", n)==0 && nArg>1 && nArg<3 ){ + p->autoEQP = booleanValue(azArg[1]); + }else + if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){ if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc); rc = 2; @@ -2873,6 +2895,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){ if( c=='s' && strncmp(azArg[0], "show", n)==0 && nArg==1 ){ int i; fprintf(p->out,"%9.9s: %s\n","echo", p->echoOn ? "on" : "off"); + fprintf(p->out,"%9.9s: %s\n","eqp", p->autoEQP ? "on" : "off"); fprintf(p->out,"%9.9s: %s\n","explain", p->explainPrev.valid ? "on" :"off"); fprintf(p->out,"%9.9s: %s\n","headers", p->showHeader ? "on" : "off"); fprintf(p->out,"%9.9s: %s\n","mode", modeDescr[p->mode]); @@ -3710,6 +3733,8 @@ int main(int argc, char **argv){ data.showHeader = 0; }else if( strcmp(z,"-echo")==0 ){ data.echoOn = 1; + }else if( strcmp(z,"-eqp")==0 ){ + data.autoEQP = 1; }else if( strcmp(z,"-stats")==0 ){ data.statsOn = 1; }else if( strcmp(z,"-bail")==0 ){