]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add a new subclass for MemPage.xCellSize specifically for the case of a leaf
authordrh <>
Wed, 23 Feb 2022 22:56:10 +0000 (22:56 +0000)
committerdrh <>
Wed, 23 Feb 2022 22:56:10 +0000 (22:56 +0000)
page in a B+Tree, that is optimized for that cases.  This gains a half million
cycles or more at the cost of less than 200 bytes of code space.

FossilOrigin-Name: 7ad829224adbec5d74ff9e5ab040eb2ad3e17fe45da7a2cf0cca770a0731401a

manifest
manifest.uuid
src/btree.c

index 65aab7e507f394a35043d4e9e57e2e1e7e30101f..3c1e65c5d2464960c4c62b5e5151712cd5f8f07e 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Optimize\scalls\sto\sget2byte()\sin\sbtree.c\sfor\salmost\sa\sone-million\scycle\nperformance\sgain\sand\sa\sfew\sbytes\sless\scode.
-D 2022-02-23T18:23:15.914
+C Add\sa\snew\ssubclass\sfor\sMemPage.xCellSize\sspecifically\sfor\sthe\scase\sof\sa\sleaf\npage\sin\sa\sB+Tree,\sthat\sis\soptimized\sfor\sthat\scases.\s\sThis\sgains\sa\shalf\smillion\ncycles\sor\smore\sat\sthe\scost\sof\sless\sthan\s200\sbytes\sof\scode\sspace.
+D 2022-02-23T22:56:10.399
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -492,7 +492,7 @@ F src/auth.c f4fa91b6a90bbc8e0d0f738aa284551739c9543a367071f55574681e0f24f8cf
 F src/backup.c a2891172438e385fdbe97c11c9745676bec54f518d4447090af97189fd8e52d7
 F src/bitvec.c 7c849aac407230278445cb069bebc5f89bf2ddd87c5ed9459b070a9175707b3d
 F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6
-F src/btree.c 35870e7059b2b5bd90b0e1ac482b632b41a81dbb9b466bc7c9f3e4086571391c
+F src/btree.c 50a8f846a1cad4e903aa31afe94df6ec329ac0cafba12977dcb7fc8b076a57d0
 F src/btree.h 74d64b8f28cfa4a894d14d4ed64fa432cd697b98b61708d4351482ae15913e22
 F src/btreeInt.h 7282a6e77775f93a6eb78d3a41dab372a01a4ec1d93d3b4728d191d15fda42e2
 F src/build.c 9891c2160886cf7e344d7e8f1f7177f9612916c7c67ffeacd64cb34a92d387a8
@@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P ece326db50201937eb688809df39edc7fb97413b4614d2e2e783418192f7b02a
-R 1c57a2dcd8f8c477175cc03c1d736930
+P 41061f29969dc546c2702f7f412127070a4dd54593827692df93a83c939dfb61
+R 0695953d4b2e50c110a18d3aed9c37a6
 U drh
-Z 34e99039e8cc6255862cb2a477919b3e
+Z dd86536eafbb7b97b20458522e864263
 # Remove this line to create a well-formed Fossil manifest.
