From: drh Date: Tue, 23 May 2017 15:33:41 +0000 (+0000) Subject: Disable the LEFT JOIN flattening optimization for aggregate queries, as it X-Git-Tag: version-3.19.1~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3c790f2a838fca91f01d7774d1faedf05b01df2d;p=thirdparty%2Fsqlite.git Disable the LEFT JOIN flattening optimization for aggregate queries, as it does not currently work. Further fix for ticket [cad1ab4cb7b0fc344]. FossilOrigin-Name: 05ada741554b9fd00befcf7b4083637f53de68699ae5210ac18e0773ad1a9910 --- diff --git a/manifest b/manifest index 79b72ec404..3bdffc23d3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Ensure\sthat\sthe\sexpression\srewriter\sinside\sthe\squery\sflattener\sdecends\sinto\nthe\ssubstructure\sof\sthe\sTK_IF_NULL_ROW\soperator.\s\sThis\sis\sa\scontinuation\nof\sthe\sfix\sfor\sticket\s[cad1ab4cb7b0fc344]. -D 2017-05-23T12:44:57.667 +C Disable\sthe\sLEFT\sJOIN\sflattening\soptimization\sfor\saggregate\squeries,\sas\sit\ndoes\snot\scurrently\swork.\s\sFurther\sfix\sfor\sticket\s[cad1ab4cb7b0fc344]. +D 2017-05-23T15:33:41.141 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 8eeb80162074004e906b53d7340a12a14c471a83743aab975947e95ce061efcc @@ -403,7 +403,7 @@ F src/printf.c 8757834f1b54dae512fb25eb1acc8e94a0d15dd2290b58f2563f65973265adb2 F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c 3e518b962d932a997fae373366880fc028c75706 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac -F src/select.c 30805a1bc0236ba70a9a1592af4a7c522f906c6bfeba44c165046e592a3a36ec +F src/select.c 9db6887514a663ef4eb117f12cbae613bece9267f180d0fcdfa49402b013483e F src/shell.c a37d96b20b3644d0eb905df5aa7a0fcf9f6e73c15898337230c760a24a8df794 F src/sqlite.h.in 8dd468837a4f6d76713e3a4cc65bea48095009038593d41040ab46c1b351197f F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 @@ -906,7 +906,7 @@ F test/ioerr3.test d3cec5e1a11ad6d27527d0d38573fbff14c71bdd F test/ioerr4.test f130fe9e71008577b342b8874d52984bd04ede2c F test/ioerr5.test 2edfa4fb0f896f733071303b42224df8bedd9da4 F test/ioerr6.test a395a6ab144b26a9e3e21059a1ab6a7149cca65b -F test/join.test 89087a3285ce7c317ac811f8cea1be226410f34b9cd9056b550390b591966b38 +F test/join.test a26e4c45edba5d2090216be6fc26d8d862c1a66e5729ce38308b4f286aa745e5 F test/join2.test a48f723c5692e2cbb23a9297ac2720cb77d51a70 F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0 F test/join4.test 1a352e4e267114444c29266ce79e941af5885916 @@ -1580,8 +1580,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 16656b8ff5cf79565b0b30f804f5f924fabfe989fdf00a2e7c30fe4438143981 -Q +941d8142b7c9a96ff143d1add3c86cf42d61fd08e532d400dac555f23eadbcfb -R f268afb33074cdb578076d3ac641679b +P 28d2902d8f4dfbbfc610f271e00d353b0baae386b56b482f96b88836410be129 +Q +44b21e35c92137cc519d0cc87c627cc531d0bd442a7b9a7356fa2c6bc5f70fb6 +R 7de9199234b8233f96ae8f86cad0d9b4 U drh -Z caa375b1b0bf90f02994a58721102cd3 +Z 5038ccf49cccdd8c3bebdd6501c9aad0 diff --git a/manifest.uuid b/manifest.uuid index cb9b76da1a..c36c072132 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -28d2902d8f4dfbbfc610f271e00d353b0baae386b56b482f96b88836410be129 \ No newline at end of file +05ada741554b9fd00befcf7b4083637f53de68699ae5210ac18e0773ad1a9910 \ No newline at end of file diff --git a/src/select.c b/src/select.c index da8cde8ba3..f620027a45 100644 --- a/src/select.c +++ b/src/select.c @@ -3301,7 +3301,8 @@ static void substSelect( ** due to ticket [2f7170d73bf9abf80] from 2015-02-09.) ** ** (3) The subquery is not the right operand of a LEFT JOIN -** or the subquery is not itself a join. +** or the subquery is not itself a join and the outer query is not +** an aggregate. ** ** (4) The subquery is not DISTINCT. ** @@ -3497,11 +3498,16 @@ static int flattenSubquery( ** ** which is not at all the same thing. ** + ** If the subquery is the right operand of a LEFT JOIN, then the outer + ** query cannot be an aggregate. This is an artifact of the way aggregates + ** are processed - there is not mechanism to determine if the LEFT JOIN + ** table should be all-NULL. + ** ** See also tickets #306, #350, and #3300. */ if( (pSubitem->fg.jointype & JT_OUTER)!=0 ){ isLeftJoin = 1; - if( pSubSrc->nSrc>1 ){ + if( pSubSrc->nSrc>1 || isAgg ){ return 0; /* Restriction (3) */ } } diff --git a/test/join.test b/test/join.test index 23e0838c2c..0f6d8e9ac5 100644 --- a/test/join.test +++ b/test/join.test @@ -732,4 +732,15 @@ do_execsql_test join-14.3 { LEFT JOIN (SELECT cc+222, * FROM (SELECT * FROM (SELECT 333 cc))); } {111 555 333} +do_execsql_test join-14.4 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(c PRIMARY KEY, a TEXT(10000), b TEXT(10000)); + SELECT * FROM (SELECT 111) LEFT JOIN (SELECT c+222 FROM t1) GROUP BY 1; +} {111 {}} +do_execsql_test join-14.5 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(c PRIMARY KEY) WITHOUT ROWID; + SELECT * FROM (SELECT 111) LEFT JOIN (SELECT c+222 FROM t1) GROUP BY 1; +} {111 {}} + finish_test