From: drh <> Date: Mon, 30 May 2022 17:33:22 +0000 (+0000) Subject: For an outer join, then ON-clause constraints need to be evaluated at just X-Git-Tag: version-3.39.0~80 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=404bf6bac6569664b23a35c22fbb18611b7c6b7c;p=thirdparty%2Fsqlite.git For an outer join, then ON-clause constraints need to be evaluated at just the right moment - not too early and not too late. Fix for the problem reported by [forum:/forumpost/3902c7b833|forum post 3902c7b833]. FossilOrigin-Name: 3869fd9a2b9483cbbf83d8f369c1744abc42f12e63abba402be35dd7e136161c --- diff --git a/manifest b/manifest index e804cf0c3a..417206cf1b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Apply\sthe\sUPDATE-FROM\sfile\sfrom\scheck-in\s[98b3816bbaf539ea]\sto\nupdate-delete-limit\sbuilds. -D 2022-05-28T14:03:23.844 +C For\san\souter\sjoin,\sthen\sON-clause\sconstraints\sneed\sto\sbe\sevaluated\sat\sjust\nthe\sright\smoment\s-\snot\stoo\searly\sand\snot\stoo\slate.\s\sFix\sfor\sthe\sproblem\nreported\sby\s[forum:/forumpost/3902c7b833|forum\spost\s3902c7b833]. +D 2022-05-30T17:33:22.759 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -656,7 +656,7 @@ F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b F src/where.c c4b64c6fa224e5b89ed547ec0ebdfd243c081509b195e71581164a2fbb8d4a80 F src/whereInt.h 8da918f392bf202ccc0ee61291455b33ad171d209445f1ff3eaf62e0b6f6b363 -F src/wherecode.c 2a8a73bcf1886632f2b2247c79395f94852a4b74484d8aa70a005892ce73d339 +F src/wherecode.c 056c96e617cbd3cebcbf68b80f85f2a8ad3e7aa6dbbe53cdd7bf25982f06a950 F src/whereexpr.c 7c5ee52e1df81d6a43f39e6b6f35d540fd37254e2b6e953a4e2715c3abf26f46 F src/window.c fff1b51757438c664e471d5184634e48dcdf8ea34b640f3b1b0810b1e06de18c F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 @@ -1163,7 +1163,7 @@ F test/join4.test 1a352e4e267114444c29266ce79e941af5885916 F test/join5.test d22b6cba8fb59ab3f1c82701434c360705eb12d4ce200c449f37b018fc47681a F test/join6.test f809c025fa253f9e150c0e9afd4cef8813257bceeb6f46e04041228c9403cc2c F test/join7.test 8e72de4b45e5e930d18c305c7efe86015fb2552731e4e03ea226353036b0dab0 -F test/join8.test 616eb7c2e4f2a54f2d730b914884d2205c8ada4757e89d08089255964a28e78e +F test/join8.test 9c07b41876dacb66b8152e26a6b1c94dd2d0ffd640596364b722ea0915544ea1 F test/join9.test 9056ddd3b0c0f4f9d658f4521038d9a37dc23ead8ca9a505d0b0db2b6a471e05 F test/joinA.test 7eab225dc1c1ab258a5e62513a4ed7cabbd3db971d59d5d92f4fb6fa14c12f6a F test/joinB.test 1b2ba3fc8568b49411787fccbf540570c148e9b6a53a30f80691cb6268098ded @@ -1970,8 +1970,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 fd668da5ccf037c2ad8e61e381dd1eb398a8deab42a00593e551c30bd176890d -R e62d67531970b1619ea2f47c2f8c0901 +P 7e87892c249f023ee9ed1d5f75a9ad8db10fb38f14dd9e6954b12b9b28400b07 +R d8c6c49a6f81ad2009470ac7c17ba847 U drh -Z 2f27046509ba92f24780e3263d6632b0 +Z 80024066eaca77187100e3cf4923e7b2 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a331df2c16..95ab423223 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7e87892c249f023ee9ed1d5f75a9ad8db10fb38f14dd9e6954b12b9b28400b07 \ No newline at end of file +3869fd9a2b9483cbbf83d8f369c1744abc42f12e63abba402be35dd7e136161c \ No newline at end of file diff --git a/src/wherecode.c b/src/wherecode.c index 3902c24f95..6617b60396 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -2624,12 +2624,9 @@ Bitmask sqlite3WhereCodeOneLoopStart( /* Defer processing WHERE clause constraints until after outer ** join processing. tag-20220513a */ continue; - }else{ - Bitmask m = sqlite3WhereGetMask(&pWInfo->sMaskSet, pE->w.iJoin); - if( m & pLevel->notReady ){ - /* An ON clause that is not ripe */ - continue; - } + }else if( (pTabItem->fg.jointype & JT_LEFT)==JT_LEFT + && !ExprHasProperty(pE,EP_OuterON) ){ + continue; } } if( iLoop==1 && !sqlite3ExprCoveredByIndex(pE, pLevel->iTabCur, pIdx) ){ diff --git a/test/join8.test b/test/join8.test index cccb167ac1..554f04562d 100644 --- a/test/join8.test +++ b/test/join8.test @@ -445,4 +445,41 @@ do_execsql_test join8-14020 { - 2 4 } +# 2022-05-30 +# https://sqlite.org/forum/forumpost/3902c7b833 +# +reset_db +do_execsql_test join8-15000 { + CREATE TABLE t1(x INT); + CREATE TABLE t2(y INT); + CREATE TABLE t3(z INT); + INSERT INTO t1 VALUES(10); + INSERT INTO t3 VALUES(20),(30); +} +do_execsql_test join8-15010 { + SELECT * FROM t1 LEFT JOIN t2 ON true JOIN t3 ON t2.y IS NOT NULL; +} {} +do_execsql_test join8-15020 { + SELECT * FROM t1 LEFT JOIN t2 ON true JOIN t3 ON t2.y IS NOT NULL + WHERE (t3.z!=400 AND t3.z!=500 AND t3.z!=600); +} {} +do_execsql_test join8-15100 { + PRAGMA automatic_index = 0; + CREATE TABLE t4(x TEXT); + CREATE TABLE t5(y TEXT); + CREATE TABLE t6(z TEXT); + INSERT INTO t4 VALUES('a'), ('b'); + INSERT INTO t5 VALUES('b'), ('c'); + INSERT INTO t6 VALUES('a'), ('d'); +} {} +db null - +do_execsql_test join8-15110 { + SELECT * FROM t4 LEFT JOIN t5 ON x=y LEFT JOIN t6 ON (x=z) ORDER BY +x; +} {a - a b b -} +do_execsql_test join8-15120 { + SELECT * FROM t4 LEFT JOIN t5 ON x=y LEFT JOIN t6 ON (x=z) + WHERE t5.y!='x' AND t4.x!='x'; +} {b b -} + + finish_test