index 3d1ba050420c3816162a3d5d191cc0e02581f74b..56a9ce097222fa15fd71472f849738ace66d4aaf 100644 (file)
@@ -1 +1 @@
-41061f29969dc546c2702f7f412127070a4dd54593827692df93a83c939dfb61
\ No newline at end of file
+7ad829224adbec5d74ff9e5ab040eb2ad3e17fe45da7a2cf0cca770a0731401a
\ No newline at end of file
index 1d3acdc51d49b9faae78f372f289cf9a3394d164..25bf8eaf9b44076675dc3bd4dacbcd1c33a9e83e 100644 (file)
@@ -1327,6 +1327,7 @@ static void btreeParseCell(
 ** the space used by the cell pointer.
 **
 ** cellSizePtrNoPayload()    =>   table internal nodes
+** cellSizePtrTableLeaf()    =>   table leaf nodes
 ** cellSizePtr()             =>   all index nodes & table leaf nodes
 */
 static u16 cellSizePtr(MemPage *pPage, u8 *pCell){
@@ -1352,13 +1353,6 @@ static u16 cellSizePtr(MemPage *pPage, u8 *pCell){
     }while( *(pIter)>=0x80 && pIter<pEnd );
   }
   pIter++;
-  if( pPage->intKey ){
-    /* pIter now points at the 64-bit integer key value, a variable length 
-    ** integer. The following block moves pIter to point at the first byte
-    ** past the end of the key value. */
-    pEnd = &pIter[9];
-    while( (*pIter++)&0x80 && pIter<pEnd );
-  }
   testcase( nSize==pPage->maxLocal );
   testcase( nSize==(u32)pPage->maxLocal+1 );
   if( nSize<=pPage->maxLocal ){
@@ -1398,6 +1392,58 @@ static u16 cellSizePtrNoPayload(MemPage *pPage, u8 *pCell){
   assert( debuginfo.nSize==(u16)(pIter - pCell) || CORRUPT_DB );
   return (u16)(pIter - pCell);
 }
+static u16 cellSizePtrTableLeaf(MemPage *pPage, u8 *pCell){
+  u8 *pIter = pCell;   /* For looping over bytes of pCell */
+  u8 *pEnd;            /* End mark for a varint */
+  u32 nSize;           /* Size value to return */
+
+#ifdef SQLITE_DEBUG
+  /* The value returned by this function should always be the same as
+  ** the (CellInfo.nSize) value found by doing a full parse of the
+  ** cell. If SQLITE_DEBUG is defined, an assert() at the bottom of
+  ** this function verifies that this invariant is not violated. */
+  CellInfo debuginfo;
+  pPage->xParseCell(pPage, pCell, &debuginfo);
+#endif
+
+  nSize = *pIter;
+  if( nSize>=0x80 ){
+    pEnd = &pIter[8];
+    nSize &= 0x7f;
+    do{
+      nSize = (nSize<<7) | (*++pIter & 0x7f);
+    }while( *(pIter)>=0x80 && pIter<pEnd );
+  }
+  pIter++;
+  /* pIter now points at the 64-bit integer key value, a variable length 
+  ** integer. The following block moves pIter to point at the first byte
+  ** past the end of the key value. */
+  if( (*pIter++)&0x80
+   && (*pIter++)&0x80
+   && (*pIter++)&0x80
+   && (*pIter++)&0x80
+   && (*pIter++)&0x80
+   && (*pIter++)&0x80
+   && (*pIter++)&0x80
+   && (*pIter++)&0x80 ){ pIter++; }
+  testcase( nSize==pPage->maxLocal );
+  testcase( nSize==(u32)pPage->maxLocal+1 );
+  if( nSize<=pPage->maxLocal ){
+    nSize += (u32)(pIter - pCell);
+    if( nSize<4 ) nSize = 4;
+  }else{
+    int minLocal = pPage->minLocal;
+    nSize = minLocal + (nSize - minLocal) % (pPage->pBt->usableSize - 4);
+    testcase( nSize==pPage->maxLocal );
+    testcase( nSize==(u32)pPage->maxLocal+1 );
+    if( nSize>pPage->maxLocal ){
+      nSize = minLocal;
+    }
+    nSize += 4 + (u16)(pIter - pCell);
+  }
+  assert( nSize==debuginfo.nSize || CORRUPT_DB );
+  return (u16)nSize;
+}
 
 
 #ifdef SQLITE_DEBUG
@@ -1880,6 +1926,7 @@ static int decodeFlags(MemPage *pPage, int flagByte){
     pPage->intKey = 1;
     if( pPage->leaf ){
       pPage->intKeyLeaf = 1;
+      pPage->xCellSize = cellSizePtrTableLeaf;
       pPage->xParseCell = btreeParseCellPtr;
     }else{
       pPage->intKeyLeaf = 0;
@@ -9310,7 +9357,7 @@ int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
   bPreserve = (flags & BTREE_SAVEPOSITION)!=0;
   if( bPreserve ){
     if( !pPage->leaf 
-     || (pPage->nFree+cellSizePtr(pPage,pCell)+2)>(int)(pBt->usableSize*2/3)
+     || (pPage->nFree+pPage->xCellSize(pPage,pCell)+2)>(int)(pBt->usableSize*2/3)
      || pPage->nCell==1  /* See dbfuzz001.test for a test case */
     ){
       /* A b-tree rebalance will be required after deleting this entry.