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

Performance optimization to the clearCell() routine inside of btree.

FossilOrigin-Name: c4e02619a4dc8b07f658e7c88011991a086eb1e760d920b9024a11437daaabfd
This commit is contained in:
drh
2021-05-15 13:08:44 +00:00
parent 49bb56e9b0
commit 86c779fe42
3 changed files with 28 additions and 17 deletions

View File

@@ -1,5 +1,5 @@
C Small\sperformance\simprovement\sfor\ssqlite3BtreeInsert(). C Performance\soptimization\sto\sthe\sclearCell()\sroutine\sinside\sof\sbtree.
D 2021-05-14T20:01:36.170 D 2021-05-15T13:08:44.420
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
@@ -484,7 +484,7 @@ F src/auth.c 08954fdc4cc2da5264ba5b75cfd90b67a6fc7d1710a02ccf917c38eadec77853
F src/backup.c 3014889fa06e20e6adfa0d07b60097eec1f6e5b06671625f476a714d2356513d F src/backup.c 3014889fa06e20e6adfa0d07b60097eec1f6e5b06671625f476a714d2356513d
F src/bitvec.c 17ea48eff8ba979f1f5b04cc484c7bb2be632f33 F src/bitvec.c 17ea48eff8ba979f1f5b04cc484c7bb2be632f33
F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6 F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6
F src/btree.c 43e755a22fa4e94cc3203b604200946088c1bb9f1b80ebacde496d515161c7e7 F src/btree.c f74511a1476175a734221d38e33638b6fc4c6c94c819bbfa8419824703b967da
F src/btree.h 096cc53baa58be22b02c896d1cf933c38cfc6d65f9253c1367ece8cc88a24de5 F src/btree.h 096cc53baa58be22b02c896d1cf933c38cfc6d65f9253c1367ece8cc88a24de5
F src/btreeInt.h 7bc15a24a02662409ebcd6aeaa1065522d14b7fda71573a2b0568b458f514ae0 F src/btreeInt.h 7bc15a24a02662409ebcd6aeaa1065522d14b7fda71573a2b0568b458f514ae0
F src/build.c a7866beda66a7c8971e013674c7f659d19977d9ad51e11032479b1f754d1ef21 F src/build.c a7866beda66a7c8971e013674c7f659d19977d9ad51e11032479b1f754d1ef21
@@ -1913,7 +1913,7 @@ 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 cf63abbe559d04f993f99a37d41ba4a97c0261094f1d4cc05cfa23b1e11731f5 P 4ae64484c57740333322cebd713b50b01a5a5838d41c65f67e26d65769770789
R 56636569b2dc12071ca5587b9d291c1a R c57f4aed344bc5813fc7501f2d476ff9
U drh U drh
Z 87019381c8d9b7e2ea4914c987f0da73 Z d7b4c1d6b383cbf19bb45bb69313de60

View File

@@ -1 +1 @@
4ae64484c57740333322cebd713b50b01a5a5838d41c65f67e26d65769770789 c4e02619a4dc8b07f658e7c88011991a086eb1e760d920b9024a11437daaabfd

View File

@@ -6420,10 +6420,9 @@ static void freePage(MemPage *pPage, int *pRC){
} }
/* /*
** Free any overflow pages associated with the given Cell. Store ** Free the overflow pages associated with the given Cell.
** size information about the cell in pInfo.
*/ */
static int clearCell( static SQLITE_NOINLINE int clearCellOverflow(
MemPage *pPage, /* The page that contains the Cell */ MemPage *pPage, /* The page that contains the Cell */
unsigned char *pCell, /* First byte of the Cell */ unsigned char *pCell, /* First byte of the Cell */
CellInfo *pInfo /* Size information about the cell */ CellInfo *pInfo /* Size information about the cell */
@@ -6435,10 +6434,7 @@ static int clearCell(
u32 ovflPageSize; u32 ovflPageSize;
assert( sqlite3_mutex_held(pPage->pBt->mutex) ); assert( sqlite3_mutex_held(pPage->pBt->mutex) );
pPage->xParseCell(pPage, pCell, pInfo); assert( pInfo->nLocal!=pInfo->nPayload );
if( pInfo->nLocal==pInfo->nPayload ){
return SQLITE_OK; /* No overflow pages. Return without doing anything */
}
testcase( pCell + pInfo->nSize == pPage->aDataEnd ); testcase( pCell + pInfo->nSize == pPage->aDataEnd );
testcase( pCell + (pInfo->nSize-1) == pPage->aDataEnd ); testcase( pCell + (pInfo->nSize-1) == pPage->aDataEnd );
if( pCell + pInfo->nSize > pPage->aDataEnd ){ if( pCell + pInfo->nSize > pPage->aDataEnd ){
@@ -6494,6 +6490,21 @@ static int clearCell(
return SQLITE_OK; return SQLITE_OK;
} }
/* Call xParseCell to compute the size of a cell. If the cell contains
** overflow, then invoke cellClearOverflow to clear out that overflow.
** STore the result code (SQLITE_OK or some error code) in rc.
**
** Implemented as macro to force inlining for performance.
*/
#define BTREE_CLEAR_CELL(rc, pPage, pCell, sInfo) \
pPage->xParseCell(pPage, pCell, &sInfo); \
if( sInfo.nLocal!=sInfo.nPayload ){ \
rc = clearCellOverflow(pPage, pCell, &sInfo); \
}else{ \
rc = SQLITE_OK; \
}
/* /*
** Create the byte sequence used to represent a cell on page pPage ** Create the byte sequence used to represent a cell on page pPage
** and write that byte sequence into pCell[]. Overflow pages are ** and write that byte sequence into pCell[]. Overflow pages are
@@ -8889,7 +8900,7 @@ int sqlite3BtreeInsert(
if( !pPage->leaf ){ if( !pPage->leaf ){
memcpy(newCell, oldCell, 4); memcpy(newCell, oldCell, 4);
} }
rc = clearCell(pPage, oldCell, &info); BTREE_CLEAR_CELL(rc, pPage, oldCell, info);
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
@@ -9191,7 +9202,7 @@ int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
** itself from within the page. */ ** itself from within the page. */
rc = sqlite3PagerWrite(pPage->pDbPage); rc = sqlite3PagerWrite(pPage->pDbPage);
if( rc ) return rc; if( rc ) return rc;
rc = clearCell(pPage, pCell, &info); BTREE_CLEAR_CELL(rc, pPage, pCell, info);
dropCell(pPage, iCellIdx, info.nSize, &rc); dropCell(pPage, iCellIdx, info.nSize, &rc);
if( rc ) return rc; if( rc ) return rc;
@@ -9478,7 +9489,7 @@ static int clearDatabasePage(
rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange); rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange);
if( rc ) goto cleardatabasepage_out; if( rc ) goto cleardatabasepage_out;
} }
rc = clearCell(pPage, pCell, &info); BTREE_CLEAR_CELL(rc, pPage, pCell, info);
if( rc ) goto cleardatabasepage_out; if( rc ) goto cleardatabasepage_out;
} }
if( !pPage->leaf ){ if( !pPage->leaf ){