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

Performance optimization in sqlite3BtreeCursor().

FossilOrigin-Name: ea068b099c96b8b9526114732d2a6be186cf381b7329d102778ad25b95510c9e
This commit is contained in:
drh
2019-10-25 14:46:05 +00:00
parent ef2df8f343
commit db561bceda
3 changed files with 31 additions and 18 deletions

View File

@@ -4379,9 +4379,13 @@ static int btreeCursor(
allocateTempSpace(pBt);
if( pBt->pTmpSpace==0 ) return SQLITE_NOMEM_BKPT;
}
if( iTable==1 && btreePagecount(pBt)==0 ){
assert( wrFlag==0 );
iTable = 0;
if( iTable<=1 ){
if( iTable<1 ){
return SQLITE_CORRUPT_BKPT;
}else if( btreePagecount(pBt)==0 ){
assert( wrFlag==0 );
iTable = 0;
}
}
/* Now that no other errors can occur, finish filling in the BtCursor
@@ -4406,6 +4410,19 @@ static int btreeCursor(
pCur->eState = CURSOR_INVALID;
return SQLITE_OK;
}
static int btreeCursorWithLock(
Btree *p, /* The btree */
int iTable, /* Root page of table to open */
int wrFlag, /* 1 to write. 0 read-only */
struct KeyInfo *pKeyInfo, /* First arg to comparison function */
BtCursor *pCur /* Space for new cursor */
){
int rc;
sqlite3BtreeEnter(p);
rc = btreeCursor(p, iTable, wrFlag, pKeyInfo, pCur);
sqlite3BtreeLeave(p);
return rc;
}
int sqlite3BtreeCursor(
Btree *p, /* The btree */
int iTable, /* Root page of table to open */
@@ -4413,15 +4430,11 @@ int sqlite3BtreeCursor(
struct KeyInfo *pKeyInfo, /* First arg to xCompare() */
BtCursor *pCur /* Write new cursor here */
){
int rc;
if( iTable<1 ){
rc = SQLITE_CORRUPT_BKPT;
if( p->sharable ){
return btreeCursorWithLock(p, iTable, wrFlag, pKeyInfo, pCur);
}else{
sqlite3BtreeEnter(p);
rc = btreeCursor(p, iTable, wrFlag, pKeyInfo, pCur);
sqlite3BtreeLeave(p);
return btreeCursor(p, iTable, wrFlag, pKeyInfo, pCur);
}
return rc;
}
/*