mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-10 01:02:56 +03:00
Simplification to the getAndInitPage() routine that results in improved
performance. FossilOrigin-Name: 2e9734c2335d8c06fedc9f4cca02baaf326f7fa276bd464f3214f383715a48d6
This commit is contained in:
12
manifest
12
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Improved\scomment\son\sthe\sgetAndInitPage()\sin\sbtree.c.\s\sNo\scode\schanges.
|
C Simplification\sto\sthe\sgetAndInitPage()\sroutine\sthat\sresults\sin\simproved\nperformance.
|
||||||
D 2023-06-21T21:47:09.597
|
D 2023-06-22T01:03:39.798
|
||||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||||
@@ -576,7 +576,7 @@ F src/auth.c 19b7ccacae3dfba23fc6f1d0af68134fa216e9040e53b0681b4715445ea030b4
|
|||||||
F src/backup.c 5c97e8023aab1ce14a42387eb3ae00ba5a0644569e3476f38661fa6f824c3523
|
F src/backup.c 5c97e8023aab1ce14a42387eb3ae00ba5a0644569e3476f38661fa6f824c3523
|
||||||
F src/bitvec.c 9eac5f42c11914d5ef00a75605bb205e934f435c579687f985f1f8b0995c8645
|
F src/bitvec.c 9eac5f42c11914d5ef00a75605bb205e934f435c579687f985f1f8b0995c8645
|
||||||
F src/btmutex.c 79a43670447eacc651519a429f6ece9fd638563cf95b469d6891185ddae2b522
|
F src/btmutex.c 79a43670447eacc651519a429f6ece9fd638563cf95b469d6891185ddae2b522
|
||||||
F src/btree.c 2ae7a720dc7af3327663ca5a1a4f4131301d040ef6058e1fb2fd5a7c743148d8
|
F src/btree.c c0c93b6cb4dc133b528c1290bb4ad0f2414452f9a5758ff2b106af718874f39e
|
||||||
F src/btree.h aa354b9bad4120af71e214666b35132712b8f2ec11869cb2315c52c81fad45cc
|
F src/btree.h aa354b9bad4120af71e214666b35132712b8f2ec11869cb2315c52c81fad45cc
|
||||||
F src/btreeInt.h 3b4eff7155c0cea6971dc51f62e3529934a15a6640ec607dd42a767e379cb3a9
|
F src/btreeInt.h 3b4eff7155c0cea6971dc51f62e3529934a15a6640ec607dd42a767e379cb3a9
|
||||||
F src/build.c a8ae3b32d9aa9bbd2c0e97d7c0dd80def9fbca408425de1608f57ee6f47f45f4
|
F src/build.c a8ae3b32d9aa9bbd2c0e97d7c0dd80def9fbca408425de1608f57ee6f47f45f4
|
||||||
@@ -2041,8 +2041,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
|||||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||||
P 61dfa92b44ad38a7aac76a09e167819ce5d0acace3e06ba9ed17b3264cc043c1
|
P dc468cfdb825083b3a4b6cb95c913961e9312e22103c5a0cd923b75c83c65e13
|
||||||
R 8109896f8dcaf1ac50fc102421edb592
|
R 61e892d0fc1ac1905da44ab1762c00e7
|
||||||
U drh
|
U drh
|
||||||
Z ee9fa6c5886a3987a472fa73645af4d3
|
Z c0e995c2a64328b6123221956a5cefda
|
||||||
# Remove this line to create a well-formed Fossil manifest.
|
# Remove this line to create a well-formed Fossil manifest.
|
||||||
|
@@ -1 +1 @@
|
|||||||
dc468cfdb825083b3a4b6cb95c913961e9312e22103c5a0cd923b75c83c65e13
|
2e9734c2335d8c06fedc9f4cca02baaf326f7fa276bd464f3214f383715a48d6
|
110
src/btree.c
110
src/btree.c
@@ -2318,69 +2318,41 @@ Pgno sqlite3BtreeLastPage(Btree *p){
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
** Get a page from the pager and initialize it.
|
** Get a page from the pager and initialize it.
|
||||||
**
|
|
||||||
** If pCur!=0 then the page is being fetched as part of a moveToChild()
|
|
||||||
** call. Do additional sanity checking on the page in this case.
|
|
||||||
** And if that additional sanity checking fails, adjust the state of
|
|
||||||
** the cursor so that the fetch is effectively "undone".
|
|
||||||
**
|
|
||||||
** 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.
|
|
||||||
*/
|
*/
|
||||||
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 */
|
||||||
BtCursor *pCur, /* Cursor to receive the page, or NULL */
|
|
||||||
int bReadOnly /* True for a read-only page */
|
int bReadOnly /* True for a read-only page */
|
||||||
){
|
){
|
||||||
int rc;
|
int rc;
|
||||||
DbPage *pDbPage;
|
DbPage *pDbPage;
|
||||||
|
MemPage *pPage;
|
||||||
assert( sqlite3_mutex_held(pBt->mutex) );
|
assert( sqlite3_mutex_held(pBt->mutex) );
|
||||||
assert( pCur==0 || ppPage==&pCur->pPage );
|
|
||||||
assert( pCur==0 || bReadOnly==pCur->curPagerFlags );
|
|
||||||
assert( pCur==0 || pCur->iPage>0 );
|
|
||||||
|
|
||||||
if( pgno>btreePagecount(pBt) ){
|
if( pgno>btreePagecount(pBt) ){
|
||||||
rc = SQLITE_CORRUPT_BKPT;
|
*ppPage = 0;
|
||||||
goto getAndInitPage_error1;
|
return SQLITE_CORRUPT_BKPT;
|
||||||
}
|
}
|
||||||
rc = sqlite3PagerGet(pBt->pPager, pgno, (DbPage**)&pDbPage, bReadOnly);
|
rc = sqlite3PagerGet(pBt->pPager, pgno, (DbPage**)&pDbPage, bReadOnly);
|
||||||
if( rc ){
|
if( rc ){
|
||||||
goto getAndInitPage_error1;
|
*ppPage = 0;
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
*ppPage = (MemPage*)sqlite3PagerGetExtra(pDbPage);
|
pPage = (MemPage*)sqlite3PagerGetExtra(pDbPage);
|
||||||
if( (*ppPage)->isInit==0 ){
|
if( pPage->isInit==0 ){
|
||||||
btreePageFromDbPage(pDbPage, pgno, pBt);
|
btreePageFromDbPage(pDbPage, pgno, pBt);
|
||||||
rc = btreeInitPage(*ppPage);
|
rc = btreeInitPage(pPage);
|
||||||
if( rc!=SQLITE_OK ){
|
if( rc!=SQLITE_OK ){
|
||||||
goto getAndInitPage_error2;
|
releasePage(pPage);
|
||||||
|
*ppPage = 0;
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert( (*ppPage)->pgno==pgno || CORRUPT_DB );
|
assert( pPage->pgno==pgno || CORRUPT_DB );
|
||||||
assert( (*ppPage)->aData==sqlite3PagerGetData(pDbPage) );
|
assert( pPage->aData==sqlite3PagerGetData(pDbPage) );
|
||||||
|
*ppPage = pPage;
|
||||||
/* If obtaining a child page for a cursor, we must verify that the page is
|
|
||||||
** compatible with the root page. */
|
|
||||||
if( pCur && ((*ppPage)->nCell<1 || (*ppPage)->intKey!=pCur->curIntKey) ){
|
|
||||||
rc = SQLITE_CORRUPT_PGNO(pgno);
|
|
||||||
goto getAndInitPage_error2;
|
|
||||||
}
|
|
||||||
return SQLITE_OK;
|
return SQLITE_OK;
|
||||||
|
|
||||||
getAndInitPage_error2:
|
|
||||||
releasePage(*ppPage);
|
|
||||||
getAndInitPage_error1:
|
|
||||||
if( pCur ){
|
|
||||||
pCur->iPage--;
|
|
||||||
pCur->pPage = pCur->apPage[pCur->iPage];
|
|
||||||
}
|
|
||||||
testcase( pgno==0 );
|
|
||||||
assert( pgno!=0 || rc!=SQLITE_OK );
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -5354,6 +5326,7 @@ const void *sqlite3BtreePayloadFetch(BtCursor *pCur, u32 *pAmt){
|
|||||||
** vice-versa).
|
** vice-versa).
|
||||||
*/
|
*/
|
||||||
static int moveToChild(BtCursor *pCur, u32 newPgno){
|
static int moveToChild(BtCursor *pCur, u32 newPgno){
|
||||||
|
int rc;
|
||||||
assert( cursorOwnsBtShared(pCur) );
|
assert( cursorOwnsBtShared(pCur) );
|
||||||
assert( pCur->eState==CURSOR_VALID );
|
assert( pCur->eState==CURSOR_VALID );
|
||||||
assert( pCur->iPage<BTCURSOR_MAX_DEPTH );
|
assert( pCur->iPage<BTCURSOR_MAX_DEPTH );
|
||||||
@@ -5367,8 +5340,17 @@ static int moveToChild(BtCursor *pCur, u32 newPgno){
|
|||||||
pCur->apPage[pCur->iPage] = pCur->pPage;
|
pCur->apPage[pCur->iPage] = pCur->pPage;
|
||||||
pCur->ix = 0;
|
pCur->ix = 0;
|
||||||
pCur->iPage++;
|
pCur->iPage++;
|
||||||
return getAndInitPage(pCur->pBt, newPgno, &pCur->pPage, pCur,
|
rc = getAndInitPage(pCur->pBt, newPgno, &pCur->pPage, pCur->curPagerFlags);
|
||||||
pCur->curPagerFlags);
|
if( rc==SQLITE_OK
|
||||||
|
&& (pCur->pPage->nCell<1 || pCur->pPage->intKey!=pCur->curIntKey)
|
||||||
|
){
|
||||||
|
releasePage(pCur->pPage);
|
||||||
|
rc = SQLITE_CORRUPT_PGNO(newPgno);
|
||||||
|
}
|
||||||
|
if( rc ){
|
||||||
|
pCur->pPage = pCur->apPage[--pCur->iPage];
|
||||||
|
}
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SQLITE_DEBUG
|
#ifdef SQLITE_DEBUG
|
||||||
@@ -5475,7 +5457,7 @@ static int moveToRoot(BtCursor *pCur){
|
|||||||
sqlite3BtreeClearCursor(pCur);
|
sqlite3BtreeClearCursor(pCur);
|
||||||
}
|
}
|
||||||
rc = getAndInitPage(pCur->pBt, pCur->pgnoRoot, &pCur->pPage,
|
rc = getAndInitPage(pCur->pBt, pCur->pgnoRoot, &pCur->pPage,
|
||||||
0, pCur->curPagerFlags);
|
pCur->curPagerFlags);
|
||||||
if( rc!=SQLITE_OK ){
|
if( rc!=SQLITE_OK ){
|
||||||
pCur->eState = CURSOR_INVALID;
|
pCur->eState = CURSOR_INVALID;
|
||||||
return rc;
|
return rc;
|
||||||
@@ -6088,10 +6070,36 @@ bypass_moveto_root:
|
|||||||
}else{
|
}else{
|
||||||
chldPg = get4byte(findCell(pPage, lwr));
|
chldPg = get4byte(findCell(pPage, lwr));
|
||||||
}
|
}
|
||||||
pCur->ix = (u16)lwr;
|
|
||||||
rc = moveToChild(pCur, chldPg);
|
/* This block is similar to an in-lined version of:
|
||||||
if( rc ) break;
|
**
|
||||||
}
|
** pCur->ix = (u16)lwr;
|
||||||
|
** rc = moveToChild(pCur, chldPg);
|
||||||
|
** if( rc ) break;
|
||||||
|
*/
|
||||||
|
pCur->info.nSize = 0;
|
||||||
|
pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
|
||||||
|
if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
|
||||||
|
return SQLITE_CORRUPT_BKPT;
|
||||||
|
}
|
||||||
|
pCur->aiIdx[pCur->iPage] = (u16)lwr;
|
||||||
|
pCur->apPage[pCur->iPage] = pCur->pPage;
|
||||||
|
pCur->ix = 0;
|
||||||
|
pCur->iPage++;
|
||||||
|
rc = getAndInitPage(pCur->pBt, chldPg, &pCur->pPage, pCur->curPagerFlags);
|
||||||
|
if( rc==SQLITE_OK
|
||||||
|
&& (pCur->pPage->nCell<1 || pCur->pPage->intKey!=pCur->curIntKey)
|
||||||
|
){
|
||||||
|
releasePage(pCur->pPage);
|
||||||
|
rc = SQLITE_CORRUPT_PGNO(chldPg);
|
||||||
|
}
|
||||||
|
if( rc ){
|
||||||
|
pCur->pPage = pCur->apPage[--pCur->iPage];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
***** End of in-lined moveToChild() call */
|
||||||
|
}
|
||||||
moveto_index_finish:
|
moveto_index_finish:
|
||||||
pCur->info.nSize = 0;
|
pCur->info.nSize = 0;
|
||||||
assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
|
assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
|
||||||
@@ -8145,7 +8153,7 @@ static int balance_nonroot(
|
|||||||
pgno = get4byte(pRight);
|
pgno = get4byte(pRight);
|
||||||
while( 1 ){
|
while( 1 ){
|
||||||
if( rc==SQLITE_OK ){
|
if( rc==SQLITE_OK ){
|
||||||
rc = getAndInitPage(pBt, pgno, &apOld[i], 0, 0);
|
rc = getAndInitPage(pBt, pgno, &apOld[i], 0);
|
||||||
}
|
}
|
||||||
if( rc ){
|
if( rc ){
|
||||||
memset(apOld, 0, (i+1)*sizeof(MemPage*));
|
memset(apOld, 0, (i+1)*sizeof(MemPage*));
|
||||||
@@ -10030,7 +10038,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, 0);
|
rc = getAndInitPage(pBt, pgno, &pPage, 0);
|
||||||
if( rc ) return rc;
|
if( rc ) return rc;
|
||||||
if( (pBt->openFlags & BTREE_SINGLE)==0
|
if( (pBt->openFlags & BTREE_SINGLE)==0
|
||||||
&& sqlite3PagerPageRefcount(pPage->pDbPage) != (1 + (pgno==1))
|
&& sqlite3PagerPageRefcount(pPage->pDbPage) != (1 + (pgno==1))
|
||||||
|
Reference in New Issue
Block a user