1961a7260Sdan# 2020-12-22 2961a7260Sdan# 3961a7260Sdan# The author disclaims copyright to this source code. In place of 4961a7260Sdan# a legal notice, here is a blessing: 5961a7260Sdan# 6961a7260Sdan# May you do good and not evil. 7961a7260Sdan# May you find forgiveness for yourself and forgive others. 8961a7260Sdan# May you share freely, never taking more than you give. 9961a7260Sdan# 10961a7260Sdan#*********************************************************************** 11961a7260Sdan# This file implements regression tests for SQLite library. The 12961a7260Sdan# focus of this file is flattening UNION ALL sub-queries. 13961a7260Sdan# 14961a7260Sdan 15961a7260Sdanset testdir [file dirname $argv0] 16961a7260Sdansource $testdir/tester.tcl 17961a7260Sdanset testprefix unionall2 18961a7260Sdan 19961a7260Sdando_execsql_test 1.0 { 20961a7260Sdan CREATE TABLE t1(a, b); 21961a7260Sdan CREATE TABLE t2(c, d); 22961a7260Sdan 23961a7260Sdan CREATE VIEW v1 AS SELECT * FROM t1, t2; 24961a7260Sdan CREATE VIEW v2 AS SELECT * FROM t1, t2; 25961a7260Sdan 26961a7260Sdan CREATE VIEW vA AS 27961a7260Sdan SELECT * FROM v1, ( 28961a7260Sdan SELECT * FROM t1 LEFT JOIN t2 ON (a=c) 29961a7260Sdan ) 30961a7260Sdan UNION ALL 31961a7260Sdan SELECT * FROM v1, v2 32961a7260Sdan} 33961a7260Sdan 34961a7260Sdando_execsql_test 1.1 { 35961a7260Sdan SELECT 1 FROM vA, vA, vA, vA, vA, vA, vA, vA, vA, vA 36961a7260Sdan} 37961a7260Sdan 38*240e36c0Sdan#------------------------------------------------------------------------- 39*240e36c0Sdan 40*240e36c0Sdando_execsql_test 2.1 { 41*240e36c0Sdan CREATE TABLE y1(a INTEGER, b); 42*240e36c0Sdan CREATE TABLE y2(c INTEGER, d); 43*240e36c0Sdan 44*240e36c0Sdan CREATE TABLE x3_a(a INTEGER PRIMARY KEY, b TEXT); 45*240e36c0Sdan CREATE TABLE x3_b(c INTEGER PRIMARY KEY, d TEXT); 46*240e36c0Sdan} 47*240e36c0Sdan 48*240e36c0Sdando_execsql_test 2.2 { 49*240e36c0Sdan 50*240e36c0Sdan SELECT * FROM y1 CROSS JOIN y2 WHERE y1.a=y2.c AND y2.c IN ( 51*240e36c0Sdan SELECT a FROM x3_a UNION ALL 52*240e36c0Sdan SELECT c FROM x3_b ORDER BY 1 53*240e36c0Sdan ) 54*240e36c0Sdan} 55*240e36c0Sdan 56*240e36c0Sdan 57961a7260Sdan 58961a7260Sdanfinish_test 59