mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-29 08:01:23 +03:00
Allow sub-queries that use UNION ALL to be flattened, even if the parent query is a join. Still some problems on this branch.
FossilOrigin-Name: 00e4bf74d3dfb87666a2266905f7d1a2afc6eb088d22cfd4f38f048733d6b936
This commit is contained in:
@ -261,10 +261,10 @@ do_execsql_test 5.2 {
|
||||
}
|
||||
|
||||
do_execsql_test 5.3 {
|
||||
SELECT * FROM x1, (SELECT b FROM vvv UNION ALL SELECT c from x3);
|
||||
SELECT * FROM x1, (SELECT b FROM vvv UNION ALL SELECT c from x3) ORDER BY 1,2;
|
||||
} {
|
||||
a 21 a 22 a 23 a 24 a 25 a 302 a 303 a 301
|
||||
b 21 b 22 b 23 b 24 b 25 b 302 b 303 b 301
|
||||
a 21 a 22 a 23 a 24 a 25 a 301 a 302 a 303
|
||||
b 21 b 22 b 23 b 24 b 25 b 301 b 302 b 303
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
58
test/unionall.test
Normal file
58
test/unionall.test
Normal file
@ -0,0 +1,58 @@
|
||||
# 2020-12-16
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is flattening UNION ALL sub-queries.
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
set testprefix unionall
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE TABLE t1_a(a INTEGER PRIMARY KEY, b TEXT);
|
||||
CREATE TABLE t1_b(c INTEGER PRIMARY KEY, d TEXT);
|
||||
CREATE TABLE t1_c(e INTEGER PRIMARY KEY, f TEXT);
|
||||
|
||||
INSERT INTO t1_a VALUES(1, 'one'), (4, 'four');
|
||||
INSERT INTO t1_b VALUES(2, 'two'), (5, 'five');
|
||||
INSERT INTO t1_c VALUES(3, 'three'), (6, 'six');
|
||||
|
||||
CREATE VIEW t1 AS
|
||||
SELECT a, b FROM t1_a UNION ALL
|
||||
SELECT c, d FROM t1_b UNION ALL
|
||||
SELECT e, f FROM t1_c;
|
||||
|
||||
CREATE TABLE i1(x);
|
||||
INSERT INTO i1 VALUES(2), (5), (6), (1);
|
||||
}
|
||||
|
||||
do_execsql_test 1.1 {
|
||||
SELECT a, b FROM (
|
||||
SELECT a, b FROM t1_a UNION ALL
|
||||
SELECT c, d FROM t1_b UNION ALL
|
||||
SELECT e, f FROM t1_c
|
||||
) ORDER BY a
|
||||
} {
|
||||
1 one 2 two 3 three 4 four 5 five 6 six
|
||||
}
|
||||
|
||||
do_execsql_test 1.2 {
|
||||
SELECT a, b FROM t1 ORDER BY a
|
||||
} {
|
||||
1 one 2 two 3 three 4 four 5 five 6 six
|
||||
}
|
||||
|
||||
do_execsql_test 1.3 {
|
||||
SELECT a, b FROM i1, t1 WHERE a=x ORDER BY a
|
||||
} {1 one 2 two 5 five 6 six}
|
||||
|
||||
|
||||
finish_test
|
36
test/unionallfault.test
Normal file
36
test/unionallfault.test
Normal file
@ -0,0 +1,36 @@
|
||||
# 2020-12-16
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
set testprefix unionallfault
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE TABLE t1(x,y,z);
|
||||
CREATE TABLE t3(x,y,z);
|
||||
}
|
||||
faultsim_save_and_close
|
||||
|
||||
|
||||
do_faultsim_test 1 -faults oom-t* -prep {
|
||||
faultsim_restore_and_reopen
|
||||
} -body {
|
||||
execsql {
|
||||
SELECT * FROM (
|
||||
SELECT x FROM t1 UNION ALL SELECT y FROM t1
|
||||
)
|
||||
}
|
||||
} -test {
|
||||
faultsim_test_result {0 {}}
|
||||
}
|
||||
|
||||
finish_test
|
@ -26,14 +26,13 @@ do_eqp_test 110 {
|
||||
SELECT * FROM t1, v4 WHERE t1.a=?1 AND v4.a=t1.a;
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--MATERIALIZE xxxxxx
|
||||
| `--COMPOUND QUERY
|
||||
| |--LEFT-MOST SUBQUERY
|
||||
| | `--SEARCH TABLE t2 USING INDEX sqlite_autoindex_t2_1 (a=?)
|
||||
| `--UNION ALL
|
||||
| `--SEARCH TABLE t3 USING INDEX sqlite_autoindex_t3_1 (a=?)
|
||||
|--SCAN SUBQUERY xxxxxx
|
||||
`--SEARCH TABLE t1 USING INDEX sqlite_autoindex_t1_1 (a=?)
|
||||
`--COMPOUND QUERY
|
||||
|--LEFT-MOST SUBQUERY
|
||||
| |--SEARCH TABLE t2 USING INDEX sqlite_autoindex_t2_1 (a=?)
|
||||
| `--SEARCH TABLE t1 USING INDEX sqlite_autoindex_t1_1 (a=?)
|
||||
`--UNION ALL
|
||||
|--SEARCH TABLE t3 USING INDEX sqlite_autoindex_t3_1 (a=?)
|
||||
`--SEARCH TABLE t1 USING INDEX sqlite_autoindex_t1_1 (a=?)
|
||||
}
|
||||
|
||||
# The scan of the t1 table goes first since that enables the ORDER BY
|
||||
|
Reference in New Issue
Block a user