]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Optimizations to the OP_Found opcode save about 600K cycles in speedtest1.
authordrh <>
Mon, 4 Apr 2022 19:43:57 +0000 (19:43 +0000)
committerdrh <>
Mon, 4 Apr 2022 19:43:57 +0000 (19:43 +0000)
FossilOrigin-Name: 5c3357ad62843fe982b9c2d31dbf02018f2948ceab2c85dac917cd9ce1e97dd6

manifest
manifest.uuid
src/vdbe.c

index 6c7b5741fe172fe31683077a574db5cdb71713dd..911821ee8f420f17e9d2cba8c565ad4ebdd0ee0e 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Use\sunpacked\skeys\sfor\sOP_Found\sin\sforeign\skey\sprocessing.
-D 2022-04-04T18:17:59.858
+C Optimizations\sto\sthe\sOP_Found\sopcode\ssave\sabout\s600K\scycles\sin\sspeedtest1.
+D 2022-04-04T19:43:57.944
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -624,7 +624,7 @@ F src/upsert.c 8789047a8f0a601ea42fa0256d1ba3190c13746b6ba940fe2d25643a7e991937
 F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0
 F src/util.c 602fe229f32a96ceccae4f40824129669582096f7c355f53dbac156c9fecef23
 F src/vacuum.c 6c38ddc52f0619865c91dae9c441d4d48bf3040d7dc1bc5b22da1e45547ed0b3
-F src/vdbe.c c6e546c9d1ade8e253f54476263d669b2f9af2f57c9de113b1a1096575cfa36e
+F src/vdbe.c 61ff67a29b89214c928631be206af9cb5f820ed46b8cec3e58308fea205123e4
 F src/vdbe.h 89f5edb1422c8783a0b29db836e409876f2b3e847f78e2b21b1fbcc48a93f85f
 F src/vdbeInt.h 5f3d0abcf30c2b7a6672ad4386f18be0fca9c9b2cefe18f85a2e3df74f2613bf
 F src/vdbeapi.c 354c893f1500cf524cc45c32879b9c68893a28b77e3442c24668d6afe4236217
@@ -1945,8 +1945,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 0fbbe7881cadf0b3c211653c7a0797e0a90c7c24da78ecc8a27140c05f89f2ed
-R 98b3d21b59eb71e092a0c493cf5ae5c8
+P 328dc76657eb5317f0201859d2b3abe6918103b894f7beaed0aca3058a9f2b64
+R ac8b3e120e5046f4e8f53f05766d7e6a
 U drh
-Z fe844f2684caa7d8abe26eb99432eaf4
+Z 8545e3f2f52a7362bf82a3c0cf610720
 # Remove this line to create a well-formed Fossil manifest.
index a2be00456663886fdf40ddb5c0a27069937adae7..a05f745f93cf328fb2beef5b39c5d8d1fe59a5d6 100644 (file)
@@ -1 +1 @@
-328dc76657eb5317f0201859d2b3abe6918103b894f7beaed0aca3058a9f2b64
\ No newline at end of file
+5c3357ad62843fe982b9c2d31dbf02018f2948ceab2c85dac917cd9ce1e97dd6
\ No newline at end of file
index e7343e820787ec29743bbb98d66825070e93128f..c29198f747689f11714fd2745a5a17943b4e38ea 100644 (file)
@@ -4966,11 +4966,9 @@ case OP_NoConflict:     /* jump, in3 */
 case OP_NotFound:       /* jump, in3 */
 case OP_Found: {        /* jump, in3 */
   int alreadyExists;
-  int takeJump;
   int ii;
   VdbeCursor *pC;
   int res;
-  UnpackedRecord *pFree;
   UnpackedRecord *pIdxKey;
   UnpackedRecord r;
 
@@ -4990,9 +4988,11 @@ case OP_Found: {        /* jump, in3 */
   assert( pC->uc.pCursor!=0 );
   assert( pC->isTable==0 );
   if( pOp->p4.i>0 ){
-    r.pKeyInfo = pC->pKeyInfo;
+    /* Key values in an array of registers */
     r.nField = (u16)pOp->p4.i;
+    r.pKeyInfo = pC->pKeyInfo;
     r.aMem = pIn3;
+    r.default_rc = 0;
 #ifdef SQLITE_DEBUG
     for(ii=0; ii<r.nField; ii++){
       assert( memIsValid(&r.aMem[ii]) );
@@ -5000,32 +5000,21 @@ case OP_Found: {        /* jump, in3 */
       if( ii ) REGISTER_TRACE(pOp->p3+ii, &r.aMem[ii]);
     }
 #endif
-    pIdxKey = &r;
-    pFree = 0;
+    rc = sqlite3BtreeIndexMoveto(pC->uc.pCursor, &r, &res);
   }else{
+    /* Composite key generated by OP_MakeRecord */
     assert( pIn3->flags & MEM_Blob );
+    assert( pOp->opcode!=OP_NoConflict );
     rc = ExpandBlob(pIn3);
     assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );
     if( rc ) goto no_mem;
-    pFree = pIdxKey = sqlite3VdbeAllocUnpackedRecord(pC->pKeyInfo);
+    pIdxKey = sqlite3VdbeAllocUnpackedRecord(pC->pKeyInfo);
     if( pIdxKey==0 ) goto no_mem;
     sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
+    pIdxKey->default_rc = 0;
+    rc = sqlite3BtreeIndexMoveto(pC->uc.pCursor, pIdxKey, &res);
+    sqlite3DbFreeNN(db, pIdxKey);
   }
-  pIdxKey->default_rc = 0;
-  takeJump = 0;
-  if( pOp->opcode==OP_NoConflict ){
-    /* For the OP_NoConflict opcode, take the jump if any of the
-    ** input fields are NULL, since any key with a NULL will not
-    ** conflict */
-    for(ii=0; ii<pIdxKey->nField; ii++){
-      if( pIdxKey->aMem[ii].flags & MEM_Null ){
-        takeJump = 1;
-        break;
-      }
-    }
-  }
-  rc = sqlite3BtreeIndexMoveto(pC->uc.pCursor, pIdxKey, &res);
-  if( pFree ) sqlite3DbFreeNN(db, pFree);
   if( rc!=SQLITE_OK ){
     goto abort_due_to_error;
   }
@@ -5038,9 +5027,25 @@ case OP_Found: {        /* jump, in3 */
     VdbeBranchTaken(alreadyExists!=0,2);
     if( alreadyExists ) goto jump_to_p2;
   }else{
-    VdbeBranchTaken(takeJump||alreadyExists==0,2);
-    if( takeJump || !alreadyExists ) goto jump_to_p2;
-    if( pOp->opcode==OP_IfNoHope ) pC->seekHit = pOp->p4.i;
+    if( !alreadyExists ){
+      VdbeBranchTaken(1,2);
+      goto jump_to_p2;
+    }
+    if( pOp->opcode==OP_NoConflict ){
+      /* For the OP_NoConflict opcode, take the jump if any of the
+      ** input fields are NULL, since any key with a NULL will not
+      ** conflict */
+      for(ii=0; ii<r.nField; ii++){
+        if( r.aMem[ii].flags & MEM_Null ){
+          VdbeBranchTaken(1,2);
+          goto jump_to_p2;
+        }
+      }
+    }
+    VdbeBranchTaken(0,2);
+    if( pOp->opcode==OP_IfNoHope ){
+      pC->seekHit = pOp->p4.i;
+    }
   }
   break;
 }