From: drh Date: Tue, 23 May 2017 15:21:37 +0000 (+0000) Subject: Disable the LEFT JOIN flattening optimization for aggregate queries, as it X-Git-Tag: version-3.20.0~251 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1d1fc5e385554e56f33ed3699cf0fe5456cf184c;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: 44b21e35c92137cc519d0cc87c627cc531d0bd442a7b9a7356fa2c6bc5f70fb6 --- diff --git a/manifest b/manifest index e5b072614d..5225059a63 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:36:13.432 +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:21:37.230 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 8eeb80162074004e906b53d7340a12a14c471a83743aab975947e95ce061efcc @@ -404,7 +404,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 9235003e7269ca95e6357393cee03450e7e89ba74470e5ee698d3a8cb1a7deea F src/sqlite.h.in 8dd468837a4f6d76713e3a4cc65bea48095009038593d41040ab46c1b351197f F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 @@ -907,7 +907,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 @@ -1581,7 +1581,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 92c178507df553e4f1110342c8f9b11b3ee37989e1d634fcaccabf657befa22f -R 2239a710791ec9b87e0ae90a011fc293 +P 941d8142b7c9a96ff143d1add3c86cf42d61fd08e532d400dac555f23eadbcfb +R ffe4a77f21d90dd19d519ba4779a42b9 U drh -Z 322e7f1069223cac48868922c1f54e26 +Z e4d6716b4bf6ca92e150c31ad5fda640 diff --git a/manifest.uuid b/manifest.uuid index 6ef0275ec1..289d8b2557 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -941d8142b7c9a96ff143d1add3c86cf42d61fd08e532d400dac555f23eadbcfb \ No newline at end of file +44b21e35c92137cc519d0cc87c627cc531d0bd442a7b9a7356fa2c6bc5f70fb6 \ 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