/ Check-in [59560d07]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Performance optimization to pageFindSlot() in the b-tree layer.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 59560d079fab4b91ec50855cc60349da178209c38fb6dae674ff874ccfc7f5fa
User & Date: drh 2017-08-23 23:09:03
References
2017-08-25
13:02
Convert a branch made unreachable by [59560d07] into an assert(). check-in: 2738b8db user: drh tags: trunk
Context
2017-08-24
13:55
Make sure the sqlite3_result_pointer() interface does not leave a VM register in an inconsistent state. Fix for ticket [7486aa54b968e9b5]. Test cases are in TH3. check-in: d2f9230c user: drh tags: trunk
2017-08-23
23:09
Performance optimization to pageFindSlot() in the b-tree layer. check-in: 59560d07 user: drh tags: trunk
20:36
Size and performance optimization to dropCell() and freeSpace(). check-in: bc1ec123 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

  1484   1484   static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){
  1485   1485     const int hdr = pPg->hdrOffset;
  1486   1486     u8 * const aData = pPg->aData;
  1487   1487     int iAddr = hdr + 1;
  1488   1488     int pc = get2byte(&aData[iAddr]);
  1489   1489     int x;
  1490   1490     int usableSize = pPg->pBt->usableSize;
         1491  +  int size;            /* Size of the free slot */
  1491   1492   
  1492   1493     assert( pc>0 );
  1493         -  do{
  1494         -    int size;            /* Size of the free slot */
  1495         -    /* EVIDENCE-OF: R-06866-39125 Freeblocks are always connected in order of
  1496         -    ** increasing offset. */
  1497         -    if( pc>usableSize-4 || pc<iAddr+4 ){
  1498         -      *pRc = SQLITE_CORRUPT_PGNO(pPg->pgno);
  1499         -      return 0;
  1500         -    }
         1494  +  while( pc<=usableSize-4 ){
  1501   1495       /* EVIDENCE-OF: R-22710-53328 The third and fourth bytes of each
  1502   1496       ** freeblock form a big-endian integer which is the size of the freeblock
  1503   1497       ** in bytes, including the 4-byte header. */
  1504   1498       size = get2byte(&aData[pc+2]);
  1505   1499       if( (x = size - nByte)>=0 ){
  1506   1500         testcase( x==4 );
  1507   1501         testcase( x==3 );
................................................................................
  1522   1516            ** for the portion used by the new allocation. */
  1523   1517           put2byte(&aData[pc+2], x);
  1524   1518         }
  1525   1519         return &aData[pc + x];
  1526   1520       }
  1527   1521       iAddr = pc;
  1528   1522       pc = get2byte(&aData[pc]);
  1529         -  }while( pc );
         1523  +    if( pc<iAddr+size ) break;
         1524  +  }
         1525  +  if( pc ){
         1526  +    *pRc = SQLITE_CORRUPT_PGNO(pPg->pgno);
         1527  +  }
  1530   1528   
  1531   1529     return 0;
  1532   1530   }
  1533   1531   
  1534   1532   /*
  1535   1533   ** Allocate nByte bytes of space from within the B-Tree page passed
  1536   1534   ** as the first argument. Write into *pIdx the index into pPage->aData[]