]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
If a subquery is used to drive an index, this change avoids making an extra copy-optimization
authordrh <>
Fri, 28 May 2021 14:28:54 +0000 (14:28 +0000)
committerdrh <>
Fri, 28 May 2021 14:28:54 +0000 (14:28 +0000)
copy of the result of that subquery.  But, such situations are probably
sufficiently unusual that the added complexity of this enhancement is not
worth the performance gain.  So I'm going to park this check-in on a branch.
If we later find a use case to justify it, we can merge it to trunk then.
This is the "further change" that was promised by the prior check-in comment.

FossilOrigin-Name: 4488cb883e155a7466946d25569ab2816c4a8de9d4c7d540f5053ea5334e7ae5

manifest
manifest.uuid
src/wherecode.c

index cc15943c16ef84e9b9a1da04341d871d2d872265..37759ca1d8f69ac884d920cd3b80b2a9a3544b8a 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Make\sa\sdeep\scopy\sof\sthe\sresult\sof\sa\ssubquery\sin\scase\sthe\ssubquery\sis\nreused.\s\sFix\sfor\sthe\sproblem\sreported\sby\n[forum:/forumpost/28216b36ac|forum\spost\s28216b36ac]\sand\sintroduced\sby\ncheck-in\s[f30fb19ff763a7cb].\s\sFurther\schanges\sto\stry\sto\soptimize\sthe\snew\nOP_Copy\sopcode\sback\sinto\seither\sOP_SCopy\sor\sOP_Move\swill\sbe\sattempted\nseparately.\s\sA\stest\scase\swill\sbe\sin\sTH3.
-D 2021-05-28T12:48:31.685
+C If\sa\ssubquery\sis\sused\sto\sdrive\san\sindex,\sthis\schange\savoids\smaking\san\sextra\ncopy\sof\sthe\sresult\sof\sthat\ssubquery.\s\sBut,\ssuch\ssituations\sare\sprobably\nsufficiently\sunusual\sthat\sthe\sadded\scomplexity\sof\sthis\senhancement\sis\snot\nworth\sthe\sperformance\sgain.\s\sSo\sI'm\sgoing\sto\spark\sthis\scheck-in\son\sa\sbranch.\nIf\swe\slater\sfind\sa\suse\scase\sto\sjustify\sit,\swe\scan\smerge\sit\sto\strunk\sthen.\nThis\sis\sthe\s"further\schange"\sthat\swas\spromised\sby\sthe\sprior\scheck-in\scomment.
+D 2021-05-28T14:28:54.261
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -633,7 +633,7 @@ F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a
 F src/walker.c 7342becedf3f8a26f9817f08436bdf8b56ad69af83705f6b9320a0ad3092c2ac
 F src/where.c 32f41c3c93c6785e0077e3a2cdc669c3ccfe70173787847be77f294c18fc7dc3
 F src/whereInt.h 9248161dd004f625ce5d3841ca9b99fed3fc8d61522cf76340fc5217dbe1375b
-F src/wherecode.c 9f1f65d11437b25cd0a1497a170514c785f19ce6ad9d3e6fc73719cb5a49012f
+F src/wherecode.c bcfee3789a7d3da1f3f8a76c1b20c95d6c0fc4ea93c5d9b03206a432ac8b1cc4
 F src/whereexpr.c 5a9c9f5d2dac4bcdcaae3035034b4667523f731df228e0bb1d4efc669efa9da5
 F src/window.c a6d624d83b2d5b3cfb82bb437a2fbae759c928d47dc9ad1338a9419269181bb2
 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
@@ -1918,7 +1918,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 21676731cedae27d1ab9fe62b269001ae6e3eeb3caa87b4f5536f777631a8bbc
-R 77e951a6e7b5327d1f646c5968da6983
+P c9f0b9cb0aef107265435e22c164dd3c974eadfd00abf7cfd4fc7ec95c0dd7d0
+R c044497982752ba303617f7de106b59c
+T *branch * copy-optimization
+T *sym-copy-optimization *
+T -sym-trunk *
 U drh
-Z 20c9ad1ef6610380252081cdda3138d3
+Z 0c06d6f1ffda88b03d3d1e66ad233058
index f8745ea2ba30c4a9ca660ae23d9f20cb3f3d6bae..121f771c64a05e028e6f2ea74c23800f28007350 100644 (file)
@@ -1 +1 @@
-c9f0b9cb0aef107265435e22c164dd3c974eadfd00abf7cfd4fc7ec95c0dd7d0
\ No newline at end of file
+4488cb883e155a7466946d25569ab2816c4a8de9d4c7d540f5053ea5334e7ae5
\ No newline at end of file
index 84fa1a14108e8c7cb37f38f44e25e36579f1a33e..18f79e33e13235f303cfeef4394298b590a21c31 100644 (file)
@@ -752,11 +752,16 @@ static int codeAllEqualityTerms(
     testcase( pTerm->wtFlags & TERM_VIRTUAL );
     r1 = codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, regBase+j);
     if( r1!=regBase+j ){
+      assert( pTerm->pExpr->op==TK_EQ || pTerm->pExpr->op==TK_IS );
       if( nReg==1 ){
         sqlite3ReleaseTempReg(pParse, regBase);
         regBase = r1;
       }else{
-        sqlite3VdbeAddOp2(v, OP_Copy, r1, regBase+j);
+        if( ExprHasProperty(pTerm->pExpr->pRight, EP_VarSelect) ){
+          sqlite3VdbeAddOp3(v, OP_Move, r1, regBase+j, 1);
+        }else{
+          sqlite3VdbeAddOp2(v, OP_SCopy, r1, regBase+j);
+        }
       }
     }
     if( pTerm->eOperator & WO_IN ){