Simplifications to vdbe.c in support of coverage testing. (CVS 6794)

FossilOrigin-Name: 16680f05bd169dfb1b4bf0eb082e69701f9b07ab
This commit is contained in:
drh 2009-06-22 00:55:30 +00:00
parent 3a1bf71f95
commit aa73609f92
5 changed files with 67 additions and 104 deletions

View File

@ -1,5 +1,5 @@
C When\srecovering\sfrom\sthe\serror-state\sin\spagerSharedLock(),\sdo\snot\ssearch\sfor\sa\shot-journal\sin\sthe\sfile-system\sif\sthe\spager\sis\sconfigured\sto\suse\san\sanonymous\stemp\sfile\sas\sthe\sjournal.\s(CVS\s6793)
D 2009-06-20T18:52:50
C Simplifications\sto\svdbe.c\sin\ssupport\sof\scoverage\stesting.\s(CVS\s6794)
D 2009-06-22T00:55:31
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 8b8fb7823264331210cddf103831816c286ba446
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -203,11 +203,11 @@ F src/update.c 6ae6c26adff8dc34532d578f66e6cfde04b5d177
F src/utf.c 9541d28f40441812c0b40f00334372a0542c00ff
F src/util.c a7e981e032c3c9c0887d50d7e658a33cb355b43d
F src/vacuum.c 0e14f371ea3326c6b8cfba257286d798cd20db59
F src/vdbe.c 51b0d7394f70a114b11bf0263dfe7c59b802f932
F src/vdbe.c 67ec344095e6d9d68292aec3be3d96295561b8d6
F src/vdbe.h 35a648bc3279a120da24f34d9a25213ec15daf8a
F src/vdbeInt.h f5147efa8ead0ae78496487a83c7e87c54ffa405
F src/vdbeInt.h 7823eac611229163c6a5df0e9e0d54ffcda527e7
F src/vdbeapi.c 73bd1d2c57b953bc688d1d8c84b24c2084c2aec7
F src/vdbeaux.c 77b6734303c58e36db65f6e63795425546905059
F src/vdbeaux.c 516b7e123ece051e93ab1aa96c2ff04578b3b465
F src/vdbeblob.c c25d7e7bc6d5917feeb17270bd275fa771f26e5c
F src/vdbemem.c ba39c0afa609595c7c23dfc2ac929d9414faa59f
F src/vtab.c 98fbffc5efe68d8107511dec0a650efc7daa9446
@ -736,7 +736,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl 672f81d693a03f80f5ae60bfefacd8a349e76746
P 9a0666003764774b0bf861687002f8db9fd314b1
R 5dd91765f94027c048c1a58ba9ebd707
U danielk1977
Z 0386e8ad9294e91ace2c01f921b33dd2
P 4b46805cbc9fe71f1febe9ea5f0f5634b65128e3
R 9ec6304164ed6368f2b420838c219481
U drh
Z 85bde85d2f308c9e2ad6cd0b0c32a22d

View File

@ -1 +1 @@
4b46805cbc9fe71f1febe9ea5f0f5634b65128e3
16680f05bd169dfb1b4bf0eb082e69701f9b07ab

View File

