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

Optimizations associated with error handling in btree cursors.

FossilOrigin-Name: 49ba54e26731ed371745d4bdd9dd1dfeb73357b6d206c85a4252ec866be971d0
This commit is contained in:
drh
2017-08-02 15:50:09 +00:00
parent 57498ae9cf
commit 85ef630fde
3 changed files with 21 additions and 23 deletions

View File

@@ -731,7 +731,7 @@ static int SQLITE_NOINLINE saveCursorsOnList(
return rc;
}
}else{
testcase( p->iPage>0 );
testcase( p->iPage>=0 );
btreeReleaseAllCursorPages(p);
}
}
@@ -3981,7 +3981,6 @@ int sqlite3BtreeTripAllCursors(Btree *pBtree, int errCode, int writeOnly){
if( pBtree ){
sqlite3BtreeEnter(pBtree);
for(p=pBtree->pBt->pCursor; p; p=p->pNext){
int i;
if( writeOnly && (p->curFlags & BTCF_WriteFlag)==0 ){
if( p->eState==CURSOR_VALID || p->eState==CURSOR_SKIPNEXT ){
rc = saveCursorPosition(p);
@@ -3995,10 +3994,7 @@ int sqlite3BtreeTripAllCursors(Btree *pBtree, int errCode, int writeOnly){
p->eState = CURSOR_FAULT;
p->skipNext = errCode;
}
for(i=0; i<=p->iPage; i++){
releasePage(p->apPage[i]);
p->apPage[i] = 0;
}
btreeReleaseAllCursorPages(p);
}
sqlite3BtreeLeave(pBtree);
}
@@ -4315,7 +4311,7 @@ int sqlite3BtreeCloseCursor(BtCursor *pCur){
}while( ALWAYS(pPrev) );
}
for(i=0; i<=pCur->iPage; i++){
releasePage(pCur->apPage[i]);
releasePageNotNull(pCur->apPage[i]);
}
unlockBtreeIfUnused(pBt);
sqlite3_free(pCur->aOverflow);
@@ -4938,13 +4934,7 @@ static int moveToRoot(BtCursor *pCur){
assert( CURSOR_INVALID < CURSOR_REQUIRESEEK );
assert( CURSOR_VALID < CURSOR_REQUIRESEEK );
assert( CURSOR_FAULT > CURSOR_REQUIRESEEK );
if( pCur->eState>=CURSOR_REQUIRESEEK ){
if( pCur->eState==CURSOR_FAULT ){
assert( pCur->skipNext!=SQLITE_OK );
return pCur->skipNext;
}
sqlite3BtreeClearCursor(pCur);
}
assert( pCur->eState < CURSOR_REQUIRESEEK || pCur->iPage<0 );
if( pCur->iPage>=0 ){
if( pCur->iPage ){
@@ -4959,6 +4949,13 @@ static int moveToRoot(BtCursor *pCur){
return SQLITE_OK;
}else{
assert( pCur->iPage==(-1) );
if( pCur->eState>=CURSOR_REQUIRESEEK ){
if( pCur->eState==CURSOR_FAULT ){
assert( pCur->skipNext!=SQLITE_OK );
return pCur->skipNext;
}
sqlite3BtreeClearCursor(pCur);
}
rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->apPage[0],
0, pCur->curPagerFlags);
if( rc!=SQLITE_OK ){
@@ -8254,7 +8251,7 @@ int sqlite3BtreeInsert(
pCur->apPage[pCur->iPage]->nOverflow = 0;
pCur->eState = CURSOR_INVALID;
if( (flags & BTREE_SAVEPOSITION) && rc==SQLITE_OK ){
rc = moveToRoot(pCur);
btreeReleaseAllCursorPages(pCur);
if( pCur->pKeyInfo ){
assert( pCur->pKey==0 );
pCur->pKey = sqlite3Malloc( pX->nKey );
@@ -8268,7 +8265,7 @@ int sqlite3BtreeInsert(
pCur->nKey = pX->nKey;
}
}
assert( pCur->apPage[pCur->iPage]->nOverflow==0 );
assert( pCur->iPage<0 || pCur->apPage[pCur->iPage]->nOverflow==0 );
end_insert:
return rc;
@@ -8438,6 +8435,7 @@ int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
}else{
rc = moveToRoot(pCur);
if( bPreserve ){
btreeReleaseAllCursorPages(pCur);
pCur->eState = CURSOR_REQUIRESEEK;
}
}