sqlite/test/unionall.test
dan de9ed6293d 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
2020-12-16 20:00:46 +00:00

59 lines
1.5 KiB
Plaintext

# 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