Fix the query flattener optimization so that it preserve the "SF_Compound"

bit when flattening a compound subquery into a non-compound outer query.
Failure to preserve that bit could allow subsequent flattenings which are
not valid. Fix for ticket [c41afac34f15781fe09cd].

FossilOrigin-Name: 523b42371122d9e1b3185425745f1490138bff7f7cc941ee26ee81df7ade5bf4
This commit is contained in:
drh 2019-05-29 17:22:38 +00:00
parent efdb371a1d
commit 7cd5e856e5
4 changed files with 29 additions and 14 deletions

View File

@ -1,5 +1,5 @@
C Fix\san\sassert()\sin\sfts3\sthat\scould\sfail\swhen\sprocessing\scorrupt\srecords.\sAlso\ssome\sminor\ssanitizer\swarnings.
D 2019-05-28T14:42:32.004
C Fix\sthe\squery\sflattener\soptimization\sso\sthat\sit\spreserve\sthe\s"SF_Compound"\nbit\swhen\sflattening\sa\scompound\ssubquery\sinto\sa\snon-compound\souter\squery.\nFailure\sto\spreserve\sthat\sbit\scould\sallow\ssubsequent\sflattenings\swhich\sare\nnot\svalid.\sFix\sfor\sticket\s[c41afac34f15781fe09cd].
D 2019-05-29T17:22:38.103
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -522,7 +522,7 @@ F src/printf.c 9be6945837c839ba57837b4bc3af349eba630920fa5532aa518816defe42a7d4
F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
F src/resolve.c bae0a7562db77b02d87101b587819d5a5dcd8625e477d2d8a228a20bba4fead6
F src/rowset.c d977b011993aaea002cab3e0bb2ce50cf346000dff94e944d547b989f4b1fe93
F src/select.c ccd314a204ef27edadeb58faebc7ded1f967fa83d6b9b858cd422c80ef171643
F src/select.c 87ea2169d63a363a4ce5e2b9fa901c98126e5a57a5e865cb8e0032d8781d4b6f
F src/shell.c.in 6c992809abf20dbb4aad89299d7c15c98ddf2504b23c83ef71eb435ad392cdc3
F src/sqlite.h.in d19c873a17c2effd4417f687fad942b6cc0ab0c64535f669cc2f22a5b05db23b
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
@ -1282,7 +1282,7 @@ F test/select2.test 352480e0e9c66eda9c3044e412abdf5be0215b56
F test/select3.test 3905450067c28766bc83ee397f6d87342de868baa60f2bcfd00f286dfbd62cb9
F test/select4.test 5389d9895968d1196c457d59b3ee6515d771d328
F test/select5.test df9ec0d218cedceb4fe7b63262025b547b50a55e59148c6f40b60ca25f1d4546
F test/select6.test 39eac4a5c03650b2b473c532882273283ee8b7a0
F test/select6.test 319d45e414cdd321bf17cfacedaf19e3935ad64dac357c53f1492338c6e9b801
F test/select7.test f659f231489349e8c5734e610803d7654207318f
F test/select8.test 8c8f5ae43894c891efc5755ed905467d1d67ad5d
F test/select9.test aebc2bb0c3bc44606125033cbcaac2c8d1f33a95
@ -1829,7 +1829,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 7cbb9a5fe835d01be158edd1e2f9d553dc257f2d27b53a5d5bf6660d0bd101c4
R 26e3f1c25f112ad35d8663e8b483c4e3
U dan
Z 20d8c2bc205996206f3528e83303f90e
P c736c40aab071a69bd5c5347b7c116d87ea3954019e967ca8ff7bdb4b518e5bf
R 2c266512a1a06dffad446ef8f7479e2d
U drh
Z e14541c4ce7a69af488fec1ac8365e2a

View File

@ -1 +1 @@
c736c40aab071a69bd5c5347b7c116d87ea3954019e967ca8ff7bdb4b518e5bf
523b42371122d9e1b3185425745f1490138bff7f7cc941ee26ee81df7ade5bf4

View File

@ -4045,10 +4045,10 @@ static int flattenSubquery(
substSelect(&x, pParent, 0);
}
/* The flattened query is distinct if either the inner or the
** outer query is distinct.
*/
pParent->selFlags |= pSub->selFlags & SF_Distinct;
/* The flattened query is a compound if either the inner or the
** outer query is a compound. */
pParent->selFlags |= pSub->selFlags & SF_Compound;
assert( (pSub->selFlags & SF_Distinct)==0 ); /* restriction (17b) */
/*
** SELECT ... FROM (SELECT ... LIMIT a OFFSET b) LIMIT x OFFSET y;

View File

@ -12,7 +12,6 @@
# focus of this file is testing SELECT statements that contain
# subqueries in their FROM clause.
#
# $Id: select6.test,v 1.29 2009/01/09 01:12:28 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -613,5 +612,21 @@ do_execsql_test 11.100 {
FROM ( SELECT count(*) AS cnt FROM t1 );
} {{}}
# 2019-05-29 ticket https://www.sqlite.org/src/info/c41afac34f15781f
# A LIMIT clause in a subquery is incorrectly applied to a subquery.
#
do_execsql_test 12.100 {
DROP TABLE t1;
DROP TABLE t2;
CREATE TABLE t1(a);
INSERT INTO t1 VALUES(1);
INSERT INTO t1 VALUES(2);
CREATE TABLE t2(b);
INSERT INTO t2 VALUES(3);
SELECT * FROM (
SELECT * FROM (SELECT * FROM t1 LIMIT 1)
UNION ALL
SELECT * from t2);
} {1 3}
finish_test