1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Change the OP_Trace opcode to OP_Init and give it the ability to jump to the

initialization code at the bottom of the program, thus avoiding the need for
an extra OP_Goto.

FossilOrigin-Name: 192dea97316144f15f6dd0eabff08a0bf9ef203e
This commit is contained in:
drh
2014-02-08 01:40:27 +00:00
parent 642364a48b
commit aceb31b120
10 changed files with 61 additions and 117 deletions

View File

@@ -1,5 +1,5 @@
C Add\sopcodes\sOP_InitCoroutine\sand\sOP_EndCoroutine.\s\sUse\sthese\sto\sremove\sthe\nneed\sfor\sseparate\sboolean\sregisters\sto\srecord\swhen\sa\sco-routine\shas\sfinished. C Change\sthe\sOP_Trace\sopcode\sto\sOP_Init\sand\sgive\sit\sthe\sability\sto\sjump\sto\sthe\ninitialization\scode\sat\sthe\sbottom\sof\sthe\sprogram,\sthus\savoiding\sthe\sneed\sfor\nan\sextra\sOP_Goto.
D 2014-02-07T22:21:07.782 D 2014-02-08T01:40:27.230
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81 F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -169,7 +169,7 @@ F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7
F src/btree.c 7b2c3cd16deedff7f4904f2e871e7b77328b9872 F src/btree.c 7b2c3cd16deedff7f4904f2e871e7b77328b9872
F src/btree.h a61ddebc78c66795a2b93181321a116746302cc9 F src/btree.h a61ddebc78c66795a2b93181321a116746302cc9
F src/btreeInt.h f038e818bfadf75afbd09819ed93c26a333d39e0 F src/btreeInt.h f038e818bfadf75afbd09819ed93c26a333d39e0
F src/build.c 40c38ec8f10835cf68879cb12e7c00e32b8edf78 F src/build.c 1bc258476158bfe7707d21daa5221dd95c03d37c
F src/callback.c 174e3c8656bc29f91d710ab61550d16eea34be98 F src/callback.c 174e3c8656bc29f91d710ab61550d16eea34be98
F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
F src/ctime.c 77779efbe78dd678d84bfb4fc2e87b6b6ad8dccd F src/ctime.c 77779efbe78dd678d84bfb4fc2e87b6b6ad8dccd
@@ -183,7 +183,7 @@ F src/global.c 1d7bb7ea8254ae6a68ed9bfaf65fcb3d1690b486
F src/hash.c d139319967164f139c8d1bb8a11b14db9c4ba3cd F src/hash.c d139319967164f139c8d1bb8a11b14db9c4ba3cd
F src/hash.h 8890a25af81fb85a9ad7790d32eedab4b994da22 F src/hash.h 8890a25af81fb85a9ad7790d32eedab4b994da22
F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08
F src/insert.c b50cb5a51edb0d6e1a99e04b232b8632a54e522a F src/insert.c 89526b031cf8f0e2306f02099a73cee56110c580
F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d
F src/legacy.c 0df0b1550b9cc1f58229644735e317ac89131f12 F src/legacy.c 0df0b1550b9cc1f58229644735e317ac89131f12
F src/lempar.c cdf0a000315332fc9b50b62f3b5e22e080a0952b F src/lempar.c cdf0a000315332fc9b50b62f3b5e22e080a0952b
@@ -219,12 +219,12 @@ F src/printf.c 85d07756e45d7496d19439dcae3e6e9e0090f269
F src/random.c d10c1f85b6709ca97278428fd5db5bbb9c74eece F src/random.c d10c1f85b6709ca97278428fd5db5bbb9c74eece
F src/resolve.c 7eda9097b29fcf3d2b42fdc17d1de672134e09b6 F src/resolve.c 7eda9097b29fcf3d2b42fdc17d1de672134e09b6
F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0
F src/select.c 47d93e6f0b58000e2093e7b489bdca778884f82a F src/select.c 0b6011a51496c916914f6fba11c3a6a0042a0439
F src/shell.c 7dedf7367ee49050b0366bf8dbc8ec2bd15b42c7 F src/shell.c 7dedf7367ee49050b0366bf8dbc8ec2bd15b42c7
F src/sqlite.h.in eed7f7d66a60daaa7b4a597dcd9bad87aad9611b F src/sqlite.h.in eed7f7d66a60daaa7b4a597dcd9bad87aad9611b
F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e
F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc
F src/sqliteInt.h d3dd8e370f0c4e72a612c71c9b4255fee44806c8 F src/sqliteInt.h ab719053ec9fb58702dd8cdfc4fc9d4870af9979
F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158
F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
@@ -275,16 +275,16 @@ F src/test_vfs.c e72f555ef7a59080f898fcf1a233deb9eb704ea9
F src/test_vfstrace.c 3a0ab304682fecbceb689e7d9b904211fde11d78 F src/test_vfstrace.c 3a0ab304682fecbceb689e7d9b904211fde11d78
F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9
F src/tokenize.c 6da2de6e12218ccb0aea5184b56727d011f4bee7 F src/tokenize.c 6da2de6e12218ccb0aea5184b56727d011f4bee7
F src/trigger.c 5c1c0b899ac0ce284763dcb8fdbaa38ecf15ef98 F src/trigger.c a417d386e214f0abd2e0f756b834b4d9f4d3368a
F src/update.c a7df6fffce6bfedc578fda6136dd33e34a63f8ee F src/update.c a7df6fffce6bfedc578fda6136dd33e34a63f8ee
F src/utf.c 6fc6c88d50448c469c5c196acf21617a24f90269 F src/utf.c 6fc6c88d50448c469c5c196acf21617a24f90269
F src/util.c 15ac2627f548f5481d0d7e6c4eb67be673027695 F src/util.c 15ac2627f548f5481d0d7e6c4eb67be673027695
F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179 F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179
F src/vdbe.c e7bb0587ad4866c0db5fe3b83104c4df8f93d19f F src/vdbe.c 0944fe28f711ce12b631f00d18ecf9d82f2f04f8
F src/vdbe.h e6c4c610fcabad4fa80ebb1efc6822a9367e2b26 F src/vdbe.h e6c4c610fcabad4fa80ebb1efc6822a9367e2b26
F src/vdbeInt.h b5d62957a408c4bea649484008e5f98335b09e97 F src/vdbeInt.h b5d62957a408c4bea649484008e5f98335b09e97
F src/vdbeapi.c ce4e68ea4842cc6081046f533d088dcf01d247ad F src/vdbeapi.c ce4e68ea4842cc6081046f533d088dcf01d247ad
F src/vdbeaux.c 3fd95b226330e1d50aedb40d750effe726ebb3fb F src/vdbeaux.c 379343f1d98b60b0771366e5955f3cab34f1a3ca
F src/vdbeblob.c 9542e116c1db5ed813977581d506c176e117c0ec F src/vdbeblob.c 9542e116c1db5ed813977581d506c176e117c0ec
F src/vdbemem.c c0bcc02d6816ab4218ac0f94b63c8ee78a0f739f F src/vdbemem.c c0bcc02d6816ab4218ac0f94b63c8ee78a0f739f
F src/vdbesort.c 9d83601f9d6243fe70dd0169a2820c5ddfd48147 F src/vdbesort.c 9d83601f9d6243fe70dd0169a2820c5ddfd48147
@@ -293,7 +293,7 @@ F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd
F src/wal.c 7dc3966ef98b74422267e7e6e46e07ff6c6eb1b4 F src/wal.c 7dc3966ef98b74422267e7e6e46e07ff6c6eb1b4
F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
F src/walker.c 11edb74d587bc87b33ca96a5173e3ec1b8389e45 F src/walker.c 11edb74d587bc87b33ca96a5173e3ec1b8389e45
F src/where.c 8c2aada8b44140382406cf07b84ff2f6127cb39e F src/where.c 924f24a04bb639eb391ad12618f941bfb641a472
F src/whereInt.h 921f935af8b684ffb49705610bda7284db1db138 F src/whereInt.h 921f935af8b684ffb49705610bda7284db1db138
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
@@ -1152,8 +1152,7 @@ F tool/vdbe-compress.tcl 0cf56e9263a152b84da86e75a5c0cdcdb7a47891
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
P 4043d879795bfad55af35e9cb48e0a42eb4087ae a522f364a6b8ca6f69c353b30609a2166f6e94cf P 5a88b6a7aef3a0d5380e19eee2ee38439cc9b08b
R fcb91b77c89313a695cdcaff36627dad R a9b46d5717be39fdc7732934fcbad0a2
T +closed a522f364a6b8ca6f69c353b30609a2166f6e94cf
U drh U drh
Z 935dc7a454a2a09335ff0c234e8fb57e Z 07d97eaa48af367d9c2a599f3698a466

