mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-15 11:41:13 +03:00
Avoid unnecessary zeroing of fields in the Vdbe object when it is allocated.
FossilOrigin-Name: 1e21bbe836539e64d24857f4faa3d12cd607dc7e
This commit is contained in:
@@ -340,34 +340,47 @@ struct ScanStatus {
|
||||
*/
|
||||
struct Vdbe {
|
||||
sqlite3 *db; /* The database connection that owns this statement */
|
||||
Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
|
||||
Parse *pParse; /* Parsing context used to create this Vdbe */
|
||||
ynVar nVar; /* Number of entries in aVar[] */
|
||||
ynVar nzVar; /* Number of entries in azVar[] */
|
||||
u32 magic; /* Magic number for sanity checking */
|
||||
int nMem; /* Number of memory locations currently allocated */
|
||||
int nCursor; /* Number of slots in apCsr[] */
|
||||
u32 cacheCtr; /* VdbeCursor row cache generation counter */
|
||||
int pc; /* The program counter */
|
||||
int rc; /* Value to return */
|
||||
int nChange; /* Number of db changes made since last reset */
|
||||
int iStatement; /* Statement number (or 0 if has not opened stmt) */
|
||||
i64 iCurrentTime; /* Value of julianday('now') for this statement */
|
||||
i64 nFkConstraint; /* Number of imm. FK constraints this VM */
|
||||
i64 nStmtDefCons; /* Number of def. constraints when stmt started */
|
||||
i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */
|
||||
|
||||
/* When allocating a new Vdbe object, all of the fields below should be
|
||||
** initialized to zero or NULL */
|
||||
|
||||
Op *aOp; /* Space to hold the virtual machine's program */
|
||||
Mem *aMem; /* The memory locations */
|
||||
Mem **apArg; /* Arguments to currently executing user function */
|
||||
Mem *aColName; /* Column names to return */
|
||||
Mem *pResultSet; /* Pointer to an array of results */
|
||||
Parse *pParse; /* Parsing context used to create this Vdbe */
|
||||
int nMem; /* Number of memory locations currently allocated */
|
||||
int nOp; /* Number of instructions in the program */
|
||||
int nCursor; /* Number of slots in apCsr[] */
|
||||
u32 magic; /* Magic number for sanity checking */
|
||||
char *zErrMsg; /* Error message written here */
|
||||
Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
|
||||
VdbeCursor **apCsr; /* One element of this array for each open cursor */
|
||||
Mem *aVar; /* Values for the OP_Variable opcode. */
|
||||
char **azVar; /* Name of variables */
|
||||
ynVar nVar; /* Number of entries in aVar[] */
|
||||
ynVar nzVar; /* Number of entries in azVar[] */
|
||||
u32 cacheCtr; /* VdbeCursor row cache generation counter */
|
||||
int pc; /* The program counter */
|
||||
int rc; /* Value to return */
|
||||
#ifndef SQLITE_OMIT_TRACE
|
||||
i64 startTime; /* Time when query started - used for profiling */
|
||||
#endif
|
||||
int nOp; /* Number of instructions in the program */
|
||||
#ifdef SQLITE_DEBUG
|
||||
int rcApp; /* errcode set by sqlite3_result_error_code() */
|
||||
#endif
|
||||
u16 nResColumn; /* Number of columns in one row of the result set */
|
||||
u8 errorAction; /* Recovery action to do in case of an error */
|
||||
u8 minWriteFileFormat; /* Minimum file format for writable database files */
|
||||
bft expired:1; /* True if the VM needs to be recompiled */
|
||||
bft doingRerun:1; /* True if rerunning after an auto-reprepare */
|
||||
u8 minWriteFileFormat; /* Minimum file format for writable database files */
|
||||
bft explain:2; /* True if EXPLAIN present on SQL command */
|
||||
bft changeCntOn:1; /* True to update the change-counter */
|
||||
bft runOnlyOnce:1; /* Automatically expire on reset */
|
||||
@@ -375,18 +388,9 @@ struct Vdbe {
|
||||
bft readOnly:1; /* True for statements that do not write */
|
||||
bft bIsReader:1; /* True for statements that read */
|
||||
bft isPrepareV2:1; /* True if prepared with prepare_v2() */
|
||||
int nChange; /* Number of db changes made since last reset */
|
||||
yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */
|
||||
yDbMask lockMask; /* Subset of btreeMask that requires a lock */
|
||||
int iStatement; /* Statement number (or 0 if has not opened stmt) */
|
||||
u32 aCounter[5]; /* Counters used by sqlite3_stmt_status() */
|
||||
#ifndef SQLITE_OMIT_TRACE
|
||||
i64 startTime; /* Time when query started - used for profiling */
|
||||
#endif
|
||||
i64 iCurrentTime; /* Value of julianday('now') for this statement */
|
||||
i64 nFkConstraint; /* Number of imm. FK constraints this VM */
|
||||
i64 nStmtDefCons; /* Number of def. constraints when stmt started */
|
||||
i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */
|
||||
char *zSql; /* Text of the SQL statement that generated this */
|
||||
void *pFree; /* Free this when deleting the vdbe */
|
||||
VdbeFrame *pFrame; /* Parent frame */
|
||||
@@ -405,10 +409,11 @@ struct Vdbe {
|
||||
/*
|
||||
** The following are allowed values for Vdbe.magic
|
||||
*/
|
||||
#define VDBE_MAGIC_INIT 0x26bceaa5 /* Building a VDBE program */
|
||||
#define VDBE_MAGIC_RUN 0xbdf20da3 /* VDBE is ready to execute */
|
||||
#define VDBE_MAGIC_HALT 0x519c2973 /* VDBE has completed execution */
|
||||
#define VDBE_MAGIC_DEAD 0xb606c3c8 /* The VDBE has been deallocated */
|
||||
#define VDBE_MAGIC_INIT 0x16bceaa5 /* Building a VDBE program */
|
||||
#define VDBE_MAGIC_RUN 0x2df20da3 /* VDBE is ready to execute */
|
||||
#define VDBE_MAGIC_HALT 0x319c2973 /* VDBE has completed execution */
|
||||
#define VDBE_MAGIC_RESET 0x48fa9f76 /* Reset and ready to run again */
|
||||
#define VDBE_MAGIC_DEAD 0x5606c3c8 /* The VDBE has been deallocated */
|
||||
|
||||
/*
|
||||
** Structure used to store the context required by the
|
||||
|
||||
@@ -21,8 +21,9 @@
|
||||
Vdbe *sqlite3VdbeCreate(Parse *pParse){
|
||||
sqlite3 *db = pParse->db;
|
||||
Vdbe *p;
|
||||
p = sqlite3DbMallocZero(db, sizeof(Vdbe) );
|
||||
p = sqlite3DbMallocRaw(db, sizeof(Vdbe) );
|
||||
if( p==0 ) return 0;
|
||||
memset(&p->aOp, 0, sizeof(Vdbe)-offsetof(Vdbe,aOp));
|
||||
p->db = db;
|
||||
if( db->pVdbe ){
|
||||
db->pVdbe->pPrev = p;
|
||||
@@ -1826,7 +1827,7 @@ void sqlite3VdbeRewind(Vdbe *p){
|
||||
int i;
|
||||
#endif
|
||||
assert( p!=0 );
|
||||
assert( p->magic==VDBE_MAGIC_INIT );
|
||||
assert( p->magic==VDBE_MAGIC_INIT || p->magic==VDBE_MAGIC_RESET );
|
||||
|
||||
/* There should be at least one opcode.
|
||||
*/
|
||||
@@ -1953,7 +1954,11 @@ void sqlite3VdbeMakeReady(
|
||||
pParse->nzVar = 0;
|
||||
pParse->azVar = 0;
|
||||
p->explain = pParse->explain;
|
||||
if( db->mallocFailed==0 ){
|
||||
if( db->mallocFailed ){
|
||||
p->nVar = 0;
|
||||
p->nCursor = 0;
|
||||
p->nMem = 0;
|
||||
}else{
|
||||
p->nCursor = nCursor;
|
||||
p->nVar = (ynVar)nVar;
|
||||
initMemArray(p->aVar, nVar, db, MEM_Null);
|
||||
@@ -2880,7 +2885,7 @@ int sqlite3VdbeReset(Vdbe *p){
|
||||
}
|
||||
#endif
|
||||
p->iCurrentTime = 0;
|
||||
p->magic = VDBE_MAGIC_INIT;
|
||||
p->magic = VDBE_MAGIC_RESET;
|
||||
return p->rc & db->errMask;
|
||||
}
|
||||
|
||||
@@ -2951,7 +2956,9 @@ void sqlite3VdbeClearObject(sqlite3 *db, Vdbe *p){
|
||||
vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
|
||||
sqlite3DbFree(db, pSub);
|
||||
}
|
||||
for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]);
|
||||
if( p->magic!=VDBE_MAGIC_INIT ){
|
||||
for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]);
|
||||
}
|
||||
sqlite3DbFree(db, p->azVar);
|
||||
vdbeFreeOpArray(db, p->aOp, p->nOp);
|
||||
sqlite3DbFree(db, p->aColName);
|
||||
|
||||
Reference in New Issue
Block a user