]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Performance improvements in sqlite3BtreeMovetoUnpacked().
authordrh <drh@noemail.net>
Mon, 25 Nov 2013 02:38:55 +0000 (02:38 +0000)
committerdrh <drh@noemail.net>
Mon, 25 Nov 2013 02:38:55 +0000 (02:38 +0000)
FossilOrigin-Name: d0fb7acea7cbfe6f2d84782a28bb51675a06576f

manifest
manifest.uuid
src/btree.c

index aa2b98cdb9dbbcea930fb1b72d4ba90f8d8243c8..4b817f5f32938f4e509236b9b279964f637ab98c 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\sthe\s--scratch\sparameter\sto\sspeedtest1.\s\sImproved\serror\smessages\swhen\nmisconfiguring\smemory\sparameters\sin\sspeedtest1.
-D 2013-11-24T01:14:14.123
+C Performance\simprovements\sin\ssqlite3BtreeMovetoUnpacked().
+D 2013-11-25T02:38:55.810
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in e1a9b4258bbde53f5636f4e238c65b7e11459e2b
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -166,7 +166,7 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34
 F src/backup.c 1809a7caa2504233bdddd12f5018422421789537
 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb
 F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7
-F src/btree.c 17ca5729d07ba03f81633aab56de87956d9b188a
+F src/btree.c b0fd869c044bbf29640b9e53c43d8846a929d7f4
 F src/btree.h a61ddebc78c66795a2b93181321a116746302cc9
 F src/btreeInt.h f038e818bfadf75afbd09819ed93c26a333d39e0
 F src/build.c 07054d45319953e54a89d726e589a423e9c1c590
@@ -1142,7 +1142,10 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
-P 12e612e8e7c4a6f83acf0daf5608151fb5ec1575
-R d231270eb8540c71c1fe43ad7f945ecf
+P 8f3c767a30c552548ead104ca125f182ce4849ad
+R c168ba651eff475cfa32f75aa61b62eb
+T *branch * btree-optimization
+T *sym-btree-optimization *
+T -sym-trunk *
 U drh
-Z 904197ecb3cb4ac430a652007d0a071c
+Z f59a524da90eada9da104b9026589d30
index 7967f97b83844b27753b2883867579a4ca03f53a..0597b2d1cd30a1fb812139562dae064f673b0b04 100644 (file)
@@ -1 +1 @@
-8f3c767a30c552548ead104ca125f182ce4849ad
\ No newline at end of file
+d0fb7acea7cbfe6f2d84782a28bb51675a06576f
\ No newline at end of file
index 2a5b45e5c6b408a8779783fa5d7caffc7e326f8d..a21b72a0daff0411f0b37d96b31472c1eb66106a 100644 (file)
@@ -4647,10 +4647,10 @@ int sqlite3BtreeMovetoUnpacked(
   }
   assert( pCur->apPage[0]->intKey || pIdxKey );
   for(;;){
-    int lwr, upr, idx;
+    int lwr, upr, idx, c;
     Pgno chldPg;
     MemPage *pPage = pCur->apPage[pCur->iPage];
-    int c;
+    u8 *pCell;                          /* Pointer to current cell in pPage */
 
     /* pPage->nCell must be greater than zero. If this is the root-page
     ** the cursor would have been INVALID above and this for(;;) loop
@@ -4667,30 +4667,45 @@ int sqlite3BtreeMovetoUnpacked(
     }else{
       pCur->aiIdx[pCur->iPage] = (u16)(idx = (upr+lwr)/2);
     }
-    for(;;){
-      u8 *pCell;                          /* Pointer to current cell in pPage */
-
+    pCur->info.nSize = 0;
+    if( pPage->intKey ){
       assert( idx==pCur->aiIdx[pCur->iPage] );
-      pCur->info.nSize = 0;
-      pCell = findCell(pPage, idx) + pPage->childPtrSize;
-      if( pPage->intKey ){
+      for(;;){
         i64 nCellKey;
+        pCell = findCell(pPage, idx) + pPage->childPtrSize;
         if( pPage->hasData ){
           u32 dummy;
           pCell += getVarint32(pCell, dummy);
         }
         getVarint(pCell, (u64*)&nCellKey);
         if( nCellKey==intKey ){
-          c = 0;
+          pCur->validNKey = 1;
+          pCur->info.nKey = nCellKey;
+          if( !pPage->leaf ){
+            lwr = idx;
+            break;
+          }else{
+            *pRes = 0;
+            rc = SQLITE_OK;
+            goto moveto_finish;
+          }
         }else if( nCellKey<intKey ){
           c = -1;
+          lwr = idx+1;
         }else{
           assert( nCellKey>intKey );
           c = +1;
+          upr = idx-1;
         }
-        pCur->validNKey = 1;
-        pCur->info.nKey = nCellKey;
-      }else{
+        if( lwr>upr ) break;
+        pCur->aiIdx[pCur->iPage] = (u16)(idx = (lwr+upr)/2);
+      }
+    }else{
+      for(;;){
+        int nCell;
+        assert( idx==pCur->aiIdx[pCur->iPage] );
+        pCell = findCell(pPage, idx) + pPage->childPtrSize;
+
         /* The maximum supported page-size is 65536 bytes. This means that
         ** the maximum number of record bytes stored on an index B-Tree
         ** page is less than 16384 bytes and may be stored as a 2-byte
@@ -4699,7 +4714,7 @@ int sqlite3BtreeMovetoUnpacked(
         ** stored entirely within the b-tree page by inspecting the first 
         ** 2 bytes of the cell.
         */
-        int nCell = pCell[0];
+        nCell = pCell[0];
         if( nCell<=pPage->max1bytePayload
          /* && (pCell+nCell)<pPage->aDataEnd */
         ){
@@ -4738,47 +4753,37 @@ int sqlite3BtreeMovetoUnpacked(
           c = sqlite3VdbeRecordCompare(nCell, pCellKey, pIdxKey);
           sqlite3_free(pCellKey);
         }
-      }
-      if( c==0 ){
-        if( pPage->intKey && !pPage->leaf ){
-          lwr = idx;
-          break;
-        }else{
+        if( c==0 ){
           *pRes = 0;
           rc = SQLITE_OK;
           goto moveto_finish;
         }
+        if( c<0 ){
+          lwr = idx+1;
+        }else{
+          upr = idx-1;
+        }
+        if( lwr>upr ) break;
+        pCur->aiIdx[pCur->iPage] = (u16)(idx = (lwr+upr)/2);
       }
-      if( c<0 ){
-        lwr = idx+1;
-      }else{
-        upr = idx-1;
-      }
-      if( lwr>upr ){
-        break;
-      }
-      pCur->aiIdx[pCur->iPage] = (u16)(idx = (lwr+upr)/2);
     }
     assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
     assert( pPage->isInit );
     if( pPage->leaf ){
-      chldPg = 0;
-    }else if( lwr>=pPage->nCell ){
-      chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
-    }else{
-      chldPg = get4byte(findCell(pPage, lwr));
-    }
-    if( chldPg==0 ){
       assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
       *pRes = c;
       rc = SQLITE_OK;
       goto moveto_finish;
+    }else if( lwr>=pPage->nCell ){
+      chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
+    }else{
+      chldPg = get4byte(findCell(pPage, lwr));
     }
     pCur->aiIdx[pCur->iPage] = (u16)lwr;
     pCur->info.nSize = 0;
     pCur->validNKey = 0;
     rc = moveToChild(pCur, chldPg);
-    if( rc ) goto moveto_finish;
+    if( rc ) break;
   }
 moveto_finish:
   return rc;