View File

@@ -1 +1 @@
5a88b6a7aef3a0d5380e19eee2ee38439cc9b08b 192dea97316144f15f6dd0eabff08a0bf9ef203e

View File

@@ -149,10 +149,11 @@ void sqlite3FinishCoding(Parse *pParse){
** transaction on each used database and to verify the schema cookie ** transaction on each used database and to verify the schema cookie
** on each used database. ** on each used database.
*/ */
if( pParse->cookieGoto>0 ){ if( db->mallocFailed==0 && pParse->cookieMask ){
yDbMask mask; yDbMask mask;
int iDb, i, addr; int iDb, i;
sqlite3VdbeJumpHere(v, pParse->cookieGoto-1); assert( sqlite3VdbeGetOp(v, 0)->opcode==OP_Init );
sqlite3VdbeJumpHere(v, 0);
for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){ for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
if( (mask & pParse->cookieMask)==0 ) continue; if( (mask & pParse->cookieMask)==0 ) continue;
sqlite3VdbeUsesBtree(v, iDb); sqlite3VdbeUsesBtree(v, iDb);
@@ -184,17 +185,16 @@ void sqlite3FinishCoding(Parse *pParse){
sqlite3AutoincrementBegin(pParse); sqlite3AutoincrementBegin(pParse);
/* Code constant expressions that where factored out of inner loops */ /* Code constant expressions that where factored out of inner loops */
addr = pParse->cookieGoto;
if( pParse->pConstExpr ){ if( pParse->pConstExpr ){
ExprList *pEL = pParse->pConstExpr; ExprList *pEL = pParse->pConstExpr;
pParse->cookieGoto = 0; pParse->okConstFactor = 0;
for(i=0; i<pEL->nExpr; i++){ for(i=0; i<pEL->nExpr; i++){
sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg); sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg);
} }
} }
/* Finally, jump back to the beginning of the executable code. */ /* Finally, jump back to the beginning of the executable code. */
sqlite3VdbeAddOp2(v, OP_Goto, 0, addr); sqlite3VdbeAddOp2(v, OP_Goto, 0, 1);
} }
} }
@@ -217,7 +217,6 @@ void sqlite3FinishCoding(Parse *pParse){
pParse->nSet = 0; pParse->nSet = 0;
pParse->nVar = 0; pParse->nVar = 0;
pParse->cookieMask = 0; pParse->cookieMask = 0;
pParse->cookieGoto = 0;
} }
/* /*
@@ -3826,59 +3825,29 @@ int sqlite3OpenTempDatabase(Parse *pParse){
} }
/* /*
** Generate VDBE code that will verify the schema cookie and start ** Record the fact that the schema cookie will need to be verified
** a read-transaction for all named database files. ** for database iDb. The code to actually verify the schema cookie
** ** will occur at the end of the top-level VDBE and will be generated
** It is important that all schema cookies be verified and all ** later, by sqlite3FinishCoding().
** read transactions be started before anything else happens in
** the VDBE program. But this routine can be called after much other
** code has been generated. So here is what we do:
**
** The first time this routine is called, we code an OP_Goto that
** will jump to a subroutine at the end of the program. Then we
** record every database that needs its schema verified in the
** pParse->cookieMask field. Later, after all other code has been
** generated, the subroutine that does the cookie verifications and
** starts the transactions will be coded and the OP_Goto P2 value
** will be made to point to that subroutine. The generation of the
** cookie verification subroutine code happens in sqlite3FinishCoding().
**
** If iDb<0 then code the OP_Goto only - don't set flag to verify the
** schema on any databases. This can be used to position the OP_Goto
** early in the code, before we know if any database tables will be used.
*/ */
void sqlite3CodeVerifySchema(Parse *pParse, int iDb){ void sqlite3CodeVerifySchema(Parse *pParse, int iDb){
Parse *pToplevel = sqlite3ParseToplevel(pParse); Parse *pToplevel = sqlite3ParseToplevel(pParse);
sqlite3 *db = pToplevel->db;
yDbMask mask;
#ifndef SQLITE_OMIT_TRIGGER assert( iDb>=0 && iDb<db->nDb );
if( pToplevel!=pParse ){ assert( db->aDb[iDb].pBt!=0 || iDb==1 );
/* This branch is taken if a trigger is currently being coded. In this assert( iDb<SQLITE_MAX_ATTACHED+2 );
** case, set cookieGoto to a non-zero value to show that this function assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
** has been called. This is used by the sqlite3ExprCodeConstants() mask = ((yDbMask)1)<<iDb;
** function. */ if( (pToplevel->cookieMask & mask)==0 ){
pParse->cookieGoto = -1; pToplevel->cookieMask |= mask;
} pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie;
#endif if( !OMIT_TEMPDB && iDb==1 ){
if( pToplevel->cookieGoto==0 ){ sqlite3OpenTempDatabase(pToplevel);
Vdbe *v = sqlite3GetVdbe(pToplevel); }
if( v==0 ) return; /* This only happens if there was a prior error */ if( pToplevel==pParse && OptimizationEnabled(db,SQLITE_FactorOutConst) ){
pToplevel->cookieGoto = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0)+1; pParse->okConstFactor = 1;
}
if( iDb>=0 ){
sqlite3 *db = pToplevel->db;
yDbMask mask;
assert( iDb<db->nDb );
assert( db->aDb[iDb].pBt!=0 || iDb==1 );
assert( iDb<SQLITE_MAX_ATTACHED+2 );
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
mask = ((yDbMask)1)<<iDb;
if( (pToplevel->cookieMask & mask)==0 ){
pToplevel->cookieMask |= mask;
pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie;
if( !OMIT_TEMPDB && iDb==1 ){
sqlite3OpenTempDatabase(pToplevel);
}
} }
} }
} }

