mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +03:00
Performance optimization to sqlite3BtreeInsert().
FossilOrigin-Name: b8976ebfe03fbc1e09a38d598a62493a7f19ff7a2a3acd1ec54d0dee190471e9
This commit is contained in:
14
manifest
14
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Small\sperformance\simprovement\sin\ssqlite3BtreeTransferRow().
|
C Performance\soptimization\sto\ssqlite3BtreeInsert().
|
||||||
D 2022-11-21T13:35:00.374
|
D 2022-11-21T14:13:10.344
|
||||||
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
|
||||||
@@ -580,9 +580,9 @@ F src/auth.c f4fa91b6a90bbc8e0d0f738aa284551739c9543a367071f55574681e0f24f8cf
|
|||||||
F src/backup.c a2891172438e385fdbe97c11c9745676bec54f518d4447090af97189fd8e52d7
|
F src/backup.c a2891172438e385fdbe97c11c9745676bec54f518d4447090af97189fd8e52d7
|
||||||
F src/bitvec.c 7c849aac407230278445cb069bebc5f89bf2ddd87c5ed9459b070a9175707b3d
|
F src/bitvec.c 7c849aac407230278445cb069bebc5f89bf2ddd87c5ed9459b070a9175707b3d
|
||||||
F src/btmutex.c 6ffb0a22c19e2f9110be0964d0731d2ef1c67b5f7fabfbaeb7b9dabc4b7740ca
|
F src/btmutex.c 6ffb0a22c19e2f9110be0964d0731d2ef1c67b5f7fabfbaeb7b9dabc4b7740ca
|
||||||
F src/btree.c 89e0e5af46d1921a0a1d17bc5ec95cd0ec89b050b32373d825c76b5d3f3a2ec9
|
F src/btree.c 6fc3f0c6db7ec2296778cca7c696bb10be9de42f531f106c43d0f410cec0ee2a
|
||||||
F src/btree.h 4fcbb0b041013071dd5e9f53c538d49916c092e6ad8842185985e5270a0792de
|
F src/btree.h 4fcbb0b041013071dd5e9f53c538d49916c092e6ad8842185985e5270a0792de
|
||||||
F src/btreeInt.h 8ce1332edd89dfd2461d561ac10a0ab5601c8e06200cb5230596c3caaf54482e
|
F src/btreeInt.h 88ad499c92b489afedbfefc3f067c4d15023ec021afe622db240dc9d2277cfa5
|
||||||
F src/build.c d3e43e950e4e377c1d451a4862556792acdef1faba14a03f899d30d09731c48b
|
F src/build.c d3e43e950e4e377c1d451a4862556792acdef1faba14a03f899d30d09731c48b
|
||||||
F src/callback.c 4cd7225b26a97f7de5fee5ae10464bed5a78f2adefe19534cc2095b3a8ca484a
|
F src/callback.c 4cd7225b26a97f7de5fee5ae10464bed5a78f2adefe19534cc2095b3a8ca484a
|
||||||
F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e
|
F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e
|
||||||
@@ -2059,8 +2059,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 07182dca9f2a4ffea1af0684c93e55e105465b2ee9820c70764e3e7bc1c28efc
|
P dab959ea3edf99788bfd76352cd46a3e56876b0e7d7008c6927aa14534853c50
|
||||||
R 06d7ab66cd3f5a521e55d8df4889b401
|
R 2eb76fb48a48a84e8cbe3f1574fa7eb8
|
||||||
U drh
|
U drh
|
||||||
Z a6fa3008dc4759fddba2bf18530ff99d
|
Z 44675fc68f20e0cf82e7b5bf3a25ed71
|
||||||
# Remove this line to create a well-formed Fossil manifest.
|
# Remove this line to create a well-formed Fossil manifest.
|
||||||
|
@@ -1 +1 @@
|
|||||||
dab959ea3edf99788bfd76352cd46a3e56876b0e7d7008c6927aa14534853c50
|
b8976ebfe03fbc1e09a38d598a62493a7f19ff7a2a3acd1ec54d0dee190471e9
|
37
src/btree.c
37
src/btree.c
@@ -6606,7 +6606,7 @@ static int freePage2(BtShared *pBt, MemPage *pMemPage, Pgno iPage){
|
|||||||
/* If the database supports auto-vacuum, write an entry in the pointer-map
|
/* If the database supports auto-vacuum, write an entry in the pointer-map
|
||||||
** to indicate that the page is free.
|
** to indicate that the page is free.
|
||||||
*/
|
*/
|
||||||
if( ISAUTOVACUUM ){
|
if( ISAUTOVACUUM(pBt) ){
|
||||||
ptrmapPut(pBt, iPage, PTRMAP_FREEPAGE, 0, &rc);
|
ptrmapPut(pBt, iPage, PTRMAP_FREEPAGE, 0, &rc);
|
||||||
if( rc ) goto freepage_out;
|
if( rc ) goto freepage_out;
|
||||||
}
|
}
|
||||||
@@ -7682,7 +7682,7 @@ static int balance_quick(MemPage *pParent, MemPage *pPage, u8 *pSpace){
|
|||||||
** be marked as dirty. Returning an error code will cause a
|
** be marked as dirty. Returning an error code will cause a
|
||||||
** rollback, undoing any changes made to the parent page.
|
** rollback, undoing any changes made to the parent page.
|
||||||
*/
|
*/
|
||||||
if( ISAUTOVACUUM ){
|
if( ISAUTOVACUUM(pBt) ){
|
||||||
ptrmapPut(pBt, pgnoNew, PTRMAP_BTREE, pParent->pgno, &rc);
|
ptrmapPut(pBt, pgnoNew, PTRMAP_BTREE, pParent->pgno, &rc);
|
||||||
if( szCell>pNew->minLocal ){
|
if( szCell>pNew->minLocal ){
|
||||||
ptrmapPutOvflPtr(pNew, pNew, pCell, &rc);
|
ptrmapPutOvflPtr(pNew, pNew, pCell, &rc);
|
||||||
@@ -7820,7 +7820,7 @@ static void copyNodeContent(MemPage *pFrom, MemPage *pTo, int *pRC){
|
|||||||
/* If this is an auto-vacuum database, update the pointer-map entries
|
/* If this is an auto-vacuum database, update the pointer-map entries
|
||||||
** for any b-tree or overflow pages that pTo now contains the pointers to.
|
** for any b-tree or overflow pages that pTo now contains the pointers to.
|
||||||
*/
|
*/
|
||||||
if( ISAUTOVACUUM ){
|
if( ISAUTOVACUUM(pBt) ){
|
||||||
*pRC = setChildPtrmaps(pTo);
|
*pRC = setChildPtrmaps(pTo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8308,7 +8308,7 @@ static int balance_nonroot(
|
|||||||
cntOld[i] = b.nCell;
|
cntOld[i] = b.nCell;
|
||||||
|
|
||||||
/* Set the pointer-map entry for the new sibling page. */
|
/* Set the pointer-map entry for the new sibling page. */
|
||||||
if( ISAUTOVACUUM ){
|
if( ISAUTOVACUUM(pBt) ){
|
||||||
ptrmapPut(pBt, pNew->pgno, PTRMAP_BTREE, pParent->pgno, &rc);
|
ptrmapPut(pBt, pNew->pgno, PTRMAP_BTREE, pParent->pgno, &rc);
|
||||||
if( rc!=SQLITE_OK ){
|
if( rc!=SQLITE_OK ){
|
||||||
goto balance_cleanup;
|
goto balance_cleanup;
|
||||||
@@ -8401,7 +8401,7 @@ static int balance_nonroot(
|
|||||||
** updated. This happens below, after the sibling pages have been
|
** updated. This happens below, after the sibling pages have been
|
||||||
** populated, not here.
|
** populated, not here.
|
||||||
*/
|
*/
|
||||||
if( ISAUTOVACUUM ){
|
if( ISAUTOVACUUM(pBt) ){
|
||||||
MemPage *pOld;
|
MemPage *pOld;
|
||||||
MemPage *pNew = pOld = apNew[0];
|
MemPage *pNew = pOld = apNew[0];
|
||||||
int cntOldNext = pNew->nCell + pNew->nOverflow;
|
int cntOldNext = pNew->nCell + pNew->nOverflow;
|
||||||
@@ -8594,7 +8594,7 @@ static int balance_nonroot(
|
|||||||
);
|
);
|
||||||
copyNodeContent(apNew[0], pParent, &rc);
|
copyNodeContent(apNew[0], pParent, &rc);
|
||||||
freePage(apNew[0], &rc);
|
freePage(apNew[0], &rc);
|
||||||
}else if( ISAUTOVACUUM && !leafCorrection ){
|
}else if( ISAUTOVACUUM(pBt) && !leafCorrection ){
|
||||||
/* Fix the pointer map entries associated with the right-child of each
|
/* Fix the pointer map entries associated with the right-child of each
|
||||||
** sibling page. All other pointer map entries have already been taken
|
** sibling page. All other pointer map entries have already been taken
|
||||||
** care of. */
|
** care of. */
|
||||||
@@ -8615,7 +8615,7 @@ static int balance_nonroot(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
if( ISAUTOVACUUM && rc==SQLITE_OK && apNew[0]->isInit ){
|
if( ISAUTOVACUUM(pBt) && rc==SQLITE_OK && apNew[0]->isInit ){
|
||||||
/* The ptrmapCheckPages() contains assert() statements that verify that
|
/* The ptrmapCheckPages() contains assert() statements that verify that
|
||||||
** all pointer map pages are set correctly. This is helpful while
|
** all pointer map pages are set correctly. This is helpful while
|
||||||
** debugging. This is usually disabled because a corrupt database may
|
** debugging. This is usually disabled because a corrupt database may
|
||||||
@@ -8677,7 +8677,7 @@ static int balance_deeper(MemPage *pRoot, MemPage **ppChild){
|
|||||||
if( rc==SQLITE_OK ){
|
if( rc==SQLITE_OK ){
|
||||||
rc = allocateBtreePage(pBt,&pChild,&pgnoChild,pRoot->pgno,0);
|
rc = allocateBtreePage(pBt,&pChild,&pgnoChild,pRoot->pgno,0);
|
||||||
copyNodeContent(pRoot, pChild, &rc);
|
copyNodeContent(pRoot, pChild, &rc);
|
||||||
if( ISAUTOVACUUM ){
|
if( ISAUTOVACUUM(pBt) ){
|
||||||
ptrmapPut(pBt, pgnoChild, PTRMAP_BTREE, pRoot->pgno, &rc);
|
ptrmapPut(pBt, pgnoChild, PTRMAP_BTREE, pRoot->pgno, &rc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9009,7 +9009,6 @@ int sqlite3BtreeInsert(
|
|||||||
int idx;
|
int idx;
|
||||||
MemPage *pPage;
|
MemPage *pPage;
|
||||||
Btree *p = pCur->pBtree;
|
Btree *p = pCur->pBtree;
|
||||||
BtShared *pBt = p->pBt;
|
|
||||||
unsigned char *oldCell;
|
unsigned char *oldCell;
|
||||||
unsigned char *newCell = 0;
|
unsigned char *newCell = 0;
|
||||||
|
|
||||||
@@ -9028,7 +9027,7 @@ int sqlite3BtreeInsert(
|
|||||||
** not to clear the cursor here.
|
** not to clear the cursor here.
|
||||||
*/
|
*/
|
||||||
if( pCur->curFlags & BTCF_Multiple ){
|
if( pCur->curFlags & BTCF_Multiple ){
|
||||||
rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
|
rc = saveAllCursors(p->pBt, pCur->pgnoRoot, pCur);
|
||||||
if( rc ) return rc;
|
if( rc ) return rc;
|
||||||
if( loc && pCur->iPage<0 ){
|
if( loc && pCur->iPage<0 ){
|
||||||
/* This can only happen if the schema is corrupt such that there is more
|
/* This can only happen if the schema is corrupt such that there is more
|
||||||
@@ -9052,8 +9051,8 @@ int sqlite3BtreeInsert(
|
|||||||
|
|
||||||
assert( cursorOwnsBtShared(pCur) );
|
assert( cursorOwnsBtShared(pCur) );
|
||||||
assert( (pCur->curFlags & BTCF_WriteFlag)!=0
|
assert( (pCur->curFlags & BTCF_WriteFlag)!=0
|
||||||
&& pBt->inTransaction==TRANS_WRITE
|
&& p->pBt->inTransaction==TRANS_WRITE
|
||||||
&& (pBt->btsFlags & BTS_READ_ONLY)==0 );
|
&& (p->pBt->btsFlags & BTS_READ_ONLY)==0 );
|
||||||
assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
|
assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
|
||||||
|
|
||||||
/* Assert that the caller has been consistent. If this cursor was opened
|
/* Assert that the caller has been consistent. If this cursor was opened
|
||||||
@@ -9170,19 +9169,19 @@ int sqlite3BtreeInsert(
|
|||||||
pCur->pgnoRoot, pX->nKey, pX->nData, pPage->pgno,
|
pCur->pgnoRoot, pX->nKey, pX->nData, pPage->pgno,
|
||||||
loc==0 ? "overwrite" : "new entry"));
|
loc==0 ? "overwrite" : "new entry"));
|
||||||
assert( pPage->isInit || CORRUPT_DB );
|
assert( pPage->isInit || CORRUPT_DB );
|
||||||
newCell = pBt->pTmpSpace;
|
newCell = p->pBt->pTmpSpace;
|
||||||
assert( newCell!=0 );
|
assert( newCell!=0 );
|
||||||
assert( BTREE_PREFORMAT==OPFLAG_PREFORMAT );
|
assert( BTREE_PREFORMAT==OPFLAG_PREFORMAT );
|
||||||
if( flags & BTREE_PREFORMAT ){
|
if( flags & BTREE_PREFORMAT ){
|
||||||
rc = SQLITE_OK;
|
rc = SQLITE_OK;
|
||||||
szNew = pBt->nPreformatSize;
|
szNew = p->pBt->nPreformatSize;
|
||||||
if( szNew<4 ) szNew = 4;
|
if( szNew<4 ) szNew = 4;
|
||||||
if( ISAUTOVACUUM && szNew>pPage->maxLocal ){
|
if( ISAUTOVACUUM(p->pBt) && szNew>pPage->maxLocal ){
|
||||||
CellInfo info;
|
CellInfo info;
|
||||||
pPage->xParseCell(pPage, newCell, &info);
|
pPage->xParseCell(pPage, newCell, &info);
|
||||||
if( info.nPayload!=info.nLocal ){
|
if( info.nPayload!=info.nLocal ){
|
||||||
Pgno ovfl = get4byte(&newCell[szNew-4]);
|
Pgno ovfl = get4byte(&newCell[szNew-4]);
|
||||||
ptrmapPut(pBt, ovfl, PTRMAP_OVERFLOW1, pPage->pgno, &rc);
|
ptrmapPut(p->pBt, ovfl, PTRMAP_OVERFLOW1, pPage->pgno, &rc);
|
||||||
if( NEVER(rc) ) goto end_insert;
|
if( NEVER(rc) ) goto end_insert;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9191,7 +9190,7 @@ int sqlite3BtreeInsert(
|
|||||||
if( rc ) goto end_insert;
|
if( rc ) goto end_insert;
|
||||||
}
|
}
|
||||||
assert( szNew==pPage->xCellSize(pPage, newCell) );
|
assert( szNew==pPage->xCellSize(pPage, newCell) );
|
||||||
assert( szNew <= MX_CELL_SIZE(pBt) );
|
assert( szNew <= MX_CELL_SIZE(p->pBt) );
|
||||||
idx = pCur->ix;
|
idx = pCur->ix;
|
||||||
if( loc==0 ){
|
if( loc==0 ){
|
||||||
CellInfo info;
|
CellInfo info;
|
||||||
@@ -9211,7 +9210,7 @@ int sqlite3BtreeInsert(
|
|||||||
testcase( pCur->curFlags & BTCF_ValidOvfl );
|
testcase( pCur->curFlags & BTCF_ValidOvfl );
|
||||||
invalidateOverflowCache(pCur);
|
invalidateOverflowCache(pCur);
|
||||||
if( info.nSize==szNew && info.nLocal==info.nPayload
|
if( info.nSize==szNew && info.nLocal==info.nPayload
|
||||||
&& (!ISAUTOVACUUM || szNew<pPage->minLocal)
|
&& (!ISAUTOVACUUM(p->pBt) || szNew<pPage->minLocal)
|
||||||
){
|
){
|
||||||
/* Overwrite the old cell with the new if they are the same size.
|
/* Overwrite the old cell with the new if they are the same size.
|
||||||
** We could also try to do this if the old cell is smaller, then add
|
** We could also try to do this if the old cell is smaller, then add
|
||||||
@@ -9390,7 +9389,7 @@ int sqlite3BtreeTransferRow(BtCursor *pDest, BtCursor *pSrc, i64 iKey){
|
|||||||
MemPage *pNew = 0;
|
MemPage *pNew = 0;
|
||||||
rc = allocateBtreePage(pBt, &pNew, &pgnoNew, 0, 0);
|
rc = allocateBtreePage(pBt, &pNew, &pgnoNew, 0, 0);
|
||||||
put4byte(pPgnoOut, pgnoNew);
|
put4byte(pPgnoOut, pgnoNew);
|
||||||
if( ISAUTOVACUUM && pPageOut ){
|
if( ISAUTOVACUUM(pBt) && pPageOut ){
|
||||||
ptrmapPut(pBt, pgnoNew, PTRMAP_OVERFLOW2, pPageOut->pgno, &rc);
|
ptrmapPut(pBt, pgnoNew, PTRMAP_OVERFLOW2, pPageOut->pgno, &rc);
|
||||||
}
|
}
|
||||||
releasePage(pPageOut);
|
releasePage(pPageOut);
|
||||||
|
@@ -674,9 +674,9 @@ struct BtCursor {
|
|||||||
** So, this macro is defined instead.
|
** So, this macro is defined instead.
|
||||||
*/
|
*/
|
||||||
#ifndef SQLITE_OMIT_AUTOVACUUM
|
#ifndef SQLITE_OMIT_AUTOVACUUM
|
||||||
#define ISAUTOVACUUM (pBt->autoVacuum)
|
#define ISAUTOVACUUM(pBt) (pBt->autoVacuum)
|
||||||
#else
|
#else
|
||||||
#define ISAUTOVACUUM 0
|
#define ISAUTOVACUUM(pBt) 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user