From: drh <> Date: Sat, 30 Apr 2022 17:22:22 +0000 (+0000) Subject: Fix another problem with subroutine reuse in the RIGHT JOIN no-match code X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fheads%2Fnot-working;p=thirdparty%2Fsqlite.git Fix another problem with subroutine reuse in the RIGHT JOIN no-match code for the subquery on the right-hand side of an IN operator. The current code works for all known cases, but seems unnecessarily complex and in need of simplification. FossilOrigin-Name: ad32da8045e691372871a05ca49688032e9c2bab769a07da6b6cfd6186d25955 --- diff --git a/manifest b/manifest index 57c9658d48..34937ca48a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Preserve\sthe\sCOLLATE\soperator\son\san\sindex\son\san\sexpression\swhen\sresolving\nthe\suse\sof\sthat\sexpression\sinto\sa\sreference\sto\sthe\sindex.\s\sSee\n[forum:/info/7efabf4b03328e57|forum\sthread\s7efabf4b03328e57]\sfor\sdetails. -D 2022-04-30T12:35:51.942 +C Fix\sanother\sproblem\swith\ssubroutine\sreuse\sin\sthe\sRIGHT\sJOIN\sno-match\scode\nfor\sthe\ssubquery\son\sthe\sright-hand\sside\sof\san\sIN\soperator.\s\sThe\scurrent\scode\nworks\sfor\sall\sknown\scases,\sbut\sseems\sunnecessarily\scomplex\sand\sin\sneed\sof\nsimplification. +D 2022-04-30T17:22:22.048 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -626,10 +626,10 @@ F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0 F src/util.c 602fe229f32a96ceccae4f40824129669582096f7c355f53dbac156c9fecef23 F src/vacuum.c 6c38ddc52f0619865c91dae9c441d4d48bf3040d7dc1bc5b22da1e45547ed0b3 F src/vdbe.c 9527ab7f71c5b0291e5ed7727f213f4d7f6e0a82af019da5b365fd5a0f56bb96 -F src/vdbe.h 07641758ca8b4f4c6d81ea667ea167c541e6ece21f5574da11e3d21ec37e2662 +F src/vdbe.h 76eb1b3d84173e7f39fa236c03537aacdb53bc0c7ce21d8fd10cf1be9830ffe6 F src/vdbeInt.h ef43f7fdc5fde29fc3fd29c506c12830f366178fdb4edbbf0cbc3dfbd1278b5f F src/vdbeapi.c 354c893f1500cf524cc45c32879b9c68893a28b77e3442c24668d6afe4236217 -F src/vdbeaux.c f406d8d8b461f260aeaa69d265c5d175ff0a9f84d6153c87975cdfbf9d681922 +F src/vdbeaux.c 9279cb71557235d6bf0fcda139a1c8a773ad5542bcec27c6591320cc9027970f F src/vdbeblob.c 5e61ce31aca17db8fb60395407457a8c1c7fb471dde405e0cd675974611dcfcd F src/vdbemem.c 7189090b72baa025f945a1ac8c61ee420c645254476e8a191d555db76dfea5d4 F src/vdbesort.c 43756031ca7430f7aec3ef904824a7883c4ede783e51f280d99b9b65c0796e35 @@ -642,7 +642,7 @@ F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b F src/where.c 43085b3a4ce2e56315fabb0b240a56e76667d9e03c79f287695bcae7b76152d5 F src/whereInt.h 4db5a877a9d1f38b5c928c1c84297c07f30b9a3bc1f5f66214cf1a8ef90a0556 -F src/wherecode.c 3c6f6ff594edb6eb3d7d38b9b922e43dcd15b31949718acbb4d6b51a66fef509 +F src/wherecode.c 96b342445146c0352a55924d9c3509b66b6284fa246dd276ca7599cf4637ab50 F src/whereexpr.c 174d4ad5be165c610c907abb779ef4a97974d22b84e1ce7898d2d9f6947249e5 F src/window.c 924e04fd6e0e113d4dba18b78d43fcb8e42b8ebffc8fc728da52cf3ab014cf3c F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 @@ -1148,7 +1148,7 @@ F test/join4.test 1a352e4e267114444c29266ce79e941af5885916 F test/join5.test c4df54e2e204d7f1417bfbdd21ca324b4b07415c647595cc47798eacfddc96d3 F test/join6.test f809c025fa253f9e150c0e9afd4cef8813257bceeb6f46e04041228c9403cc2c F test/join7.test 8e72de4b45e5e930d18c305c7efe86015fb2552731e4e03ea226353036b0dab0 -F test/join8.test ecb51527fa3dedea1b9e816b1bc5a9effe73894bd3630936716ee5983dd99081 +F test/join8.test 9a4b2f53d5358abb29e6356e357c0cd40f4d8f282589300dcb76728dce050b51 F test/join9.test 9056ddd3b0c0f4f9d658f4521038d9a37dc23ead8ca9a505d0b0db2b6a471e05 F test/joinA.test 7eab225dc1c1ab258a5e62513a4ed7cabbd3db971d59d5d92f4fb6fa14c12f6a F test/joinB.test 1b2ba3fc8568b49411787fccbf540570c148e9b6a53a30f80691cb6268098ded @@ -1951,8 +1951,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 bb2798be3fb5737827eec505db2d4c8cb510d227d98fc26ce748bf2da7e8b382 -R 8ae07a550172cb86bf694a85b364f3bb +P a8da85c57e07721dc1c918d67433d6c99ce48421e369123cc3194d855e55f7e8 +R e3fbc3d41c1e378863d3a3844f4d4b19 U drh -Z 620a3ae79bd73fe692219fff192dc087 +Z 429a0d8657da0ac87e9e33fefb72e33d # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 375ab1598b..ac8b5e7e54 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a8da85c57e07721dc1c918d67433d6c99ce48421e369123cc3194d855e55f7e8 \ No newline at end of file +ad32da8045e691372871a05ca49688032e9c2bab769a07da6b6cfd6186d25955 \ No newline at end of file diff --git a/src/vdbe.h b/src/vdbe.h index 5909d3995d..fd93fb7aee 100644 --- a/src/vdbe.h +++ b/src/vdbe.h @@ -232,6 +232,7 @@ void sqlite3VdbeJumpHere(Vdbe*, int addr); void sqlite3VdbeJumpHereOrPopInst(Vdbe*, int addr); int sqlite3VdbeChangeToNoop(Vdbe*, int addr); int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op); +void sqlite3VdbeUndoBackTo(Vdbe*, int addr); #ifdef SQLITE_DEBUG void sqlite3VdbeReleaseRegisters(Parse*,int addr, int n, u32 mask, int); #else diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 9e702edcd5..7e0549fecf 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -1303,6 +1303,22 @@ int sqlite3VdbeDeletePriorOpcode(Vdbe *p, u8 op){ } } +/* +** Undo all opcode inserts so that addr is the last opcode. +*/ +void sqlite3VdbeUndoBackTo(Vdbe *p, int addr){ + while( p->nOp>addr ){ +#ifdef SQLITE_DEBUG + if( p->db->flags & SQLITE_VdbeAddopTrace ){ + printf("UNDO: "); + sqlite3VdbePrintOp(0, p->nOp-1, &p->aOp[p->nOp-1]); + } +#endif + sqlite3VdbeChangeToNoop(p, p->nOp-1); + p->nOp--; + } +} + #ifdef SQLITE_DEBUG /* ** Generate an OP_ReleaseReg opcode to indicate that a range of diff --git a/src/wherecode.c b/src/wherecode.c index 0d6030793a..f212258a62 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -619,14 +619,16 @@ static int codeEqualityTerm( aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq); eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap,&iTab); pExpr->iTable = iTab; - pExpr->op2 = eType; } sqlite3ExprDelete(db, pX); }else{ - sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn, - pExpr->y.sub.iAddr); + int j1; + j1 = sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn, + pExpr->y.sub.iAddr); + aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq); + eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap,&iTab); iTab = pExpr->iTable; - eType = pExpr->op2; + sqlite3VdbeUndoBackTo(v, j1+1); } pX = pExpr; } diff --git a/test/join8.test b/test/join8.test index ca362d7333..a33622d9bb 100644 --- a/test/join8.test +++ b/test/join8.test @@ -172,5 +172,12 @@ do_execsql_test join8-6010 { SELECT value, t1.* FROM json_each('7') NATURAL RIGHT JOIN t1 WHERE (a,b) IN (SELECT a, b FROM t1); } {7 15 xray baker 42} +do_execsql_test join8-6020 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(a INTEGER PRIMARY KEY,b); + INSERT INTO t1 VALUES(0,NULL),(1,2); + SELECT value, t1.* FROM json_each('17') NATURAL RIGHT JOIN t1 + WHERE (a,b) IN (SELECT rowid, b FROM t1); +} {17 1 2} finish_test