mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-10 01:02:56 +03:00
Performance improvements in moveToChild() by shifting some work over
to getAndInitPage(). Net improvement is about 800K cycles at cost of 30 bytes. FossilOrigin-Name: 1956a4ce8eca650d98a7f68fd2d82eb8a3d6069f
This commit is contained in:
14
manifest
14
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Manually\sinline\sthe\scall\sfrom\sgetAndInitPage()\sto\sbtreeGetPage()\sfor\sa\nsavings\sof\s2.5\smillion\scycles\sat\sa\scost\sof\sless\sthan\s100\sbytes.
|
C Performance\simprovements\sin\smoveToChild()\sby\sshifting\ssome\swork\sover\nto\sgetAndInitPage().\s\sNet\simprovement\sis\sabout\s800K\scycles\sat\scost\sof\s30\sbytes.
|
||||||
D 2015-06-27T15:51:06.913
|
D 2015-06-27T19:45:03.070
|
||||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||||
F Makefile.in 285a0a234ed7610d431d91671c136098c2bd86a9
|
F Makefile.in 285a0a234ed7610d431d91671c136098c2bd86a9
|
||||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||||
@@ -269,9 +269,9 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240
|
|||||||
F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3
|
F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3
|
||||||
F src/bitvec.c 5eb7958c3bf65210211cbcfc44eff86d0ded7c9d
|
F src/bitvec.c 5eb7958c3bf65210211cbcfc44eff86d0ded7c9d
|
||||||
F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79
|
F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79
|
||||||
F src/btree.c be03b25d28cf714e81a825e60f7abcd8825e9b4e
|
F src/btree.c b1ba9f65eba193ecae9519be29cce63bc1daef4c
|
||||||
F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1
|
F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1
|
||||||
F src/btreeInt.h 426d1e0d1a15d06b3ad2304f4bedc5bb71e5b4a2
|
F src/btreeInt.h 30f611b87ff873f47a28ce0bf66dd778c3274d9a
|
||||||
F src/build.c b3f15255d5b16e42dafeaa638fd4f8a47c94ed70
|
F src/build.c b3f15255d5b16e42dafeaa638fd4f8a47c94ed70
|
||||||
F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0
|
F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0
|
||||||
F src/complete.c a5cf5b4b56390cfb7b8636e8f7ddef90258dd575
|
F src/complete.c a5cf5b4b56390cfb7b8636e8f7ddef90258dd575
|
||||||
@@ -1364,7 +1364,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
|
|||||||
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
||||||
F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
|
F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
|
||||||
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
|
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
|
||||||
P 9383a688701ac2c366a308efc287c9c0f8977d4e
|
P 7f65b96b4017413bd19624570efe8fb2b0f7b991
|
||||||
R 16848ebaab74906a500d4e5002f1b1ec
|
R 4df1944eb9c633cad9fdc689344e2d7e
|
||||||
U drh
|
U drh
|
||||||
Z a8b43d2118aa53b4955ba2ebec95dffb
|
Z 093d236679649777c7df295c5a4c84ba
|
||||||
|
@@ -1 +1 @@
|
|||||||
7f65b96b4017413bd19624570efe8fb2b0f7b991
|
1956a4ce8eca650d98a7f68fd2d82eb8a3d6069f
|
82
src/btree.c
82
src/btree.c
@@ -1909,40 +1909,63 @@ u32 sqlite3BtreeLastPage(Btree *p){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Get a page from the pager and initialize it. This routine is just a
|
** Get a page from the pager and initialize it.
|
||||||
** convenience wrapper around separate calls to btreeGetPage() and
|
|
||||||
** btreeInitPage().
|
|
||||||
**
|
**
|
||||||
** If an error occurs, then the value *ppPage is set to is undefined. It
|
** If pCur!=0 then the page acquired will be added to that cursor.
|
||||||
|
** If the fetch fails, this routine must decrement pCur->iPage.
|
||||||
|
**
|
||||||
|
** The page is fetched as read-write unless pCur is not NULL and is
|
||||||
|
** a read-only cursor.
|
||||||
|
**
|
||||||
|
** If an error occurs, then *ppPage is undefined. It
|
||||||
** may remain unchanged, or it may be set to an invalid value.
|
** may remain unchanged, or it may be set to an invalid value.
|
||||||
*/
|
*/
|
||||||
static int getAndInitPage(
|
static int getAndInitPage(
|
||||||
BtShared *pBt, /* The database file */
|
BtShared *pBt, /* The database file */
|
||||||
Pgno pgno, /* Number of the page to get */
|
Pgno pgno, /* Number of the page to get */
|
||||||
MemPage **ppPage, /* Write the page pointer here */
|
MemPage **ppPage, /* Write the page pointer here */
|
||||||
int bReadonly /* PAGER_GET_READONLY or 0 */
|
BtCursor *pCur, /* Cursor to receive the page, or NULL */
|
||||||
|
int bReadOnly /* True for a read-only page */
|
||||||
){
|
){
|
||||||
int rc;
|
int rc;
|
||||||
|
DbPage *pDbPage;
|
||||||
assert( sqlite3_mutex_held(pBt->mutex) );
|
assert( sqlite3_mutex_held(pBt->mutex) );
|
||||||
assert( bReadonly==PAGER_GET_READONLY || bReadonly==0 );
|
assert( pCur==0 || ppPage==&pCur->apPage[pCur->iPage] );
|
||||||
|
assert( pCur==0 || bReadOnly==pCur->curPagerFlags );
|
||||||
|
|
||||||
if( pgno>btreePagecount(pBt) ){
|
if( pgno>btreePagecount(pBt) ){
|
||||||
rc = SQLITE_CORRUPT_BKPT;
|
rc = SQLITE_CORRUPT_BKPT;
|
||||||
}else{
|
goto getAndInitPage_error;
|
||||||
DbPage *pDbPage;
|
}
|
||||||
rc = sqlite3PagerAcquire(pBt->pPager, pgno, (DbPage**)&pDbPage, bReadonly);
|
rc = sqlite3PagerAcquire(pBt->pPager, pgno, (DbPage**)&pDbPage, bReadOnly);
|
||||||
if( rc ) return rc;
|
if( rc ){
|
||||||
*ppPage = btreePageFromDbPage(pDbPage, pgno, pBt);
|
goto getAndInitPage_error;
|
||||||
if( (*ppPage)->isInit==0 ){
|
}
|
||||||
rc = btreeInitPage(*ppPage);
|
*ppPage = btreePageFromDbPage(pDbPage, pgno, pBt);
|
||||||
if( rc!=SQLITE_OK ){
|
if( (*ppPage)->isInit==0 ){
|
||||||
releasePage(*ppPage);
|
rc = btreeInitPage(*ppPage);
|
||||||
}
|
if( rc!=SQLITE_OK ){
|
||||||
|
releasePage(*ppPage);
|
||||||
|
goto getAndInitPage_error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If obtaining a page for a cursor, we must verify that the page is
|
||||||
|
** compatible with the cursor */
|
||||||
|
if( pCur && pCur->iPage>0
|
||||||
|
&& ((*ppPage)->nCell<1 || (*ppPage)->intKey!=pCur->apPage[0]->intKey)
|
||||||
|
){
|
||||||
|
rc = SQLITE_CORRUPT_BKPT;
|
||||||
|
releasePage(*ppPage);
|
||||||
|
goto getAndInitPage_error;
|
||||||
|
}
|
||||||
|
|
||||||
testcase( pgno==0 );
|
testcase( pgno==0 );
|
||||||
assert( pgno!=0 || rc==SQLITE_CORRUPT );
|
assert( pgno!=0 || rc==SQLITE_CORRUPT );
|
||||||
|
return SQLITE_OK;
|
||||||
|
|
||||||
|
getAndInitPage_error:
|
||||||
|
if( pCur ) pCur->iPage--;
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4028,6 +4051,7 @@ static int btreeCursor(
|
|||||||
pCur->pBt = pBt;
|
pCur->pBt = pBt;
|
||||||
assert( wrFlag==0 || wrFlag==BTCF_WriteFlag );
|
assert( wrFlag==0 || wrFlag==BTCF_WriteFlag );
|
||||||
pCur->curFlags = wrFlag;
|
pCur->curFlags = wrFlag;
|
||||||
|
pCur->curPagerFlags = wrFlag ? 0 : PAGER_GET_READONLY;
|
||||||
pCur->pNext = pBt->pCursor;
|
pCur->pNext = pBt->pCursor;
|
||||||
if( pCur->pNext ){
|
if( pCur->pNext ){
|
||||||
pCur->pNext->pPrev = pCur;
|
pCur->pNext->pPrev = pCur;
|
||||||
@@ -4641,9 +4665,6 @@ const void *sqlite3BtreeDataFetch(BtCursor *pCur, u32 *pAmt){
|
|||||||
** vice-versa).
|
** vice-versa).
|
||||||
*/
|
*/
|
||||||
static int moveToChild(BtCursor *pCur, u32 newPgno){
|
static int moveToChild(BtCursor *pCur, u32 newPgno){
|
||||||
int rc;
|
|
||||||
int i = pCur->iPage;
|
|
||||||
MemPage *pNewPage;
|
|
||||||
BtShared *pBt = pCur->pBt;
|
BtShared *pBt = pCur->pBt;
|
||||||
|
|
||||||
assert( cursorHoldsMutex(pCur) );
|
assert( cursorHoldsMutex(pCur) );
|
||||||
@@ -4653,19 +4674,12 @@ static int moveToChild(BtCursor *pCur, u32 newPgno){
|
|||||||
if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
|
if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
|
||||||
return SQLITE_CORRUPT_BKPT;
|
return SQLITE_CORRUPT_BKPT;
|
||||||
}
|
}
|
||||||
rc = getAndInitPage(pBt, newPgno, &pNewPage,
|
|
||||||
(pCur->curFlags & BTCF_WriteFlag)==0 ? PAGER_GET_READONLY : 0);
|
|
||||||
if( rc ) return rc;
|
|
||||||
pCur->apPage[i+1] = pNewPage;
|
|
||||||
pCur->aiIdx[i+1] = 0;
|
|
||||||
pCur->iPage++;
|
|
||||||
|
|
||||||
pCur->info.nSize = 0;
|
pCur->info.nSize = 0;
|
||||||
pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
|
pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
|
||||||
if( pNewPage->nCell<1 || pNewPage->intKey!=pCur->apPage[i]->intKey ){
|
pCur->iPage++;
|
||||||
return SQLITE_CORRUPT_BKPT;
|
pCur->aiIdx[pCur->iPage] = 0;
|
||||||
}
|
return getAndInitPage(pBt, newPgno, &pCur->apPage[pCur->iPage],
|
||||||
return SQLITE_OK;
|
pCur, pCur->curPagerFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SQLITE_DEBUG
|
#if SQLITE_DEBUG
|
||||||
@@ -4760,8 +4774,10 @@ static int moveToRoot(BtCursor *pCur){
|
|||||||
pCur->eState = CURSOR_INVALID;
|
pCur->eState = CURSOR_INVALID;
|
||||||
return SQLITE_OK;
|
return SQLITE_OK;
|
||||||
}else{
|
}else{
|
||||||
|
assert( pCur->iPage==(-1) );
|
||||||
|
pCur->iPage = 0;
|
||||||
rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->apPage[0],
|
rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->apPage[0],
|
||||||
(pCur->curFlags & BTCF_WriteFlag)==0 ? PAGER_GET_READONLY : 0);
|
pCur, pCur->curPagerFlags);
|
||||||
if( rc!=SQLITE_OK ){
|
if( rc!=SQLITE_OK ){
|
||||||
pCur->eState = CURSOR_INVALID;
|
pCur->eState = CURSOR_INVALID;
|
||||||
return rc;
|
return rc;
|
||||||
@@ -6963,7 +6979,7 @@ static int balance_nonroot(
|
|||||||
}
|
}
|
||||||
pgno = get4byte(pRight);
|
pgno = get4byte(pRight);
|
||||||
while( 1 ){
|
while( 1 ){
|
||||||
rc = getAndInitPage(pBt, pgno, &apOld[i], 0);
|
rc = getAndInitPage(pBt, pgno, &apOld[i], 0, 0);
|
||||||
if( rc ){
|
if( rc ){
|
||||||
memset(apOld, 0, (i+1)*sizeof(MemPage*));
|
memset(apOld, 0, (i+1)*sizeof(MemPage*));
|
||||||
goto balance_cleanup;
|
goto balance_cleanup;
|
||||||
@@ -8280,7 +8296,7 @@ static int clearDatabasePage(
|
|||||||
if( pgno>btreePagecount(pBt) ){
|
if( pgno>btreePagecount(pBt) ){
|
||||||
return SQLITE_CORRUPT_BKPT;
|
return SQLITE_CORRUPT_BKPT;
|
||||||
}
|
}
|
||||||
rc = getAndInitPage(pBt, pgno, &pPage, 0);
|
rc = getAndInitPage(pBt, pgno, &pPage, 0, 0);
|
||||||
if( rc ) return rc;
|
if( rc ) return rc;
|
||||||
if( pPage->bBusy ){
|
if( pPage->bBusy ){
|
||||||
rc = SQLITE_CORRUPT_BKPT;
|
rc = SQLITE_CORRUPT_BKPT;
|
||||||
|
@@ -518,6 +518,7 @@ struct BtCursor {
|
|||||||
int skipNext; /* Prev() is noop if negative. Next() is noop if positive.
|
int skipNext; /* Prev() is noop if negative. Next() is noop if positive.
|
||||||
** Error code if eState==CURSOR_FAULT */
|
** Error code if eState==CURSOR_FAULT */
|
||||||
u8 curFlags; /* zero or more BTCF_* flags defined below */
|
u8 curFlags; /* zero or more BTCF_* flags defined below */
|
||||||
|
u8 curPagerFlags; /* Flags to send to sqlite3PagerAcquire() */
|
||||||
u8 eState; /* One of the CURSOR_XXX constants (see below) */
|
u8 eState; /* One of the CURSOR_XXX constants (see below) */
|
||||||
u8 hints; /* As configured by CursorSetHints() */
|
u8 hints; /* As configured by CursorSetHints() */
|
||||||
i16 iPage; /* Index of current page in apPage */
|
i16 iPage; /* Index of current page in apPage */
|
||||||
|
Reference in New Issue
Block a user