diff options
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/regress/expected/union.out | 51 | ||||
-rw-r--r-- | src/test/regress/sql/union.sql | 27 |
2 files changed, 78 insertions, 0 deletions
diff --git a/src/test/regress/expected/union.out b/src/test/regress/expected/union.out index d3ea433db15..7c089e0d598 100644 --- a/src/test/regress/expected/union.out +++ b/src/test/regress/expected/union.out @@ -1216,6 +1216,57 @@ select event_id drop table events_child, events, other_events; reset enable_indexonlyscan; +-- +-- Test handling of UNION with provably empty inputs +-- +-- Ensure the empty UNION input is pruned and de-duplication is done for the +-- remaining relation. +EXPLAIN (COSTS OFF, VERBOSE) +SELECT two FROM tenk1 WHERE 1=2 +UNION +SELECT four FROM tenk1 +ORDER BY 1; + QUERY PLAN +-------------------------------------- + Sort + Output: tenk1.four + Sort Key: tenk1.four + -> HashAggregate + Output: tenk1.four + Group Key: tenk1.four + -> Seq Scan on public.tenk1 + Output: tenk1.four +(8 rows) + +-- Validate that the results of the above are correct +SELECT two FROM tenk1 WHERE 1=2 +UNION +SELECT four FROM tenk1 +ORDER BY 1; + two +----- + 0 + 1 + 2 + 3 +(4 rows) + +-- All UNION inputs are proven empty. Ensure the planner provides a +-- const-false Result node +EXPLAIN (COSTS OFF, VERBOSE) +SELECT two FROM tenk1 WHERE 1=2 +UNION +SELECT four FROM tenk1 WHERE 1=2 +UNION +SELECT ten FROM tenk1 WHERE 1=2; + QUERY PLAN +-------------------------------- + Result + Output: unnamed_subquery.two + Replaces: Aggregate + One-Time Filter: false +(4 rows) + -- Test constraint exclusion of UNION ALL subqueries explain (costs off) SELECT * FROM diff --git a/src/test/regress/sql/union.sql b/src/test/regress/sql/union.sql index 13700a6bfc4..56bd20e741c 100644 --- a/src/test/regress/sql/union.sql +++ b/src/test/regress/sql/union.sql @@ -459,6 +459,33 @@ drop table events_child, events, other_events; reset enable_indexonlyscan; +-- +-- Test handling of UNION with provably empty inputs +-- + +-- Ensure the empty UNION input is pruned and de-duplication is done for the +-- remaining relation. +EXPLAIN (COSTS OFF, VERBOSE) +SELECT two FROM tenk1 WHERE 1=2 +UNION +SELECT four FROM tenk1 +ORDER BY 1; + +-- Validate that the results of the above are correct +SELECT two FROM tenk1 WHERE 1=2 +UNION +SELECT four FROM tenk1 +ORDER BY 1; + +-- All UNION inputs are proven empty. Ensure the planner provides a +-- const-false Result node +EXPLAIN (COSTS OFF, VERBOSE) +SELECT two FROM tenk1 WHERE 1=2 +UNION +SELECT four FROM tenk1 WHERE 1=2 +UNION +SELECT ten FROM tenk1 WHERE 1=2; + -- Test constraint exclusion of UNION ALL subqueries explain (costs off) SELECT * FROM |