From ada7045eabf23116f9c6b422fff7ca604198ce58 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 21 Dec 2017 21:02:27 +0000 Subject: [PATCH] Add the ".eqp trigger" option to the ".eqp" command in the command-line shell. Implemented using the new SQLITE_DBCONFIG_TRIGGER_EQP control. FossilOrigin-Name: 2c51644a12a638d89e4f7cc3fd561236ce424f2d4e1db31f1e8388f77add02b8 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/shell.c.in | 27 +++++++++++++++++++++------ 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index b9641d26a6..62b8ff3da8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s".expert"\scommand\sto\sthe\sshell\stool's\s".help"\soutput. -D 2017-12-21T18:55:24.380 +C Add\sthe\s".eqp\strigger"\soption\sto\sthe\s".eqp"\scommand\sin\sthe\scommand-line\nshell.\s\sImplemented\susing\sthe\snew\sSQLITE_DBCONFIG_TRIGGER_EQP\scontrol. +D 2017-12-21T21:02:27.410 F Makefile.in ceb40bfcb30ebba8e1202b34c56ff7e13e112f9809e2381d99be32c2726058f5 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 6480671f7c129e61208d69492b3c71ce4310d49fceac83cfb17f1c081e242b69 @@ -479,7 +479,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c bbee7e31d369a18a2f4836644769882e9c5d40ef4a3af911db06410b65cb3730 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c 17e220191860a64a18c084141e1a8b7309e166a6f2d42c02021af27ea080d157 -F src/shell.c.in ef343d708f32e43bc5abff8a4a769e026252b77ff37583cbd7ad30a9cc169f26 +F src/shell.c.in 339169a3d1307b5566ebe9ce15832d03439206106724c78cc3d9125a7b851795 F src/sqlite.h.in 53611410ade98671c0a95b209273e52dfd0ec1268ebc9213622d221d83b50bfe F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h c02d628cca67f3889c689d82d25c3eb45e2c155db08e4c6089b5840d64687d34 @@ -1687,7 +1687,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P fffc7685d19f78ec322a4e834ad727af20a17e2e1c35680e4b1c4162c4786f60 -R d5bcde1015d19d1cdfe7f85d9291f783 -U dan -Z f2c8e8756f16d691313b2a4f36b60cc0 +P fc6193af5d216b4066fbc47e75a7d0538fd5fda40b94ee15e2ff4037ea89221b +R 9e177759a0c3bcdc85d791f3df26085a +U drh +Z 1ea40405a7cdaae369b8eb1d1f8aee13 diff --git a/manifest.uuid b/manifest.uuid index 247556897e..48249eb7dd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fc6193af5d216b4066fbc47e75a7d0538fd5fda40b94ee15e2ff4037ea89221b \ No newline at end of file +2c51644a12a638d89e4f7cc3fd561236ce424f2d4e1db31f1e8388f77add02b8 \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 261a1971e7..13b1fcde39 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -877,6 +877,13 @@ struct ShellState { ExpertInfo expert; /* Valid if previous command was ".expert OPT..." */ }; +/* Allowed values for ShellState.autoEQP +*/ +#define AUTOEQP_off 0 +#define AUTOEQP_on 1 +#define AUTOEQP_trigger 2 +#define AUTOEQP_full 3 + /* ** These are the allowed shellFlgs values */ @@ -2395,7 +2402,12 @@ static int shell_exec( if( pArg && pArg->autoEQP && sqlite3_strlike("EXPLAIN%",zStmtSql,0)!=0 ){ sqlite3_stmt *pExplain; char *zEQP; + int triggerEQP = 0; disable_debug_trace_modes(); + sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, -1, &triggerEQP); + if( pArg->autoEQP>=AUTOEQP_trigger ){ + sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, 1, 0); + } zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s", zStmtSql); rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0); if( rc==SQLITE_OK ){ @@ -2408,7 +2420,7 @@ static int shell_exec( } sqlite3_finalize(pExplain); sqlite3_free(zEQP); - if( pArg->autoEQP>=2 ){ + if( pArg->autoEQP>=AUTOEQP_full ){ /* Also do an EXPLAIN for ".eqp full" mode */ zEQP = sqlite3_mprintf("EXPLAIN %s", zStmtSql); rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0); @@ -2421,6 +2433,7 @@ static int shell_exec( sqlite3_finalize(pExplain); sqlite3_free(zEQP); } + sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, triggerEQP, 0); restore_debug_trace_modes(); } @@ -4547,12 +4560,14 @@ static int do_meta_command(char *zLine, ShellState *p){ if( c=='e' && strncmp(azArg[0], "eqp", n)==0 ){ if( nArg==2 ){ if( strcmp(azArg[1],"full")==0 ){ - p->autoEQP = 2; + p->autoEQP = AUTOEQP_full; + }else if( strcmp(azArg[1],"trigger")==0 ){ + p->autoEQP = AUTOEQP_trigger; }else{ p->autoEQP = booleanValue(azArg[1]); } }else{ - raw_printf(stderr, "Usage: .eqp on|off|full\n"); + raw_printf(stderr, "Usage: .eqp off|on|trigger|full\n"); rc = 1; } }else @@ -5905,7 +5920,7 @@ static int do_meta_command(char *zLine, ShellState *p){ }else if( c=='s' && strncmp(azArg[0], "show", n)==0 ){ - static const char *azBool[] = { "off", "on", "full", "unk" }; + static const char *azBool[] = { "off", "on", "trigger", "full"}; int i; if( nArg!=1 ){ raw_printf(stderr, "Usage: .show\n"); @@ -7057,9 +7072,9 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ }else if( strcmp(z,"-echo")==0 ){ ShellSetFlag(&data, SHFLG_Echo); }else if( strcmp(z,"-eqp")==0 ){ - data.autoEQP = 1; + data.autoEQP = AUTOEQP_on; }else if( strcmp(z,"-eqpfull")==0 ){ - data.autoEQP = 2; + data.autoEQP = AUTOEQP_full; }else if( strcmp(z,"-stats")==0 ){ data.statsOn = 1; }else if( strcmp(z,"-scanstats")==0 ){ -- 2.47.2