]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Performance optimization to the clearCell() routine inside of btree.
authordrh <>
Sat, 15 May 2021 13:08:44 +0000 (13:08 +0000)
committerdrh <>
Sat, 15 May 2021 13:08:44 +0000 (13:08 +0000)
FossilOrigin-Name: c4e02619a4dc8b07f658e7c88011991a086eb1e760d920b9024a11437daaabfd

manifest
manifest.uuid
src/btree.c

index 0ead98eac2c80b0b058847b3942da2b3ae9baa0a..987b4ee6040268b850beba7f3215af5917462550 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Small\sperformance\simprovement\sfor\ssqlite3BtreeInsert().
-D 2021-05-14T20:01:36.170
+C Performance\soptimization\sto\sthe\sclearCell()\sroutine\sinside\sof\sbtree.
+D 2021-05-15T13:08:44.420
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -484,7 +484,7 @@ F src/auth.c 08954fdc4cc2da5264ba5b75cfd90b67a6fc7d1710a02ccf917c38eadec77853
 F src/backup.c 3014889fa06e20e6adfa0d07b60097eec1f6e5b06671625f476a714d2356513d
 F src/bitvec.c 17ea48eff8ba979f1f5b04cc484c7bb2be632f33
 F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6
-F src/btree.c 43e755a22fa4e94cc3203b604200946088c1bb9f1b80ebacde496d515161c7e7
+F src/btree.c f74511a1476175a734221d38e33638b6fc4c6c94c819bbfa8419824703b967da
 F src/btree.h 096cc53baa58be22b02c896d1cf933c38cfc6d65f9253c1367ece8cc88a24de5
 F src/btreeInt.h 7bc15a24a02662409ebcd6aeaa1065522d14b7fda71573a2b0568b458f514ae0
 F src/build.c a7866beda66a7c8971e013674c7f659d19977d9ad51e11032479b1f754d1ef21
@@ -1913,7 +1913,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P cf63abbe559d04f993f99a37d41ba4a97c0261094f1d4cc05cfa23b1e11731f5
-R 56636569b2dc12071ca5587b9d291c1a
+P 4ae64484c57740333322cebd713b50b01a5a5838d41c65f67e26d65769770789
+R c57f4aed344bc5813fc7501f2d476ff9
 U drh
-Z 87019381c8d9b7e2ea4914c987f0da73
+Z d7b4c1d6b383cbf19bb45bb69313de60
index 8fb0a89515e8cb059d883d7de878efa549407d54..df8f45d4c11bc0e9832c9ea7cb81b36dc041f633 100644 (file)
@@ -1 +1 @@
-4ae64484c57740333322cebd713b50b01a5a5838d41c65f67e26d65769770789
\ No newline at end of file
+c4e02619a4dc8b07f658e7c88011991a086eb1e760d920b9024a11437daaabfd
\ No newline at end of file
index e38a7c07c5e374c73704c5294a6a8903c76fba46..66716254eb8ef6d2e4d1caeb5308bd534f2c6499 100644 (file)
@@ -6420,10 +6420,9 @@ static void freePage(MemPage *pPage, int *pRC){
 }
 
 /*
-** Free any overflow pages associated with the given Cell.  Store
-** size information about the cell in pInfo.
+** Free the overflow pages associated with the given Cell.
 */
-static int clearCell(
+static SQLITE_NOINLINE int clearCellOverflow(
   MemPage *pPage,          /* The page that contains the Cell */
   unsigned char *pCell,    /* First byte of the Cell */
   CellInfo *pInfo          /* Size information about the cell */
@@ -6435,10 +6434,7 @@ static int clearCell(
   u32 ovflPageSize;
 
   assert( sqlite3_mutex_held(pPage->pBt->mutex) );
-  pPage->xParseCell(pPage, pCell, pInfo);
-  if( pInfo->nLocal==pInfo->nPayload ){
-    return SQLITE_OK;  /* No overflow pages. Return without doing anything */
-  }
+  assert( pInfo->nLocal!=pInfo->nPayload );
   testcase( pCell + pInfo->nSize == pPage->aDataEnd );
   testcase( pCell + (pInfo->nSize-1) == pPage->aDataEnd );
   if( pCell + pInfo->nSize > pPage->aDataEnd ){
@@ -6494,6 +6490,21 @@ static int clearCell(
   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
 ** and write that byte sequence into pCell[].  Overflow pages are
@@ -8889,7 +8900,7 @@ int sqlite3BtreeInsert(
     if( !pPage->leaf ){
       memcpy(newCell, oldCell, 4);
     }
-    rc = clearCell(pPage, oldCell, &info);
+    BTREE_CLEAR_CELL(rc, pPage, oldCell, info);
     testcase( pCur->curFlags & BTCF_ValidOvfl );
     invalidateOverflowCache(pCur);
     if( info.nSize==szNew && info.nLocal==info.nPayload 
@@ -9191,7 +9202,7 @@ int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
   ** itself from within the page.  */
   rc = sqlite3PagerWrite(pPage->pDbPage);
   if( rc ) return rc;
-  rc = clearCell(pPage, pCell, &info);
+  BTREE_CLEAR_CELL(rc, pPage, pCell, info);
   dropCell(pPage, iCellIdx, info.nSize, &rc);
   if( rc ) return rc;
 
@@ -9478,7 +9489,7 @@ static int clearDatabasePage(
       rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange);
       if( rc ) goto cleardatabasepage_out;
     }
-    rc = clearCell(pPage, pCell, &info);
+    BTREE_CLEAR_CELL(rc, pPage, pCell, info);
     if( rc ) goto cleardatabasepage_out;
   }
   if( !pPage->leaf ){