Remove the "rowid cache" that sought to remember the largest rowid for a
table and thereby speed up OP_NewRowid. That cache was ineffective. Removing it results in a performance increase of 0.4%, less memory usage, and a slightly smaller library size. FossilOrigin-Name: 56bc5ce8958c8e6250531b4052b905d7ac993db3
This commit is contained in:
parent
784156f84c
commit
e0670b6220
18
manifest
18
manifest
@ -1,5 +1,5 @@
|
||||
C Make\ssure\s"rowid"\scolumns\sare\scorrectly\sresolved\sin\sjoins\sbetween\snormal\ntables\sand\sWITHOUT\sROWID\stables.\s\sFix\sfor\sticket\s[c34d0557f740c45070].
|
||||
D 2014-02-12T14:43:52.953
|
||||
C Remove\sthe\s"rowid\scache"\sthat\ssought\sto\sremember\sthe\slargest\srowid\sfor\sa\ntable\sand\sthereby\sspeed\sup\sOP_NewRowid.\s\sThat\scache\swas\sineffective.\nRemoving\sit\sresults\sin\sa\sperformance\sincrease\sof\s0.4%,\sless\smemory\susage,\nand\sa\sslightly\ssmaller\slibrary\ssize.
|
||||
D 2014-02-12T21:31:12.616
|
||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||
F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81
|
||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||
@ -166,9 +166,9 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34
|
||||
F src/backup.c a729e63cf5cd1829507cb7b8e89f99b95141bb53
|
||||
F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb
|
||||
F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7
|
||||
F src/btree.c 7b2c3cd16deedff7f4904f2e871e7b77328b9872
|
||||
F src/btree.h a61ddebc78c66795a2b93181321a116746302cc9
|
||||
F src/btreeInt.h f038e818bfadf75afbd09819ed93c26a333d39e0
|
||||
F src/btree.c 97020a77cb53fb9d8e7f172d489b8f92af1d1b82
|
||||
F src/btree.h 9e0f97c01b972f779eb7655cfb4f8727fd6dc26f
|
||||
F src/btreeInt.h 0be66063468a520e4d66b80c7a1dc26d04ee6ea4
|
||||
F src/build.c 13b9d82181d95af7b00ec8a8e1304bac096432d4
|
||||
F src/callback.c 174e3c8656bc29f91d710ab61550d16eea34be98
|
||||
F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
|
||||
@ -280,7 +280,7 @@ F src/update.c a7df6fffce6bfedc578fda6136dd33e34a63f8ee
|
||||
F src/utf.c 6fc6c88d50448c469c5c196acf21617a24f90269
|
||||
F src/util.c c46c90459ef9bdc0c6c73803cf4c55425b4771cf
|
||||
F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179
|
||||
F src/vdbe.c e5c87476d717aebef5dafceab11417ebf2730554
|
||||
F src/vdbe.c 3f0872b12ec3fc24ee540f8bb09de181ddad6d8d
|
||||
F src/vdbe.h e6c4c610fcabad4fa80ebb1efc6822a9367e2b26
|
||||
F src/vdbeInt.h 5286af9067cabdb8ba57b87c0c988a931be6c6c8
|
||||
F src/vdbeapi.c 5bc41aaea448a7fc250902c418f1795859be3820
|
||||
@ -1153,7 +1153,7 @@ F tool/vdbe-compress.tcl 0cf56e9263a152b84da86e75a5c0cdcdb7a47891
|
||||
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
||||
F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
|
||||
F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
|
||||
P 0a8bcbbd4e11a60923736b2be9b1ce83ea2263fb
|
||||
R ece7306a4645e7a68a79bfe14ec94970
|
||||
P 5d01426ddfb2d47c57f93f71378594e637424be0
|
||||
R 0f58210f2a6ea71dc58155d3b9fc47e4
|
||||
U drh
|
||||
Z 89db972fa80a38407f6b56a44d53bf78
|
||||
Z 0cd8ad70eddd970bc8638e6270cc29ff
|
||||
|
@ -1 +1 @@
|
||||
5d01426ddfb2d47c57f93f71378594e637424be0
|
||||
56bc5ce8958c8e6250531b4052b905d7ac993db3
|
45
src/btree.c
45
src/btree.c
@ -3632,7 +3632,6 @@ static int btreeCursor(
|
||||
}
|
||||
pBt->pCursor = pCur;
|
||||
pCur->eState = CURSOR_INVALID;
|
||||
pCur->cachedRowid = 0;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
int sqlite3BtreeCursor(
|
||||
@ -3673,36 +3672,6 @@ void sqlite3BtreeCursorZero(BtCursor *p){
|
||||
memset(p, 0, offsetof(BtCursor, iPage));
|
||||
}
|
||||
|
||||
/*
|
||||
** Set the cached rowid value of every cursor in the same database file
|
||||
** as pCur and having the same root page number as pCur. The value is
|
||||
** set to iRowid.
|
||||
**
|
||||
** Only positive rowid values are considered valid for this cache.
|
||||
** The cache is initialized to zero, indicating an invalid cache.
|
||||
** A btree will work fine with zero or negative rowids. We just cannot
|
||||
** cache zero or negative rowids, which means tables that use zero or
|
||||
** negative rowids might run a little slower. But in practice, zero
|
||||
** or negative rowids are very uncommon so this should not be a problem.
|
||||
*/
|
||||
void sqlite3BtreeSetCachedRowid(BtCursor *pCur, sqlite3_int64 iRowid){
|
||||
BtCursor *p;
|
||||
for(p=pCur->pBt->pCursor; p; p=p->pNext){
|
||||
if( p->pgnoRoot==pCur->pgnoRoot ) p->cachedRowid = iRowid;
|
||||
}
|
||||
assert( pCur->cachedRowid==iRowid );
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the cached rowid for the given cursor. A negative or zero
|
||||
** return value indicates that the rowid cache is invalid and should be
|
||||
** ignored. If the rowid cache has never before been set, then a
|
||||
** zero is returned.
|
||||
*/
|
||||
sqlite3_int64 sqlite3BtreeGetCachedRowid(BtCursor *pCur){
|
||||
return pCur->cachedRowid;
|
||||
}
|
||||
|
||||
/*
|
||||
** Close a cursor. The read lock on the database file is released
|
||||
** when the last cursor is closed.
|
||||
@ -6986,11 +6955,17 @@ int sqlite3BtreeInsert(
|
||||
rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
|
||||
if( rc ) return rc;
|
||||
|
||||
/* If this is an insert into a table b-tree, invalidate any incrblob
|
||||
** cursors open on the row being replaced (assuming this is a replace
|
||||
** operation - if it is not, the following is a no-op). */
|
||||
if( pCur->pKeyInfo==0 ){
|
||||
/* If this is an insert into a table b-tree, invalidate any incrblob
|
||||
** cursors open on the row being replaced */
|
||||
invalidateIncrblobCursors(p, nKey, 0);
|
||||
|
||||
/* If the cursor is currently on the last row and we are appending a
|
||||
** new row onto the end, set the "loc" to avoid an unnecessary btreeMoveto()
|
||||
** call */
|
||||
if( pCur->validNKey && nKey>0 && pCur->info.nKey==nKey-1 ){
|
||||
loc = -1;
|
||||
}
|
||||
}
|
||||
|
||||
if( !loc ){
|
||||
@ -7060,8 +7035,8 @@ int sqlite3BtreeInsert(
|
||||
** row without seeking the cursor. This can be a big performance boost.
|
||||
*/
|
||||
pCur->info.nSize = 0;
|
||||
pCur->validNKey = 0;
|
||||
if( rc==SQLITE_OK && pPage->nOverflow ){
|
||||
pCur->validNKey = 0;
|
||||
rc = balance(pCur);
|
||||
|
||||
/* Must make sure nOverflow is reset to zero even if the balance()
|
||||
|
@ -182,8 +182,6 @@ const void *sqlite3BtreeKeyFetch(BtCursor*, u32 *pAmt);
|
||||
const void *sqlite3BtreeDataFetch(BtCursor*, u32 *pAmt);
|
||||
int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
|
||||
int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
|
||||
void sqlite3BtreeSetCachedRowid(BtCursor*, sqlite3_int64);
|
||||
sqlite3_int64 sqlite3BtreeGetCachedRowid(BtCursor*);
|
||||
|
||||
char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
|
||||
struct Pager *sqlite3BtreePager(Btree*);
|
||||
|
@ -500,7 +500,6 @@ struct BtCursor {
|
||||
Pgno *aOverflow; /* Cache of overflow page locations */
|
||||
#endif
|
||||
Pgno pgnoRoot; /* The root page of this tree */
|
||||
sqlite3_int64 cachedRowid; /* Next rowid cache. 0 means not valid */
|
||||
CellInfo info; /* A parse of the cell we are pointing at */
|
||||
i64 nKey; /* Size of pKey, or last integer key */
|
||||
void *pKey; /* Saved key that was cursor's last known position */
|
||||
|
85
src/vdbe.c
85
src/vdbe.c
@ -3834,59 +3834,54 @@ case OP_NewRowid: { /* out2-prerelease */
|
||||
#endif
|
||||
|
||||
if( !pC->useRandomRowid ){
|
||||
v = sqlite3BtreeGetCachedRowid(pC->pCursor);
|
||||
if( v==0 ){
|
||||
rc = sqlite3BtreeLast(pC->pCursor, &res);
|
||||
if( rc!=SQLITE_OK ){
|
||||
goto abort_due_to_error;
|
||||
}
|
||||
if( res ){
|
||||
v = 1; /* IMP: R-61914-48074 */
|
||||
rc = sqlite3BtreeLast(pC->pCursor, &res);
|
||||
if( rc!=SQLITE_OK ){
|
||||
goto abort_due_to_error;
|
||||
}
|
||||
if( res ){
|
||||
v = 1; /* IMP: R-61914-48074 */
|
||||
}else{
|
||||
assert( sqlite3BtreeCursorIsValid(pC->pCursor) );
|
||||
rc = sqlite3BtreeKeySize(pC->pCursor, &v);
|
||||
assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */
|
||||
if( v>=MAX_ROWID ){
|
||||
pC->useRandomRowid = 1;
|
||||
}else{
|
||||
assert( sqlite3BtreeCursorIsValid(pC->pCursor) );
|
||||
rc = sqlite3BtreeKeySize(pC->pCursor, &v);
|
||||
assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */
|
||||
if( v>=MAX_ROWID ){
|
||||
pC->useRandomRowid = 1;
|
||||
}else{
|
||||
v++; /* IMP: R-29538-34987 */
|
||||
}
|
||||
v++; /* IMP: R-29538-34987 */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTOINCREMENT
|
||||
if( pOp->p3 ){
|
||||
if( pOp->p3 ){
|
||||
/* Assert that P3 is a valid memory cell. */
|
||||
assert( pOp->p3>0 );
|
||||
if( p->pFrame ){
|
||||
for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
|
||||
/* Assert that P3 is a valid memory cell. */
|
||||
assert( pOp->p3>0 );
|
||||
if( p->pFrame ){
|
||||
for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
|
||||
/* Assert that P3 is a valid memory cell. */
|
||||
assert( pOp->p3<=pFrame->nMem );
|
||||
pMem = &pFrame->aMem[pOp->p3];
|
||||
}else{
|
||||
/* Assert that P3 is a valid memory cell. */
|
||||
assert( pOp->p3<=(p->nMem-p->nCursor) );
|
||||
pMem = &aMem[pOp->p3];
|
||||
memAboutToChange(p, pMem);
|
||||
}
|
||||
assert( memIsValid(pMem) );
|
||||
|
||||
REGISTER_TRACE(pOp->p3, pMem);
|
||||
sqlite3VdbeMemIntegerify(pMem);
|
||||
assert( (pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */
|
||||
if( pMem->u.i==MAX_ROWID || pC->useRandomRowid ){
|
||||
rc = SQLITE_FULL; /* IMP: R-12275-61338 */
|
||||
goto abort_due_to_error;
|
||||
}
|
||||
if( v<pMem->u.i+1 ){
|
||||
v = pMem->u.i + 1;
|
||||
}
|
||||
pMem->u.i = v;
|
||||
assert( pOp->p3<=pFrame->nMem );
|
||||
pMem = &pFrame->aMem[pOp->p3];
|
||||
}else{
|
||||
/* Assert that P3 is a valid memory cell. */
|
||||
assert( pOp->p3<=(p->nMem-p->nCursor) );
|
||||
pMem = &aMem[pOp->p3];
|
||||
memAboutToChange(p, pMem);
|
||||
}
|
||||
#endif
|
||||
assert( memIsValid(pMem) );
|
||||
|
||||
sqlite3BtreeSetCachedRowid(pC->pCursor, v<MAX_ROWID ? v+1 : 0);
|
||||
REGISTER_TRACE(pOp->p3, pMem);
|
||||
sqlite3VdbeMemIntegerify(pMem);
|
||||
assert( (pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */
|
||||
if( pMem->u.i==MAX_ROWID || pC->useRandomRowid ){
|
||||
rc = SQLITE_FULL; /* IMP: R-12275-61338 */
|
||||
goto abort_due_to_error;
|
||||
}
|
||||
if( v<pMem->u.i+1 ){
|
||||
v = pMem->u.i + 1;
|
||||
}
|
||||
pMem->u.i = v;
|
||||
}
|
||||
#endif
|
||||
if( pC->useRandomRowid ){
|
||||
/* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the
|
||||
** largest possible integer (9223372036854775807) then the database
|
||||
@ -4020,7 +4015,6 @@ case OP_InsertInt: {
|
||||
}else{
|
||||
nZero = 0;
|
||||
}
|
||||
sqlite3BtreeSetCachedRowid(pC->pCursor, 0);
|
||||
rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey,
|
||||
pData->z, pData->n, nZero,
|
||||
(pOp->p5 & OPFLAG_APPEND)!=0, seekResult
|
||||
@ -4082,7 +4076,6 @@ case OP_Delete: {
|
||||
rc = sqlite3VdbeCursorMoveto(pC);
|
||||
if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
|
||||
|
||||
sqlite3BtreeSetCachedRowid(pC->pCursor, 0);
|
||||
rc = sqlite3BtreeDelete(pC->pCursor);
|
||||
pC->cacheStatus = CACHE_STALE;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user