]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Improved EXPLAIN indentation of a loop in the ANALYZE logic for STAT4.
authordrh <drh@noemail.net>
Thu, 6 Mar 2014 13:38:37 +0000 (13:38 +0000)
committerdrh <drh@noemail.net>
Thu, 6 Mar 2014 13:38:37 +0000 (13:38 +0000)
Mark the not-found jump of a seek operation in that loop as never taken.

FossilOrigin-Name: 0a4200f95cf46ad620b9fd91f4444114a0c74730

manifest
manifest.uuid
src/analyze.c
src/shell.c
src/vdbe.c

index 8bc91eb7e38cdf0fa8cbe9471571a5549f0510de..c1695f1700c162aad274ff65071a9580d7e3dc74 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Remove\sa\sbranch\sthat\sis\snever\staken\sfrom\swhere.c.
-D 2014-03-06T12:36:26.240
+C Improved\sEXPLAIN\sindentation\sof\sa\sloop\sin\sthe\sANALYZE\slogic\sfor\sSTAT4.\nMark\sthe\snot-found\sjump\sof\sa\sseek\soperation\sin\sthat\sloop\sas\snever\staken.
+D 2014-03-06T13:38:37.861
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -157,7 +157,7 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b
 F sqlite3.1 3d8b83c91651f53472ca17599dae3457b8b89494
 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a
 F src/alter.c 5d99edbac5bc416032772b723ee30182ee6e5de0
-F src/analyze.c 69761e1677142d180a9f55250dee2952f45e4793
+F src/analyze.c 663e0b291d27eb03c9fd6b421e2d61ba348a2389
 F src/attach.c 3801129015ef59d76bf23c95ef9b0069d18a0c52
 F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34
 F src/backup.c a729e63cf5cd1829507cb7b8e89f99b95141bb53
@@ -217,7 +217,7 @@ F src/random.c d10c1f85b6709ca97278428fd5db5bbb9c74eece
 F src/resolve.c 273d5f47c4e2c05b2d3d2bffeda939551ab59e66
 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0
 F src/select.c 0adf172d33cc610ff5ffe26edfd2ba67c3551655
-F src/shell.c c0cbbbe5eec0923caafd1b9593925f8b241addb8
+F src/shell.c bab4de12b441369491812ecc93212ff4deda68fa
 F src/sqlite.h.in a2ef671f92747a5a1c8a47bad5c585a8dd9eca80
 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e
 F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc
@@ -277,7 +277,7 @@ F src/update.c 5b3e74a03b3811e586b4f2b4cbd7c49f01c93115
 F src/utf.c 6dc9ec9f1b3db43ae8ba0365377f11df1ee4c01c
 F src/util.c c46c90459ef9bdc0c6c73803cf4c55425b4771cf
 F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179
-F src/vdbe.c b2ca9b8e3a47a3bcecdb2b551279a2ba750a19e5
+F src/vdbe.c 5f0fffa9bf49a90c05dc3d46d8217603fd0ee00e
 F src/vdbe.h d189f92468a17a6f04daeec9df3b767f50557b21
 F src/vdbeInt.h e54fc4f289fce48e81b3371128446033d097733b
 F src/vdbeapi.c 0ed6053f947edd0b30f64ce5aeb811872a3450a4
@@ -1155,7 +1155,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 c87d8e07ec596d5f0ef3003cfeb226d4b7c49549
-R 8a41ab31fe82e4eb8dd3f6f960d87359
-U dan
-Z 9504b4a4d2685ecc17b4e7b160b2fd5f
+P 4a4997221f3d61c1411a993053b40c787beea736
+R 6c77c921c71ee968c47f10dbbbd337e5
+U drh
+Z 43128f0b9615c8a6ed241332450c076a
index 0a317e327080809e3c285607d6dc69db8eb9aaf4..de8a5a7e0271466d3d04fcead0801f49aa20591e 100644 (file)
@@ -1 +1 @@
-4a4997221f3d61c1411a993053b40c787beea736
\ No newline at end of file
+0a4200f95cf46ad620b9fd91f4444114a0c74730
\ No newline at end of file
index 235a2abaf85b507adc83f15bebf1884e4ad45935..2a03e292c886950228cc5117f36a0752f4183ce7 100644 (file)
@@ -1178,7 +1178,10 @@ static void analyzeOneTable(
       callStatGet(v, regStat4, STAT_GET_NLT, regLt);
       callStatGet(v, regStat4, STAT_GET_NDLT, regDLt);
       sqlite3VdbeAddOp4Int(v, seekOp, iTabCur, addrNext, regSampleRowid, 0);
-      VdbeCoverage(v);
+      /* We know that the regSampleRowid row exists because it was read by
+      ** the previous loop.  Thus the not-found jump of seekOp will never
+      ** be taken */
+      VdbeCoverageNeverTaken(v);
 #ifdef SQLITE_ENABLE_STAT3
       sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, 
                                       pIdx->aiColumn[0], regSample);
@@ -1192,7 +1195,7 @@ static void analyzeOneTable(
       sqlite3VdbeAddOp3(v, OP_MakeRecord, regTabname, 6, regTemp);
       sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur+1, regNewRowid);
       sqlite3VdbeAddOp3(v, OP_Insert, iStatCur+1, regTemp, regNewRowid);
-      sqlite3VdbeAddOp2(v, OP_Goto, 0, addrNext);
+      sqlite3VdbeAddOp2(v, OP_Goto, 1, addrNext); /* P1==1 for end-of-loop */
       sqlite3VdbeJumpHere(v, addrIsNull);
     }
 #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
index f3f80bfd717c882c3fb6c469ddb2bbf377d23345..2cff102e91c506a03599256e4430f444484ddbf0 100644 (file)
@@ -1184,6 +1184,7 @@ static int str_in_array(const char *zStr, const char **azArray){
 **     * For each "Goto", if the jump destination is earlier in the program
 **       and ends on one of:
 **          Yield  SeekGt  SeekLt  RowSetRead  Rewind
+**       or if the P1 parameter is one instead of zero,
 **       then indent all opcodes between the earlier instruction
 **       and "Goto" by 2 spaces.
 */
@@ -1231,7 +1232,9 @@ static void explain_data_prepare(struct callback_data *p, sqlite3_stmt *pSql){
     if( str_in_array(zOp, azNext) ){
       for(i=p2op; i<iOp; i++) p->aiIndent[i] += 2;
     }
-    if( str_in_array(zOp, azGoto) && p2op<p->nIndent && abYield[p2op] ){
+    if( str_in_array(zOp, azGoto) && p2op<p->nIndent
+     && (abYield[p2op] || sqlite3_column_int(pSql, 2))
+    ){
       for(i=p2op+1; i<iOp; i++) p->aiIndent[i] += 2;
     }
   }
index 4c36e12090e55fd9ecf10441192251afd4835fd4..c58b5d9fdabcec9a745144b5ad3c708efdb77bea 100644 (file)
@@ -671,6 +671,11 @@ int sqlite3VdbeExec(
 ** The next instruction executed will be 
 ** the one at index P2 from the beginning of
 ** the program.
+**
+** The P1 parameter is not actually used by this opcode.  However, it
+** is sometimes set to 1 instead of 0 as a hint to the command-line shell
+** that this Goto is the bottom of a loop and that the lines from P2 down
+** to the current line should be indented for EXPLAIN output.
 */
 case OP_Goto: {             /* jump */
   pc = pOp->p2 - 1;