diff --git a/manifest b/manifest index a17919ee09..1ea2e4a1dc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Import\sthe\sautomatic\scomment\sgenerating\schanges\sfrom\strunk. -D 2013-10-29T20:47:26.079 +C Merge\sEXPLAIN\senhancements\sfrom\strunk. +D 2013-10-30T02:37:50.150 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 0522b53cdc1fcfc18f3a98e0246add129136c654 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -145,7 +145,7 @@ F main.mk c6a433cb334bbb019625c137ab5d5e7568b47cff F mkdll.sh 7d09b23c05d56532e9d44a50868eb4b12ff4f74a F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f F mkextw.sh d2a981497b404d6498f5ff3e3b1f3816bdfcb338 -F mkopcodec.awk 393b20a2a99557ca695f7e1261c32d087ff7c0b4 +F mkopcodec.awk c2ff431854d702cdd2d779c9c0d1f58fa16fa4ea F mkopcodeh.awk 987ee588ff3bb4043bed2185c1ee2bdc39b1e526 F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83 F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271 @@ -223,7 +223,7 @@ F src/shell.c d5eebdc6034014103de2b9d58e1d3f6f7de0fb50 F src/sqlite.h.in 547a44dd4ff4d975e92a645ea2d609e543a83d0f F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc -F src/sqliteInt.h 2653257af49bf87af81d7c35899297043f10879a +F src/sqliteInt.h 03e6459326d16123441ada0a053163fd1e2e341d F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -274,16 +274,16 @@ F src/test_vfs.c e72f555ef7a59080f898fcf1a233deb9eb704ea9 F src/test_vfstrace.c 34b544e80ba7fb77be15395a609c669df2e660a2 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/tokenize.c 70061085a51f2f4fc15ece94f32c03bcb78e63b2 -F src/trigger.c ba0a883cd536b7dfdd4df3733001f5372a4299da +F src/trigger.c 53d6b5d50b3b23d4fcd0a36504feb5cff9aed716 F src/update.c e39378bc5ed0c42e80624229703e59b5c7a4d50a F src/utf.c 6fc6c88d50448c469c5c196acf21617a24f90269 F src/util.c 2fa6c821d28bbdbeec1b2a7b091a281c9ef8f918 F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179 -F src/vdbe.c cb3df2d7b2ebadf22a39efcfb12a1277e273616e -F src/vdbe.h 4f554b5627f26710c4c36d919110a3fc611ca5c4 +F src/vdbe.c 3c98b77343f8a1f4624b86795bf29cfd008b0e4a +F src/vdbe.h 6bdee35c54d57fd52733d4c542781820009311dc F src/vdbeInt.h 42dcff74dbeb2b071e569b53f885fc9c2e4b4cb0 F src/vdbeapi.c 93a22a9ba2abe292d5c2cf304d7eb2e894dde0ed -F src/vdbeaux.c 3c36d92d3ad7225e0436474f4256243e5ceaeabb +F src/vdbeaux.c 4b01ac1c84534cd5a240dffba6e8173aeff628c5 F src/vdbeblob.c ef973d8d9f8170015343dd8824f795da675caa87 F src/vdbemem.c 6087553f2c61c06c8e1ab3959a60e174d6240c98 F src/vdbesort.c 3937e06b2a0e354500e17dc206ef4c35770a5017 @@ -1127,7 +1127,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P 141a38a7a636e3e4255b59c27df4a1b3d6f26e97 5f310c6a22b8bb5f860296074aee130c14101681 -R 092c8ad63995bcb3387c2f88e6abbbb4 +P 8bb51da1305d5e35c7b75bbb176c21e04ea2a48a e1a89b56f7173166bb9224e2e360fd67ad3399c3 +R 880887149918aa46e6b88c9f75c81815 U drh -Z 2daff0292132d8122decef0d377e8179 +Z 77a0862498d22b2e5464d4447bba8799 diff --git a/manifest.uuid b/manifest.uuid index bc00d07846..5eb709e725 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8bb51da1305d5e35c7b75bbb176c21e04ea2a48a \ No newline at end of file +2fcac056074f0a23884ab5425003a7ca1d35c2a8 \ No newline at end of file diff --git a/mkopcodec.awk b/mkopcodec.awk index f4a09bf3e5..de19068c20 100644 --- a/mkopcodec.awk +++ b/mkopcodec.awk @@ -14,7 +14,7 @@ BEGIN { printf "#if !defined(SQLITE_OMIT_EXPLAIN)" printf " || defined(VDBE_PROFILE)" print " || defined(SQLITE_DEBUG)" - print "#if defined(SQLITE_DEBUG)" + print "#if defined(SQLITE_ENABLE_EXPLAIN_COMMENTS) || defined(SQLITE_DEBUG)" print "# define OpHelp(X) \"\\0\" X" print "#else" print "# define OpHelp(X)" diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 0d5a68d504..ec4aaa14db 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -217,6 +217,13 @@ # undef NDEBUG #endif +/* +** Enable SQLITE_ENABLE_EXPLAIN_COMMENTS if SQLITE_DEBUG is turned on. +*/ +#if !defined(SQLITE_ENABLE_EXPLAIN_COMMENTS) && defined(SQLITE_DEBUG) +# define SQLITE_ENABLE_EXPLAIN_COMMENTS 1 +#endif + /* ** The testcase() macro is used to aid in coverage testing. When ** doing coverage testing, the condition inside the argument to diff --git a/src/trigger.c b/src/trigger.c index 774711f0f5..607b831243 100644 --- a/src/trigger.c +++ b/src/trigger.c @@ -784,7 +784,7 @@ static int codeTriggerProgram( return 0; } -#ifdef SQLITE_DEBUG +#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS /* ** This function is used to add VdbeComment() annotations to a VDBE ** program. It is not used in production code, only for debugging. diff --git a/src/vdbe.c b/src/vdbe.c index f0400a64dc..1dd8757f4b 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -1035,7 +1035,7 @@ case OP_Variable: { /* out2-prerelease */ } /* Opcode: Move P1 P2 P3 * * -** Synopsis: r[P2]=r[P1] N=P3 +** Synopsis: r[P2@P3]=r[P1@P3] ** ** Move the values in register P1..P1+P3 over into ** registers P2..P2+P3. Registers P1..P1+P3 are @@ -1078,7 +1078,7 @@ case OP_Move: { } /* Opcode: Copy P1 P2 P3 * * -** Synopsis: r[P2]=r[P1] N=P3 +** Synopsis: r[P2@P3]=r[P1@P3] ** ** Make a copy of registers P1..P1+P3 into registers P2..P2+P3. ** @@ -1132,7 +1132,7 @@ case OP_SCopy: { /* in1, out2 */ } /* Opcode: ResultRow P1 P2 * * * -** Synopsis: output=r[P1].. columns=P1 +** Synopsis: output=r[P1@P2] ** ** The registers P1 through P1+P2-1 contain a single row of ** results. This opcode causes the sqlite3_step() call to terminate @@ -1400,7 +1400,7 @@ case OP_CollSeq: { } /* Opcode: Function P1 P2 P3 P4 P5 -** Synopsis: r[P3]=func(r[P2]..) N=P5 +** Synopsis: r[P3]=func(r[P2@P5]) ** ** Invoke a user function (P4 is a pointer to a Function structure that ** defines the function) with P5 arguments taken from register P2 and @@ -2513,7 +2513,7 @@ op_column_out: } /* Opcode: Affinity P1 P2 * P4 * -** Synopsis: affinity(r[P1]) N=P2 +** Synopsis: affinity(r[P1@P2]) ** ** Apply affinities to a range of P2 registers starting with P1. ** @@ -2540,7 +2540,7 @@ case OP_Affinity: { } /* Opcode: MakeRecord P1 P2 P3 P4 * -** Synopsis: r[P3]=rec(r[P1]..) N=P2 +** Synopsis: r[P3]=mkrec(r[P1@P2]) ** ** Convert P2 registers beginning with P1 into the [record format] ** use as a data record in a database table or as a key @@ -3379,7 +3379,7 @@ case OP_SorterOpen: { } /* Opcode: OpenPseudo P1 P2 P3 * P5 -** Synopsis: content in r[P2].. N=P3 +** Synopsis: content in r[P2@P3] ** ** Open a new cursor that points to a fake table that contains a single ** row of data. The content of that one row in the content of memory @@ -3422,7 +3422,7 @@ case OP_Close: { } /* Opcode: SeekGe P1 P2 P3 P4 * -** Synopsis: key=r[P3].. N=P4 +** Synopsis: key=r[P3@P4] ** ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys), ** use the value in register P3 as the key. If cursor P1 refers @@ -3436,7 +3436,7 @@ case OP_Close: { ** See also: Found, NotFound, Distinct, SeekLt, SeekGt, SeekLe */ /* Opcode: SeekGt P1 P2 P3 P4 * -** Synopsis: key=r[P3].. N=P4 +** Synopsis: key=r[P3@P4] ** ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys), ** use the value in register P3 as a key. If cursor P1 refers @@ -3450,7 +3450,7 @@ case OP_Close: { ** See also: Found, NotFound, Distinct, SeekLt, SeekGe, SeekLe */ /* Opcode: SeekLt P1 P2 P3 P4 * -** Synopsis: key=r[P3].. N=P4 +** Synopsis: key=r[P3@P4] ** ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys), ** use the value in register P3 as a key. If cursor P1 refers @@ -3464,7 +3464,7 @@ case OP_Close: { ** See also: Found, NotFound, Distinct, SeekGt, SeekGe, SeekLe */ /* Opcode: SeekLe P1 P2 P3 P4 * -** Synopsis: key=r[P3].. N=P4 +** Synopsis: key=r[P3@P4] ** ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys), ** use the value in register P3 as a key. If cursor P1 refers @@ -3658,7 +3658,7 @@ case OP_Seek: { /* in2 */ /* Opcode: Found P1 P2 P3 P4 * -** Synopsis: key=r[P3].. N=P4 +** Synopsis: key=r[P3@P4] ** ** If P4==0 then register P3 holds a blob constructed by MakeRecord. If ** P4>0 then register P3 is the first of P4 registers that form an unpacked @@ -3671,7 +3671,7 @@ case OP_Seek: { /* in2 */ ** See also: NotFound, NoConflict, NotExists. SeekGe */ /* Opcode: NotFound P1 P2 P3 P4 * -** Synopsis: key=r[P3] N=P4 +** Synopsis: key=r[P3@P4] ** ** If P4==0 then register P3 holds a blob constructed by MakeRecord. If ** P4>0 then register P3 is the first of P4 registers that form an unpacked @@ -3686,6 +3686,7 @@ case OP_Seek: { /* in2 */ ** See also: Found, NotExists, NoConflict */ /* Opcode: NoConflict P1 P2 P3 P4 * +** Synopsis: key=r[P3@P4] ** ** If P4==0 then register P3 holds a blob constructed by MakeRecord. If ** P4>0 then register P3 is the first of P4 registers that form an unpacked @@ -4585,7 +4586,7 @@ case OP_IdxInsert: { /* in2 */ } /* Opcode: IdxDelete P1 P2 P3 * * -** Synopsis: key=r[P2].. +** Synopsis: key=r[P2@P3] ** ** The content of P3 registers starting at register P2 form ** an unpacked index key. This opcode removes that entry from the @@ -4658,7 +4659,7 @@ case OP_IdxRowid: { /* out2-prerelease */ } /* Opcode: IdxGE P1 P2 P3 P4 P5 -** Synopsis: key=r[P3] N=P4 +** Synopsis: key=r[P3@P4] ** ** The P4 register values beginning with P3 form an unpacked index ** key that omits the ROWID. Compare this key value against the index @@ -4673,7 +4674,7 @@ case OP_IdxRowid: { /* out2-prerelease */ ** the result is false whereas it would be true with IdxGT. */ /* Opcode: IdxLT P1 P2 P3 P4 P5 -** Synopsis: key=r[P3] N=P4 +** Synopsis: key=r[P3@P4] ** ** The P4 register values beginning with P3 form an unpacked index ** key that omits the ROWID. Compare this key value against the index @@ -5416,7 +5417,7 @@ case OP_IfZero: { /* jump, in1 */ } /* Opcode: AggStep * P2 P3 P4 P5 -** Synopsis: accum=r[P3] step(r[P2]..) N=P5 +** Synopsis: accum=r[P3] step(r[P2@P5]) ** ** Execute the step function for an aggregate. The ** function has P5 arguments. P4 is a pointer to the FuncDef @@ -6034,7 +6035,7 @@ case OP_VRename: { #ifndef SQLITE_OMIT_VIRTUALTABLE /* Opcode: VUpdate P1 P2 P3 P4 * -** Synopsis: data=r[P3] N=P2 +** Synopsis: data=r[P3@P2] ** ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure. ** This opcode invokes the corresponding xUpdate method. P2 values diff --git a/src/vdbe.h b/src/vdbe.h index a6cc915444..966ea75264 100644 --- a/src/vdbe.h +++ b/src/vdbe.h @@ -61,7 +61,7 @@ struct VdbeOp { SubProgram *pProgram; /* Used when p4type is P4_SUBPROGRAM */ int (*xAdvance)(BtCursor *, int *); } p4; -#ifdef SQLITE_DEBUG +#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS char *zComment; /* Comment to improve readability */ #endif #ifdef VDBE_PROFILE @@ -219,7 +219,7 @@ void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *); #endif -#ifndef NDEBUG +#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS void sqlite3VdbeComment(Vdbe*, const char*, ...); # define VdbeComment(X) sqlite3VdbeComment X void sqlite3VdbeNoopComment(Vdbe*, const char*, ...); diff --git a/src/vdbeaux.c b/src/vdbeaux.c index c71b29caff..97c1c8cfc7 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -144,8 +144,10 @@ int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){ pOp->p3 = p3; pOp->p4.p = 0; pOp->p4type = P4_NOTUSED; -#ifdef SQLITE_DEBUG +#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS pOp->zComment = 0; +#endif +#ifdef SQLITE_DEBUG if( p->db->flags & SQLITE_VdbeAddopTrace ){ sqlite3VdbePrintOp(0, i, &p->aOp[i]); } @@ -532,8 +534,10 @@ int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){ pOut->p4type = P4_NOTUSED; pOut->p4.p = 0; pOut->p5 = 0; -#ifdef SQLITE_DEBUG +#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS pOut->zComment = 0; +#endif +#ifdef SQLITE_DEBUG if( p->db->flags & SQLITE_VdbeAddopTrace ){ sqlite3VdbePrintOp(0, i+addr, &p->aOp[i+addr]); } @@ -663,7 +667,7 @@ static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){ Op *pOp; for(pOp=aOp; pOp<&aOp[nOp]; pOp++){ freeP4(db, pOp->p4type, pOp->p4.p); -#ifdef SQLITE_DEBUG +#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS sqlite3DbFree(db, pOp->zComment); #endif } @@ -781,7 +785,7 @@ void sqlite3VdbeChangeP4(Vdbe *p, int addr, const char *zP4, int n){ } } -#ifndef NDEBUG +#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS /* ** Change the comment on the most recently coded instruction. Or ** insert a No-op and add the comment to that new instruction. This @@ -856,11 +860,28 @@ VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){ } } -#if defined(SQLITE_DEBUG) +#if defined(SQLITE_ENABLE_EXPLAIN_COMMENTS) +/* +** Return an integer value for one of the parameters to the opcode pOp +** determined by character c. +*/ +static int translateP(char c, const Op *pOp){ + if( c=='1' ) return pOp->p1; + if( c=='2' ) return pOp->p2; + if( c=='3' ) return pOp->p3; + if( c=='4' ) return pOp->p4.i; + return pOp->p5; +} + /* ** Compute a string for the "comment" field of a VDBE opcode listing */ -static int displayComment(Op *pOp, const char *zP4, char *zTemp, int nTemp){ +static int displayComment( + const Op *pOp, /* The opcode to be commented */ + const char *zP4, /* Previously obtained value for P4 */ + char *zTemp, /* Write result here */ + int nTemp /* Space available in zTemp[] */ +){ const char *zOpName; const char *zSynopsis; int nOpName; @@ -869,28 +890,32 @@ static int displayComment(Op *pOp, const char *zP4, char *zTemp, int nTemp){ nOpName = sqlite3Strlen30(zOpName); if( zOpName[nOpName+1] ){ int seenCom = 0; + char c; zSynopsis = zOpName += nOpName + 1; - for(ii=jj=0; jjp1; break; - case '2': v = pOp->p2; break; - case '3': v = pOp->p3; break; - case '5': v = pOp->p5; break; - case '4': zShow = zP4; break; - case 'X': zShow = pOp->zComment; seenCom = 1; break; - } - if( zShow ){ - sqlite3_snprintf(nTemp-jj, zTemp+jj, "%s", zShow); + for(ii=jj=0; jjzComment); + seenCom = 1; }else{ - sqlite3_snprintf(nTemp-jj, zTemp+jj, "%d", v); + int v1 = translateP(c, pOp); + int v2; + sqlite3_snprintf(nTemp-jj, zTemp+jj, "%d", v1); + if( strncmp(zSynopsis+ii+1, "@P", 2)==0 ){ + ii += 3; + jj += sqlite3Strlen30(zTemp+jj); + v2 = translateP(zSynopsis[ii], pOp); + if( v2>1 ) sqlite3_snprintf(nTemp-jj, zTemp+jj, "..%d", v1+v2-1); + }else if( strncmp(zSynopsis+ii+1, "..P3", 4)==0 && pOp->p3==0 ){ + ii += 4; + } } jj += sqlite3Strlen30(zTemp+jj); }else{ - zTemp[jj++] = zSynopsis[ii]; + zTemp[jj++] = c; } } if( !seenCom && jjzComment ){ @@ -1107,7 +1132,7 @@ void sqlite3VdbePrintOp(FILE *pOut, int pc, Op *pOp){ static const char *zFormat1 = "%4d %-13s %4d %4d %4d %-4s %.2X %s\n"; if( pOut==0 ) pOut = stdout; zP4 = displayP4(pOp, zPtr, sizeof(zPtr)); -#ifdef SQLITE_DEBUG +#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS displayComment(pOp, zP4, zCom, sizeof(zCom)); #else zCom[0] = 0 @@ -1353,7 +1378,7 @@ int sqlite3VdbeList( pMem->enc = SQLITE_UTF8; pMem++; -#ifdef SQLITE_DEBUG +#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS if( sqlite3VdbeMemGrow(pMem, 500, 0) ){ assert( p->db->mallocFailed ); return SQLITE_ERROR;