New test cases for query flattening when there are ON clauses and outer joins.

FossilOrigin-Name: db55387b1972bc7bc6855bd3497af744a111e7d28d09893cd985fbb01be41bcc
This commit is contained in:
drh 2022-09-20 19:45:04 +00:00
parent 8b9a3d1fc8
commit 4c5c941b6e
3 changed files with 65 additions and 7 deletions

View File

@ -1,5 +1,5 @@
C Modify\sthe\sOP_IfNotOpen\sopcode\sso\sthat\sthe\sjump\sis\staken\sif\sthe\scursor\sis\sopen\nbut\swas\spreviously\sset\sto\sa\sNULL\srow\susing\sOP_NullRow.
D 2022-09-20T19:22:17.805
C New\stest\scases\sfor\squery\sflattening\swhen\sthere\sare\sON\sclauses\sand\souter\sjoins.
D 2022-09-20T19:45:04.738
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -1180,7 +1180,7 @@ F test/ioerr4.test f130fe9e71008577b342b8874d52984bd04ede2c
F test/ioerr5.test 2edfa4fb0f896f733071303b42224df8bedd9da4
F test/ioerr6.test a395a6ab144b26a9e3e21059a1ab6a7149cca65b
F test/istrue.test e7f285bb70282625c258e866ce6337d4c762922f5a300e1b50f958aef6e7d9c9
F test/join.test 21dbc65ab2476b10ae3ed1dcf64a99fb9a40473caa22f4cec2d6a829933c1442
F test/join.test 41203c37d22e27b6b7211e3b1b875b6f0fc3c9fb2ea8fe31d3a8683ae3cf1a45
F test/join2.test 466b07233820f5deee66a6c3bf6e4500c8bbf7b83649e67606f5f649c07928c0
F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0
F test/join4.test 1a352e4e267114444c29266ce79e941af5885916
@ -2000,8 +2000,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 852b385a5de622aa32026824210d4bd23db52a4a8a697b83d22d6000edeba487
R 58d9f89a36d9e4cf587663a233307943
P 1292d68caa7086610ddda343f3852e63de8da1eb66536ee4716b6529f5a31bc6
R eab6511b05ba7254ebaf6e3422ee1bf8
U drh
Z 7e40ae1a3e52a669a3942bf4dda137ff
Z 0a097f1ec50fb2c86025df8ed078e191
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
1292d68caa7086610ddda343f3852e63de8da1eb66536ee4716b6529f5a31bc6
db55387b1972bc7bc6855bd3497af744a111e7d28d09893cd985fbb01be41bcc

View File

@ -1130,5 +1130,63 @@ do_execsql_test join-27.5 {
) AS t99 ON b IN (1,2,3);
} {}
db null NULL
do_execsql_test join-27.6 {
INSERT INTO t1 VALUES(3,4,NULL);
INSERT INTO t2 VALUES(1,2);
WITH t99(b) AS (
SELECT coalesce(b,3) FROM t2 AS x LEFT JOIN t1 ON c IN (SELECT x FROM t3)
)
SELECT d, e, b FROM t2 JOIN t99 ON b IN (1,2,3) ORDER BY +d;
} {NULL NULL 3 NULL NULL 3 1 2 3 1 2 3}
do_execsql_test join-27.7 {
SELECT d, e, b2
FROM t2
JOIN (SELECT coalesce(b,3) AS b2 FROM t2 AS x LEFT JOIN t1
ON c IN (SELECT x FROM t3)) AS t99
ON b2 IN (1,2,3) ORDER BY +d;
} {NULL NULL 3 NULL NULL 3 1 2 3 1 2 3}
do_execsql_test join-27.8 {
DELETE FROM t1;
DELETE FROM t2 WHERE d IS NOT NULL;
DELETE FROM t3;
SELECT * FROM t2 JOIN (SELECT b FROM t2 LEFT JOIN t1
ON c IN (SELECT x FROM t3)) AS t99 ON b IN (1,2,3);
} {}
# 2022-09-19 https://sqlite.org/forum/forumpost/96b9e5709cf47cda
# Performance regression relative to version 3.38.0 that resulted from
# a new query flattener restriction that was added to fixes the join-27.*
# tests above. The restriction needed to be removed and the join-27.*
# problem fixed another way.
#
reset_db
do_execsql_test join-28.1 {
CREATE TABLE t1(a INTEGER PRIMARY KEY, b INT, c INT);
CREATE TABLE t2(d INTEGER PRIMARY KEY, e INT);
CREATE VIEW t3(a,b,c,d,e) AS SELECT * FROM t1 LEFT JOIN t2 ON d=c;
CREATE TABLE t4(x INT, y INT);
INSERT INTO t1 VALUES(1,2,3);
INSERT INTO t2 VALUES(1,5);
INSERT INTO t4 VALUES(1,4);
SELECT a, b, y FROM t4 JOIN t3 ON a=x;
} {1 2 4}
do_eqp_test join-28.2 {
SELECT a, b, y FROM t4 JOIN t3 ON a=x;
} {
QUERY PLAN
|--SCAN t4
`--SEARCH t1 USING INTEGER PRIMARY KEY (rowid=?)
}
# ^^^^^^^ Without the fix (if the query flattening optimization does not
# run) the query plan above would look like this:
#
# QUERY PLAN
# |--MATERIALIZE t3
# | |--SCAN t1
# | `--SEARCH t2 USING INTEGER PRIMARY KEY (rowid=?) LEFT-JOIN
# |--SCAN t4
# `--SEARCH t3 USING AUTOMATIC COVERING INDEX (a=?)
finish_test