View File

@@ -2038,7 +2038,7 @@ static int xferOptimization(
sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0); sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
sqlite3VdbeAddOp2(v, OP_Close, iDest, 0); sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
} }
sqlite3VdbeJumpHere(v, emptySrcTest); if( emptySrcTest ) sqlite3VdbeJumpHere(v, emptySrcTest);
sqlite3ReleaseTempReg(pParse, regRowid); sqlite3ReleaseTempReg(pParse, regRowid);
sqlite3ReleaseTempReg(pParse, regData); sqlite3ReleaseTempReg(pParse, regData);
if( emptyDestTest ){ if( emptyDestTest ){

View File

@@ -1615,11 +1615,7 @@ Vdbe *sqlite3GetVdbe(Parse *pParse){
Vdbe *v = pParse->pVdbe; Vdbe *v = pParse->pVdbe;
if( v==0 ){ if( v==0 ){
v = pParse->pVdbe = sqlite3VdbeCreate(pParse); v = pParse->pVdbe = sqlite3VdbeCreate(pParse);
#ifndef SQLITE_OMIT_TRACE if( v ) sqlite3VdbeAddOp0(v, OP_Init);
if( v ){
sqlite3VdbeAddOp0(v, OP_Trace);
}
#endif
} }
return v; return v;
} }
@@ -4537,15 +4533,6 @@ int sqlite3Select(
*/ */
int addrTop; int addrTop;
pItem->regReturn = ++pParse->nMem; pItem->regReturn = ++pParse->nMem;
/* Before coding the OP_Goto to jump to the start of the main routine,
** ensure that the jump to the verify-schema routine has already
** been coded. Otherwise, the verify-schema would likely be coded as
** part of the co-routine. If the main routine then accessed the
** database before invoking the co-routine for the first time (for
** example to initialize a LIMIT register from a sub-select), it would
** be doing so without having verified the schema version and obtained
** the required db locks. See ticket d6b36be38. */
sqlite3CodeVerifySchema(pParse, -1);
sqlite3VdbeAddOp0(v, OP_Goto); sqlite3VdbeAddOp0(v, OP_Goto);
addrTop = sqlite3VdbeAddOp1(v, OP_OpenPseudo, pItem->iCursor); addrTop = sqlite3VdbeAddOp1(v, OP_OpenPseudo, pItem->iCursor);
sqlite3VdbeChangeP5(v, 1); sqlite3VdbeChangeP5(v, 1);

View File

@@ -1088,8 +1088,7 @@ struct sqlite3 {
** Return true if it OK to factor constant expressions into the initialization ** Return true if it OK to factor constant expressions into the initialization
** code. The argument is a Parse object for the code generator. ** code. The argument is a Parse object for the code generator.
*/ */
#define ConstFactorOk(P) \ #define ConstFactorOk(P) ((P)->okConstFactor)
((P)->cookieGoto>0 && OptimizationEnabled((P)->db,SQLITE_FactorOutConst))
/* /*
** Possible values for the sqlite.magic field. ** Possible values for the sqlite.magic field.
@@ -2354,6 +2353,7 @@ struct Parse {
u8 isMultiWrite; /* True if statement may modify/insert multiple rows */ u8 isMultiWrite; /* True if statement may modify/insert multiple rows */
u8 mayAbort; /* True if statement may throw an ABORT exception */ u8 mayAbort; /* True if statement may throw an ABORT exception */
u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */ u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */
u8 okConstFactor; /* OK to factor out constants */
int aTempReg[8]; /* Holding area for temporary registers */ int aTempReg[8]; /* Holding area for temporary registers */
int nRangeReg; /* Size of the temporary register block */ int nRangeReg; /* Size of the temporary register block */
int iRangeReg; /* First register in temporary register block */ int iRangeReg; /* First register in temporary register block */
@@ -2382,7 +2382,6 @@ struct Parse {
Token constraintName;/* Name of the constraint currently being parsed */ Token constraintName;/* Name of the constraint currently being parsed */
yDbMask writeMask; /* Start a write transaction on these databases */ yDbMask writeMask; /* Start a write transaction on these databases */
yDbMask cookieMask; /* Bitmask of schema verified databases */ yDbMask cookieMask; /* Bitmask of schema verified databases */
int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */
int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */ int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */
int regRowid; /* Register holding rowid of CREATE TABLE entry */ int regRowid; /* Register holding rowid of CREATE TABLE entry */
int regRoot; /* Register holding root page number for new objects */ int regRoot; /* Register holding root page number for new objects */

View File

@@ -726,15 +726,7 @@ static int codeTriggerProgram(
** INSERT OR IGNORE INTO t1 ... ; -- insert into t2 uses IGNORE policy ** INSERT OR IGNORE INTO t1 ... ; -- insert into t2 uses IGNORE policy
*/ */
pParse->eOrconf = (orconf==OE_Default)?pStep->orconf:(u8)orconf; pParse->eOrconf = (orconf==OE_Default)?pStep->orconf:(u8)orconf;
assert( pParse->okConstFactor==0 );
/* Clear the cookieGoto flag. When coding triggers, the cookieGoto
** variable is used as a flag to indicate to sqlite3ExprCodeConstants()
** that it is not safe to refactor constants (this happens after the
** start of the first loop in the SQL statement is coded - at that
** point code may be conditionally executed, so it is no longer safe to
** initialize constant register values). */
assert( pParse->cookieGoto==0 || pParse->cookieGoto==-1 );
pParse->cookieGoto = 0;
switch( pStep->op ){ switch( pStep->op ){
case TK_UPDATE: { case TK_UPDATE: {

View File

@@ -6144,16 +6144,26 @@ case OP_MaxPgcnt: { /* out2-prerelease */
#endif #endif
#ifndef SQLITE_OMIT_TRACE /* Opcode: Init * P2 * P4 *
/* Opcode: Trace * * * P4 * ** Synopsis: Start at P2
**
** Programs contain a single instance of this opcode as the very first
** opcode.
** **
** If tracing is enabled (by the sqlite3_trace()) interface, then ** If tracing is enabled (by the sqlite3_trace()) interface, then
** the UTF-8 string contained in P4 is emitted on the trace callback. ** the UTF-8 string contained in P4 is emitted on the trace callback.
** Or if P4 is blank, use the string returned by sqlite3_sql().
**
** If P2 is not zero, jump to instruction P2.
*/ */
case OP_Trace: { case OP_Init: { /* jump */
char *zTrace; char *zTrace;
char *z; char *z;
if( pOp->p2 ){
pc = pOp->p2 - 1;
}
#ifndef SQLITE_OMIT_TRACE
if( db->xTrace if( db->xTrace
&& !p->doingRerun && !p->doingRerun
&& (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
@@ -6179,9 +6189,9 @@ case OP_Trace: {
sqlite3DebugPrintf("SQL-trace: %s\n", zTrace); sqlite3DebugPrintf("SQL-trace: %s\n", zTrace);
} }
#endif /* SQLITE_DEBUG */ #endif /* SQLITE_DEBUG */
#endif /* SQLITE_OMIT_TRACE */
break; break;
} }
#endif
/* Opcode: Noop * * * * * /* Opcode: Noop * * * * *

View File

@@ -863,14 +863,6 @@ void sqlite3VdbeNoopComment(Vdbe *p, const char *zFormat, ...){
** this routine is a valid pointer. But because the dummy.opcode is 0, ** this routine is a valid pointer. But because the dummy.opcode is 0,
** dummy will never be written to. This is verified by code inspection and ** dummy will never be written to. This is verified by code inspection and
** by running with Valgrind. ** by running with Valgrind.
**
** About the #ifdef SQLITE_OMIT_TRACE: Normally, this routine is never called
** unless p->nOp>0. This is because in the absense of SQLITE_OMIT_TRACE,
** an OP_Trace instruction is always inserted by sqlite3VdbeGet() as soon as
** a new VDBE is created. So we are free to set addr to p->nOp-1 without
** having to double-check to make sure that the result is non-negative. But
** if SQLITE_OMIT_TRACE is defined, the OP_Trace is omitted and we do need to
** check the value of p->nOp-1 before continuing.
*/ */
VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){ VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){
/* C89 specifies that the constant "dummy" will be initialized to all /* C89 specifies that the constant "dummy" will be initialized to all
@@ -878,9 +870,6 @@ VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){
static VdbeOp dummy; /* Ignore the MSVC warning about no initializer */ static VdbeOp dummy; /* Ignore the MSVC warning about no initializer */
assert( p->magic==VDBE_MAGIC_INIT ); assert( p->magic==VDBE_MAGIC_INIT );
if( addr<0 ){ if( addr<0 ){
#ifdef SQLITE_OMIT_TRACE
if( p->nOp==0 ) return (VdbeOp*)&dummy;
#endif
addr = p->nOp - 1; addr = p->nOp - 1;
} }
assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed ); assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed );
@@ -1465,7 +1454,7 @@ void sqlite3VdbePrintSql(Vdbe *p){
z = p->zSql; z = p->zSql;
}else if( p->nOp>=1 ){ }else if( p->nOp>=1 ){
const VdbeOp *pOp = &p->aOp[0]; const VdbeOp *pOp = &p->aOp[0];
if( pOp->opcode==OP_Trace && pOp->p4.z!=0 ){ if( pOp->opcode==OP_Init && pOp->p4.z!=0 ){
z = pOp->p4.z; z = pOp->p4.z;
while( sqlite3Isspace(*z) ) z++; while( sqlite3Isspace(*z) ) z++;
} }
@@ -1484,7 +1473,7 @@ void sqlite3VdbeIOTraceSql(Vdbe *p){
if( sqlite3IoTrace==0 ) return; if( sqlite3IoTrace==0 ) return;
if( nOp<1 ) return; if( nOp<1 ) return;
pOp = &p->aOp[0]; pOp = &p->aOp[0];
if( pOp->opcode==OP_Trace && pOp->p4.z!=0 ){ if( pOp->opcode==OP_Init && pOp->p4.z!=0 ){
int i, j; int i, j;
char z[1000]; char z[1000];
sqlite3_snprintf(sizeof(z), z, "%s", pOp->p4.z); sqlite3_snprintf(sizeof(z), z, "%s", pOp->p4.z);

View File

@@ -5436,7 +5436,6 @@ WhereInfo *sqlite3WhereBegin(
initMaskSet(pMaskSet); initMaskSet(pMaskSet);
whereClauseInit(&pWInfo->sWC, pWInfo); whereClauseInit(&pWInfo->sWC, pWInfo);
whereSplit(&pWInfo->sWC, pWhere, TK_AND); whereSplit(&pWInfo->sWC, pWhere, TK_AND);
sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
/* Special case: a WHERE clause that is constant. Evaluate the /* Special case: a WHERE clause that is constant. Evaluate the
** expression and either jump over all of the code or fall thru. ** expression and either jump over all of the code or fall thru.
@@ -5725,7 +5724,7 @@ WhereInfo *sqlite3WhereBegin(
sqlite3VdbeSetP4KeyInfo(pParse, pIx); sqlite3VdbeSetP4KeyInfo(pParse, pIx);
VdbeComment((v, "%s", pIx->zName)); VdbeComment((v, "%s", pIx->zName));
} }
sqlite3CodeVerifySchema(pParse, iDb); if( iDb>=0 ) sqlite3CodeVerifySchema(pParse, iDb);
notReady &= ~getMask(&pWInfo->sMaskSet, pTabItem->iCursor); notReady &= ~getMask(&pWInfo->sMaskSet, pTabItem->iCursor);
} }
pWInfo->iTop = sqlite3VdbeCurrentAddr(v); pWInfo->iTop = sqlite3VdbeCurrentAddr(v);