From: drh Date: Mon, 19 Aug 2013 22:22:41 +0000 (+0000) Subject: Additional performance improvements in sqlite3BtreeNext() and X-Git-Tag: version-3.8.1~11^2~17 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=749ced9923571c73f3b965b4143bd924375e280a;p=thirdparty%2Fsqlite.git Additional performance improvements in sqlite3BtreeNext() and sqlite3BtreePrevious(). FossilOrigin-Name: 6f99b54aedeb91e46d52f65504d02a9cc61c0062 --- diff --git a/manifest b/manifest index 3a55a00463..58a5caee72 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stointeger()\sand\storeal()\sSQL\sfunctions. -D 2013-08-19T21:15:34.654 +C Additional\sperformance\simprovements\sin\ssqlite3BtreeNext()\sand\nsqlite3BtreePrevious(). +D 2013-08-19T22:22:41.690 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -163,9 +163,9 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/backup.c 43b348822db3e4cef48b2ae5a445fbeb6c73a165 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7 -F src/btree.c 78287b3012fe65fd5e38927d40c01e01a783e016 +F src/btree.c d8cb52cddfe575d91b90d056d91607259f78706b F src/btree.h bfe0e8c5759b4ec77b0d18390064a6ef3cdffaaf -F src/btreeInt.h eecc84f02375b2bb7a44abbcbbe3747dde73edb2 +F src/btreeInt.h 51cf220a9b9223354770883e93a859dc377aa27f F src/build.c f99a715ff9290996b579d5e1ec8e94239dc9ae5e F src/callback.c d7e46f40c3cf53c43550b7da7a1d0479910b62cc F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac @@ -1106,7 +1106,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P dc65ad8c4c67b21e3b042b8df6580d02b634a90b dd4b77c82af07bdcc92ed743f050e70887e5956e -R e3fb50f27097137963de60af3dbc18b8 -U mistachkin -Z 2bb7e5e3c9622cb177c0d8f0e5a92db1 +P af49707211ff7c7c4d30f4f457631ea8a9fa39eb +R d86e9a19461f588d02ed145ef81cfebb +U drh +Z 1181ebcd03ded8a6c716b64a93881e5c diff --git a/manifest.uuid b/manifest.uuid index 7dd17e4566..10a6d51396 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -af49707211ff7c7c4d30f4f457631ea8a9fa39eb \ No newline at end of file +6f99b54aedeb91e46d52f65504d02a9cc61c0062 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index bf679cd1f7..d3db676526 100644 --- a/src/btree.c +++ b/src/btree.c @@ -724,6 +724,9 @@ static int btreeRestoreCursorPosition(BtCursor *pCur){ sqlite3_free(pCur->pKey); pCur->pKey = 0; assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_INVALID ); + if( pCur->skipNext && pCur->eState==CURSOR_VALID ){ + pCur->eState = CURSOR_SKIPNEXT; + } } return rc; } @@ -749,7 +752,7 @@ int sqlite3BtreeCursorHasMoved(BtCursor *pCur, int *pHasMoved){ *pHasMoved = 1; return rc; } - if( pCur->eState!=CURSOR_VALID || pCur->skipNext!=0 ){ + if( pCur->eState!=CURSOR_VALID || NEVER(pCur->skipNext!=0) ){ *pHasMoved = 1; }else{ *pHasMoved = 0; @@ -4797,6 +4800,7 @@ int sqlite3BtreeNext(BtCursor *pCur, int *pRes){ assert( cursorHoldsMutex(pCur) ); assert( pRes!=0 ); + assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID ); if( pCur->eState!=CURSOR_VALID ){ rc = restoreCursorPosition(pCur); if( rc!=SQLITE_OK ){ @@ -4806,14 +4810,16 @@ int sqlite3BtreeNext(BtCursor *pCur, int *pRes){ *pRes = 1; return SQLITE_OK; } - } - if( pCur->skipNext ){ - if( pCur->skipNext>0 ){ + if( pCur->skipNext ){ + assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_SKIPNEXT ); + pCur->eState = CURSOR_VALID; + if( pCur->skipNext>0 ){ + pCur->skipNext = 0; + *pRes = 0; + return SQLITE_OK; + } pCur->skipNext = 0; - *pRes = 0; - return SQLITE_OK; } - pCur->skipNext = 0; } pPage = pCur->apPage[pCur->iPage]; @@ -4874,6 +4880,8 @@ int sqlite3BtreePrevious(BtCursor *pCur, int *pRes){ MemPage *pPage; assert( cursorHoldsMutex(pCur) ); + assert( pRes!=0 ); + assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID ); pCur->atLast = 0; if( pCur->eState!=CURSOR_VALID ){ if( ALWAYS(pCur->eState>=CURSOR_REQUIRESEEK) ){ @@ -4884,14 +4892,16 @@ int sqlite3BtreePrevious(BtCursor *pCur, int *pRes){ *pRes = 1; return SQLITE_OK; } - } - if( pCur->skipNext ){ - if( pCur->skipNext<0 ){ + if( pCur->skipNext ){ + assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_SKIPNEXT ); + pCur->eState = CURSOR_VALID; + if( pCur->skipNext<0 ){ + pCur->skipNext = 0; + *pRes = 0; + return SQLITE_OK; + } pCur->skipNext = 0; - *pRes = 0; - return SQLITE_OK; } - pCur->skipNext = 0; } pPage = pCur->apPage[pCur->iPage]; diff --git a/src/btreeInt.h b/src/btreeInt.h index ce3c5493f8..60da24d90c 100644 --- a/src/btreeInt.h +++ b/src/btreeInt.h @@ -520,14 +520,19 @@ struct BtCursor { /* ** Potential values for BtCursor.eState. ** -** CURSOR_VALID: -** Cursor points to a valid entry. getPayload() etc. may be called. -** ** CURSOR_INVALID: ** Cursor does not point to a valid entry. This can happen (for example) ** because the table is empty or because BtreeCursorFirst() has not been ** called. ** +** CURSOR_VALID: +** Cursor points to a valid entry. getPayload() etc. may be called. +** +** CURSOR_SKIPNEXT: +** Cursor is valid except that the Cursor.skipNext field is non-zero +** indicating that the next sqlite3BtreeNext() or sqlite3BtreePrevious() +** operation should be a no-op. +** ** CURSOR_REQUIRESEEK: ** The table that this cursor was opened on still exists, but has been ** modified since the cursor was last used. The cursor position is saved @@ -544,8 +549,9 @@ struct BtCursor { */ #define CURSOR_INVALID 0 #define CURSOR_VALID 1 -#define CURSOR_REQUIRESEEK 2 -#define CURSOR_FAULT 3 +#define CURSOR_SKIPNEXT 2 +#define CURSOR_REQUIRESEEK 3 +#define CURSOR_FAULT 4 /* ** The database page the PENDING_BYTE occupies. This page is never used.