From: drh Date: Sat, 17 Aug 2019 17:07:15 +0000 (+0000) Subject: Ensure the functions that appear to be constant are not factored out of X-Git-Tag: version-3.30.0~128 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9e9a67adb059733e05e0791f2ec519985eaa333c;p=thirdparty%2Fsqlite.git Ensure the functions that appear to be constant are not factored out of expression that originate on the right-hand side of a LEFT JOIN. Ticket [6710d2f7a13a2997] FossilOrigin-Name: 500c9152daaf11cf69d778aa8592175f6088337c6667c59af6df3a24cd81eb0e --- diff --git a/manifest b/manifest index e9dfb2d42c..1e155600d1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Activate\sintrospection\spragmas\sby\sdefault.\s\sThe\snew\soption\nSQLITE_OMIT_INTROSPECTION_PRAGMAS\smust\sbe\sprovided\sto\skeep\sthem\sout. -D 2019-08-17T15:27:58.078 +C Ensure\sthe\sfunctions\sthat\sappear\sto\sbe\sconstant\sare\snot\sfactored\sout\sof\nexpression\sthat\soriginate\son\sthe\sright-hand\sside\sof\sa\sLEFT\sJOIN.\nTicket\s[6710d2f7a13a2997] +D 2019-08-17T17:07:15.587 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -475,7 +475,7 @@ F src/date.c e1d8ac7102f3f283e63e13867acb0efa33861cf34f0faf4cdbaf9fa7a1eb7041 F src/dbpage.c 135eb3b5e74f9ef74bde5cec2571192c90c86984fa534c88bf4a055076fa19b7 F src/dbstat.c c12833de69cb655751487d2c5a59607e36be1c58ba1f4bd536609909ad47b319 F src/delete.c d08c9e01a2664afd12edcfa3a9c6578517e8ff8735f35509582693adbe0edeaf -F src/expr.c 1b4f5a53a5f48ba3f718413586e0f9715cf90c684fba9038186a62728e2ebe72 +F src/expr.c abb98379d53defc742ffbfb3f6260036fdeac775643b9d0c52490d717949327e F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 6b79f4c2447691aa9ac86e2a6a774b65f3b3dd053d4220a4893051a0de20f82e F src/func.c 4ee36219698d50d672a28eca4adb0fd6b92e607a1883d318315e0d2fd5044467 @@ -1077,7 +1077,7 @@ F test/ioerr4.test f130fe9e71008577b342b8874d52984bd04ede2c F test/ioerr5.test 2edfa4fb0f896f733071303b42224df8bedd9da4 F test/ioerr6.test a395a6ab144b26a9e3e21059a1ab6a7149cca65b F test/istrue.test 75327829744e65cc8700e69340b8e6c192e10e39dfae7ccb0e970d3c4f49090a -F test/join.test d53a3662762eff50b65da8775201e609878a27dd0885a1ae7bcde9bb46cecbc5 +F test/join.test f505c78a793b0c807d534c1cacf71c7bf96aa734f78d091721f2a6859077b7e8 F test/join2.test 10f7047e723ebd68b2f47189be8eed20451a6f665d8bf46f1774c640d1062417 F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0 F test/join4.test 1a352e4e267114444c29266ce79e941af5885916 @@ -1836,7 +1836,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P de767376987f7668b0770c4920f1532e341b5a27f797d69c0f5e92b87d036170 -R ba0ddacef7e202b222af2845e11208f7 +P 9c4bca64fb5f635296a8d7d7c1bf2808e02ca734a9983e5cee9132f5352a9a6d +R 522398ea68495c38ea0fcdb681aed94e U drh -Z 608f836d0fe4bfadfea3872ae408e744 +Z 11aed5fc406f7abcc5b902e904ad4203 diff --git a/manifest.uuid b/manifest.uuid index 29f3d49d56..74872cc0c3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9c4bca64fb5f635296a8d7d7c1bf2808e02ca734a9983e5cee9132f5352a9a6d \ No newline at end of file +500c9152daaf11cf69d778aa8592175f6088337c6667c59af6df3a24cd81eb0e \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 8f02ae569a..ef4221ff8d 100644 --- a/src/expr.c +++ b/src/expr.c @@ -3994,10 +3994,23 @@ expr_code_doover: break; } + /* TK_IF_NULL_ROW Expr nodes are inserted ahead of expressions + ** that derive from the right-hand table of a LEFT JOIN. The + ** Expr.iTable value is the table number for the right-hand table. + ** The expression is only evaluated if that table is not currently + ** on a LEFT JOIN NULL row. + */ case TK_IF_NULL_ROW: { int addrINR; + u8 okConstFactor = pParse->okConstFactor; addrINR = sqlite3VdbeAddOp1(v, OP_IfNullRow, pExpr->iTable); + /* Temporarily disable factoring of constant expressions, since + ** even though expressions may appear to be constant, they are not + ** really constant because they originate from the right-hand side + ** of a LEFT JOIN. */ + pParse->okConstFactor = 0; inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target); + pParse->okConstFactor = okConstFactor; sqlite3VdbeJumpHere(v, addrINR); sqlite3VdbeChangeP3(v, addrINR, inReg); break; diff --git a/test/join.test b/test/join.test index f613df85b0..25c31705c8 100644 --- a/test/join.test +++ b/test/join.test @@ -864,4 +864,19 @@ do_execsql_test join-16.100 { WHERE (b IS NOT NULL)=0; } {1 {}} +# 2019-08-17 ticket https://sqlite.org/src/tktview/6710d2f7a13a299728ab +# Ensure that constants that derive from the right-hand table of a LEFT JOIN +# are never factored out, since they are not really constant. +# +do_execsql_test join-17.100 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(x); + INSERT INTO t1(x) VALUES(0),(1); + SELECT * FROM t1 LEFT JOIN (SELECT abs(1) AS y FROM t1) ON x WHERE NOT(y='a'); +} {1 1 1 1} +do_execsql_test join-17.110 { + SELECT * FROM t1 LEFT JOIN (SELECT abs(1)+2 AS y FROM t1) ON x + WHERE NOT(y='a'); +} {1 3 1 3} + finish_test