@ -43,7 +43,7 @@
** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
**
** $Id: vdbe.c,v 1.857 2009/06/19 22:23:42 drh Exp $
** $Id: vdbe.c,v 1.858 2009/06/22 00:55:31 drh Exp $
*/
#include "sqliteInt.h"
#include "vdbeInt.h"
@ -1107,9 +1107,13 @@ case OP_ResultRow: {
** If the open statement-transaction is not closed here, then the user
** may step another VM that opens its own statement transaction. This
** may lead to overlapping statement transactions.
**
** The statement transaction is never a top-level transaction. Hence
** the RELEASE call below can never fail.
*/
assert( p->iStatement==0 || db->flags&SQLITE_CountRows );
if( SQLITE_OK!=(rc = sqlite3VdbeCloseStatement(p, SAVEPOINT_RELEASE)) ){
rc = sqlite3VdbeCloseStatement(p, SAVEPOINT_RELEASE);
if( NEVER(rc!=SQLITE_OK) ){
break;
}
@ -2052,10 +2056,10 @@ case OP_Column: {
zRec = (char*)pC->aRow;
}else if( pC->isIndex ){
sqlite3BtreeKeySize(pCrsr, &payloadSize64);
if( (payloadSize64 & SQLITE_MAX_U32)!=(u64)payloadSize64 ){
rc = SQLITE_CORRUPT_BKPT;
goto abort_due_to_error;
}
/* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the
** payload size, so it is impossible for payloadSize64 to be
** larger than 32 bits. */
assert( (payloadSize64 & SQLITE_MAX_U32)==(u64)payloadSize64 );
payloadSize = (u32)payloadSize64;
}else{
sqlite3BtreeDataSize(pCrsr, &payloadSize);
@ -2941,7 +2945,7 @@ case OP_OpenWrite: {
pIn2 = &p->aMem[p2];
sqlite3VdbeMemIntegerify(pIn2);
p2 = (int)pIn2->u.i;
if( p2<2 ) {
if( NEVER(p2<2) ) {
rc = SQLITE_CORRUPT_BKPT;
goto abort_due_to_error;
}
@ -2961,23 +2965,19 @@ case OP_OpenWrite: {
pCur->pKeyInfo = pKeyInfo;
switch( rc ){
case SQLITE_BUSY: {
p->pc = pc;
p->rc = rc = SQLITE_BUSY;
goto vdbe_return;
}
case SQLITE_OK: {
flags = sqlite3BtreeFlags(pCur->pCursor);
/* Sanity checking. Only the lower four bits of the flags byte should
** be used. Bit 3 (mask 0x08) is unpredictable. The lower 3 bits
** (mask 0x07) should be either 5 (intkey+leafdata for tables) or
** 2 (zerodata for indices). If these conditions are not met it can
** only mean that we are dealing with a corrupt database file
** only mean that we are dealing with a corrupt database file.
** Note: All of the above is checked already in sqlite3BtreeCursor().
*/
if( (flags & 0xf0)!=0 || ((flags & 0x07)!=5 && (flags & 0x07)!=2) ){
rc = SQLITE_CORRUPT_BKPT;
goto abort_due_to_error;
}
assert( (flags & 0xf0)==0 );
assert( (flags & 0x07)==5 || (flags & 0x07)==2 );
pCur->isTable = (flags & BTREE_INTKEY)!=0 ?1:0;
pCur->isIndex = (flags & BTREE_ZERODATA)!=0 ?1:0;
/* If P4==0 it means we are expected to open a table. If P4!=0 then
@ -2999,6 +2999,7 @@ case OP_OpenWrite: {
break;
}
default: {
assert( rc!=SQLITE_BUSY ); /* Busy conditions detected earlier */
goto abort_due_to_error;
}
}
@ -3217,7 +3218,7 @@ case OP_SeekGt: { /* jump, in3 */
assert( (pIn3->flags & MEM_Real)!=0 );
if( iKey==SMALLEST_INT64 && (pIn3->r<(double)iKey || pIn3->r>0) ){
/* The P3 value is to large in magnitude to be expressed as an
/* The P3 value is too large in magnitude to be expressed as an
** integer. */
res = 1;
if( pIn3->r<0 ){
@ -3300,11 +3301,12 @@ case OP_SeekGt: { /* jump, in3 */
if( res ){
pc = pOp->p2 - 1;
}
}else if( !pC->pseudoTable ){
}else{
/* This happens when attempting to open the sqlite3_master table
** for read access returns SQLITE_EMPTY. In this case always
** take the jump (since there are no records in the table).
*/
assert( pC->pseudoTable==0 );
pc = pOp->p2 - 1;
}
break;
@ -3327,7 +3329,7 @@ case OP_Seek: { /* in2 */
assert( i>=0 && i<p->nCursor );
pC = p->apCsr[i];
assert( pC!=0 );
if( pC->pCursor!=0 ){
if( ALWAYS(pC->pCursor!=0) ){
assert( pC->isTable );
pC->nullRow = 0;
pC->movetoTarget = sqlite3VdbeIntValue(pIn2);
@ -3370,18 +3372,17 @@ case OP_Seek: { /* in2 */
*/
case OP_NotFound: /* jump, in3 */
case OP_Found: { /* jump, in3 */
int i;
int alreadyExists;
VdbeCursor *pC;
int res;
UnpackedRecord *pIdxKey;
char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*3 + 7];
i = pOp->p1;
alreadyExists = 0;
assert( i>=0 && i<p->nCursor );
assert( p->apCsr[i]!=0 );
if( (pC = p->apCsr[i])->pCursor!=0 ){
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
pC = p->apCsr[pOp->p1];
assert( pC!=0 );
if( ALWAYS(pC->pCursor!=0) ){
assert( pC->isTable==0 );
assert( pIn3->flags & MEM_Blob );
@ -3507,20 +3508,20 @@ case OP_IsUnique: { /* jump, in3 */
** See also: Found, NotFound, IsUnique
*/
case OP_NotExists: { /* jump, in3 */
int i;
VdbeCursor *pC;
BtCursor *pCrsr;
int res;
u64 iKey;
i = pOp->p1;
assert( i>=0 && i<p->nCursor );
assert( p->apCsr[i]!=0 );
if( (pCrsr = (pC = p->apCsr[i])->pCursor)!=0 ){
assert( pIn3->flags & MEM_Int );
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
pC = p->apCsr[pOp->p1];
assert( pC!=0 );
assert( pC->isTable );
pCrsr = pC->pCursor;
if( pCrsr!=0 ){
res = 0;
assert( pIn3->flags & MEM_Int );
assert( p->apCsr[i]->isTable );
iKey = intToKey(pIn3->u.i);
iKey = pIn3->u.i;
rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res);
pC->lastRowid = pIn3->u.i;
pC->rowidIsValid = res==0 ?1:0;
@ -3532,10 +3533,11 @@ case OP_NotExists: { /* jump, in3 */
assert( pC->rowidIsValid==0 );
}
pC->seekResult = res;
}else if( !pC->pseudoTable ){
}else{
/* This happens when an attempt to open a read cursor on the
** sqlite_master table returns SQLITE_EMPTY.
*/
assert( !pC->pseudoTable );
assert( pC->isTable );
pc = pOp->p2 - 1;
assert( pC->rowidIsValid==0 );
@ -3576,22 +3578,18 @@ case OP_Sequence: { /* out2-prerelease */
** AUTOINCREMENT feature.
*/
case OP_NewRowid: { /* out2-prerelease */
int i;
i64 v;
VdbeCursor *pC;
int res;
int rx;
int cnt;
i64 x;
Mem *pMem;
i64 v; /* The new rowid */
VdbeCursor *pC; /* Cursor of table to get the new rowid */
int res; /* Result of an sqlite3BtreeLast() */
int cnt; /* Counter to limit the number of searches */
Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */
i = pOp->p1;
v = 0;
res = 0;
rx = SQLITE_OK;
assert( i>=0 && i<p->nCursor );
assert( p->apCsr[i]!=0 );
if( (pC = p->apCsr[i])->pCursor==0 ){
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
pC = p->apCsr[pOp->p1];
assert( pC!=0 );
if( NEVER(pC->pCursor==0) ){
/* The zero initialization above is all that is needed */
}else{
/* The next rowid or record number (different terms for the same
@ -3605,34 +3603,10 @@ case OP_NewRowid: { /* out2-prerelease */
** The second algorithm is to select a rowid at random and see if
** it already exists in the table. If it does not exist, we have
** succeeded. If the random rowid does exist, we select a new one
** and try again, up to 1000 times.
**
** For a table with less than 2 billion entries, the probability
** of not finding a unused rowid is about 1.0e-300. This is a
** non-zero probability, but it is still vanishingly small and should
** never cause a problem. You are much, much more likely to have a
** hardware failure than for this algorithm to fail.
**
** The analysis in the previous paragraph assumes that you have a good
** source of random numbers. Is a library function like lrand48()
** good enough? Maybe. Maybe not. It's hard to know whether there
** might be subtle bugs is some implementations of lrand48() that
** could cause problems. To avoid uncertainty, SQLite uses its own
** random number generator based on the RC4 algorithm.
**
** To promote locality of reference for repetitive inserts, the
** first few attempts at choosing a random rowid pick values just a little
** larger than the previous rowid. This has been shown experimentally
** to double the speed of the COPY operation.
** and try again, up to 100 times.
*/
assert( pC->isTable );
cnt = 0;
if( (sqlite3BtreeFlags(pC->pCursor)&(BTREE_INTKEY|BTREE_ZERODATA)) !=
BTREE_INTKEY ){
rc = SQLITE_CORRUPT_BKPT;
goto abort_due_to_error;
}
assert( (sqlite3BtreeFlags(pC->pCursor) & BTREE_INTKEY)!=0 );
assert( (sqlite3BtreeFlags(pC->pCursor) & BTREE_ZERODATA)==0 );
#ifdef SQLITE_32BIT_ROWID
# define MAX_ROWID 0x7fffffff
@ -3655,7 +3629,6 @@ case OP_NewRowid: { /* out2-prerelease */
v = 1;
}else{
sqlite3BtreeKeySize(pC->pCursor, &v);
v = keyToInt(v);
if( v==MAX_ROWID ){
pC->useRandomRowid = 1;
}else{
@ -3685,7 +3658,8 @@ case OP_NewRowid: { /* out2-prerelease */
sqlite3BtreeSetCachedRowid(pC->pCursor, v<MAX_ROWID ? v+1 : 0);
}
if( pC->useRandomRowid ){
assert( pOp->p3==0 ); /* SQLITE_FULL must have occurred prior to this */
assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is
** an AUTOINCREMENT table. */
v = db->priorNewRowid;
cnt = 0;
do{
@ -3695,13 +3669,11 @@ case OP_NewRowid: { /* out2-prerelease */
sqlite3_randomness(sizeof(v), &v);
if( cnt<5 ) v &= 0xffffff;
}
if( v==0 ) continue;
x = intToKey(v);
rx = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)x, 0, &res);
rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)v, 0, &res);
cnt++;
}while( cnt<100 && rx==SQLITE_OK && res==0 );
}while( cnt<100 && rc==SQLITE_OK && res==0 );
db->priorNewRowid = v;
if( rx==SQLITE_OK && res==0 ){
if( rc==SQLITE_OK && res==0 ){
rc = SQLITE_FULL;
goto abort_due_to_error;
}
@ -3765,7 +3737,7 @@ case OP_Insert: {
REGISTER_TRACE(pOp->p2, pData);
REGISTER_TRACE(pOp->p3, pKey);
iKey = intToKey(pKey->u.i);
iKey = pKey->u.i;
if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = pKey->u.i;
if( pData->flags & MEM_Null ){
@ -3995,7 +3967,7 @@ case OP_Rowid: { /* out2-prerelease */
}else if( pC->deferredMoveto ){
v = pC->movetoTarget;
}else if( pC->pseudoTable ){
v = keyToInt(pC->iKey);
v = pC->iKey;
#ifndef SQLITE_OMIT_VIRTUALTABLE
}else if( pC->pVtabCursor ){
pVtab = pC->pVtabCursor->pVtab;
@ -4016,7 +3988,6 @@ case OP_Rowid: { /* out2-prerelease */
}else{
assert( pC->pCursor!=0 );
sqlite3BtreeKeySize(pC->pCursor, &v);
v = keyToInt(v);
}
}
pOut->u.i = v;

View File

@ -15,19 +15,11 @@
** 6000 lines long) it was split up into several smaller files and
** this header information was factored out.
**
** $Id: vdbeInt.h,v 1.172 2009/06/19 14:06:03 drh Exp $
** $Id: vdbeInt.h,v 1.173 2009/06/22 00:55:31 drh Exp $
*/
#ifndef _VDBEINT_H_
#define _VDBEINT_H_
/*
** intToKey() and keyToInt() used to transform the rowid. But with
** the latest versions of the design they are no-ops.
*/
#define keyToInt(X) (X)
#define intToKey(X) (X)
/*
** SQL is translated into a sequence of instructions to be
** executed by a virtual machine. Each instruction is an instance

View File

@ -14,7 +14,7 @@
** to version 2.8.7, all this code was combined into the vdbe.c source file.
** But that file was getting too big so this subroutines were split out.
**
** $Id: vdbeaux.c,v 1.461 2009/06/19 00:33:32 drh Exp $
** $Id: vdbeaux.c,v 1.462 2009/06/22 00:55:31 drh Exp $
*/
#include "sqliteInt.h"
#include "vdbeInt.h"
@ -2027,7 +2027,7 @@ int sqlite3VdbeCursorMoveto(VdbeCursor *p){
assert( p->isTable );
rc = sqlite3BtreeMovetoUnpacked(p->pCursor, 0, p->movetoTarget, 0, &res);
if( rc ) return rc;
p->lastRowid = keyToInt(p->movetoTarget);
p->lastRowid = p->movetoTarget;
p->rowidIsValid = ALWAYS(res==0) ?1:0;
if( NEVER(res<0) ){
rc = sqlite3BtreeNext(p->pCursor, &res);