summaryrefslogtreecommitdiff
path: root/src/test/regress
diff options
context:
space:
mode:
authorRobert Haas2024-05-21 16:42:27 +0000
committerRobert Haas2024-05-21 16:44:51 +0000
commit12933dc6048902ba891f9572cab96981f50ef669 (patch)
tree3e14dabda4e36866611d8e2627b3925b011c00e3 /src/test/regress
parent3bd7b2f465deb48c0d37ed6a41bd864771f44390 (diff)
Re-allow planner to use Merge Append to efficiently implement UNION.
This reverts commit 7204f35919b7e021e8d1bc9f2d76fd6bfcdd2070, thus restoring 66c0185a3 (Allow planner to use Merge Append to efficiently implement UNION) as well as the follow-on commits d5d2205c8, 3b1a7eb28, 7487044d6. Per further discussion on pgsql-release, we wish to ship beta1 with this feature, and patch the bug that was found just before wrap, rather than shipping beta1 with the feature reverted.
Diffstat (limited to 'src/test/regress')
-rw-r--r--src/test/regress/expected/collate.icu.utf8.out2
-rw-r--r--src/test/regress/expected/incremental_sort.out13
-rw-r--r--src/test/regress/expected/union.out46
-rw-r--r--src/test/regress/sql/collate.icu.utf8.sql2
-rw-r--r--src/test/regress/sql/union.sql19
5 files changed, 55 insertions, 27 deletions
diff --git a/src/test/regress/expected/collate.icu.utf8.out b/src/test/regress/expected/collate.icu.utf8.out
index 2de8924b524..7d59fb44316 100644
--- a/src/test/regress/expected/collate.icu.utf8.out
+++ b/src/test/regress/expected/collate.icu.utf8.out
@@ -1396,6 +1396,7 @@ SELECT x FROM test3cs WHERE x ~ 'a';
abc
(1 row)
+SET enable_hashagg TO off;
SELECT x FROM test1cs UNION SELECT x FROM test2cs ORDER BY x;
x
-----
@@ -1448,6 +1449,7 @@ SELECT DISTINCT x FROM test3cs ORDER BY x;
ghi
(4 rows)
+RESET enable_hashagg;
SELECT count(DISTINCT x) FROM test3cs;
count
-------
diff --git a/src/test/regress/expected/incremental_sort.out b/src/test/regress/expected/incremental_sort.out
index 7fdb685313d..5fd54a10b1a 100644
--- a/src/test/regress/expected/incremental_sort.out
+++ b/src/test/regress/expected/incremental_sort.out
@@ -1472,14 +1472,19 @@ explain (costs off) select * from t union select * from t order by 1,3;
Sort Key: t.a, t.c
Presorted Key: t.a
-> Unique
- -> Sort
+ -> Merge Append
Sort Key: t.a, t.b, t.c
- -> Gather
+ -> Gather Merge
Workers Planned: 2
- -> Parallel Append
+ -> Sort
+ Sort Key: t.a, t.b, t.c
-> Parallel Seq Scan on t
+ -> Gather Merge
+ Workers Planned: 2
+ -> Sort
+ Sort Key: t_1.a, t_1.b, t_1.c
-> Parallel Seq Scan on t t_1
-(11 rows)
+(16 rows)
-- Full sort, not just incremental sort can be pushed below a gather merge path
-- by generate_useful_gather_paths.
diff --git a/src/test/regress/expected/union.out b/src/test/regress/expected/union.out
index 882017afc9a..26b718e9033 100644
--- a/src/test/regress/expected/union.out
+++ b/src/test/regress/expected/union.out
@@ -412,16 +412,17 @@ set enable_hashagg to off;
explain (costs off)
select count(*) from
( select unique1 from tenk1 union select fivethous from tenk1 ) ss;
- QUERY PLAN
-----------------------------------------------------------------------
+ QUERY PLAN
+----------------------------------------------------------------
Aggregate
-> Unique
- -> Sort
+ -> Merge Append
Sort Key: tenk1.unique1
- -> Append
- -> Index Only Scan using tenk1_unique1 on tenk1
+ -> Index Only Scan using tenk1_unique1 on tenk1
+ -> Sort
+ Sort Key: tenk1_1.fivethous
-> Seq Scan on tenk1 tenk1_1
-(7 rows)
+(8 rows)
select count(*) from
( select unique1 from tenk1 union select fivethous from tenk1 ) ss;
@@ -950,16 +951,9 @@ select except select;
-- check hashed implementation
set enable_hashagg = true;
set enable_sort = false;
-explain (costs off)
-select from generate_series(1,5) union select from generate_series(1,3);
- QUERY PLAN
-----------------------------------------------------------------
- HashAggregate
- -> Append
- -> Function Scan on generate_series
- -> Function Scan on generate_series generate_series_1
-(4 rows)
-
+-- We've no way to check hashed UNION as the empty pathkeys in the Append are
+-- fine to make use of Unique, which is cheaper than HashAggregate and we've
+-- no means to disable Unique.
explain (costs off)
select from generate_series(1,5) intersect select from generate_series(1,3);
QUERY PLAN
@@ -972,10 +966,6 @@ select from generate_series(1,5) intersect select from generate_series(1,3);
-> Function Scan on generate_series generate_series_1
(6 rows)
-select from generate_series(1,5) union select from generate_series(1,3);
---
-(1 row)
-
select from generate_series(1,5) union all select from generate_series(1,3);
--
(8 rows)
@@ -1045,6 +1035,20 @@ select from generate_series(1,5) except all select from generate_series(1,3);
--
(2 rows)
+-- Try a variation of the above but with a CTE which contains a column, again
+-- with an empty final select list.
+-- Ensure we get the expected 1 row with 0 columns
+with cte as materialized (select s from generate_series(1,5) s)
+select from cte union select from cte;
+--
+(1 row)
+
+-- Ensure we get the same result as the above.
+with cte as not materialized (select s from generate_series(1,5) s)
+select from cte union select from cte;
+--
+(1 row)
+
reset enable_hashagg;
reset enable_sort;
--
@@ -1081,6 +1085,7 @@ INSERT INTO t2 VALUES ('ab'), ('xy');
set enable_seqscan = off;
set enable_indexscan = on;
set enable_bitmapscan = off;
+set enable_sort = off;
explain (costs off)
SELECT * FROM
(SELECT a || b AS ab FROM t1
@@ -1162,6 +1167,7 @@ explain (costs off)
reset enable_seqscan;
reset enable_indexscan;
reset enable_bitmapscan;
+reset enable_sort;
-- This simpler variant of the above test has been observed to fail differently
create table events (event_id int primary key);
create table other_events (event_id int primary key);
diff --git a/src/test/regress/sql/collate.icu.utf8.sql b/src/test/regress/sql/collate.icu.utf8.sql
index 03837de846b..80f28a97d78 100644
--- a/src/test/regress/sql/collate.icu.utf8.sql
+++ b/src/test/regress/sql/collate.icu.utf8.sql
@@ -555,6 +555,7 @@ SELECT x FROM test3cs WHERE x LIKE 'a%';
SELECT x FROM test3cs WHERE x ILIKE 'a%';
SELECT x FROM test3cs WHERE x SIMILAR TO 'a%';
SELECT x FROM test3cs WHERE x ~ 'a';
+SET enable_hashagg TO off;
SELECT x FROM test1cs UNION SELECT x FROM test2cs ORDER BY x;
SELECT x FROM test2cs UNION SELECT x FROM test1cs ORDER BY x;
SELECT x FROM test1cs INTERSECT SELECT x FROM test2cs;
@@ -562,6 +563,7 @@ SELECT x FROM test2cs INTERSECT SELECT x FROM test1cs;
SELECT x FROM test1cs EXCEPT SELECT x FROM test2cs;
SELECT x FROM test2cs EXCEPT SELECT x FROM test1cs;
SELECT DISTINCT x FROM test3cs ORDER BY x;
+RESET enable_hashagg;
SELECT count(DISTINCT x) FROM test3cs;
SELECT x, count(*) FROM test3cs GROUP BY x ORDER BY x;
SELECT x, row_number() OVER (ORDER BY x), rank() OVER (ORDER BY x) FROM test3cs ORDER BY x;
diff --git a/src/test/regress/sql/union.sql b/src/test/regress/sql/union.sql
index d160db54588..8afc580c632 100644
--- a/src/test/regress/sql/union.sql
+++ b/src/test/regress/sql/union.sql
@@ -302,12 +302,12 @@ select except select;
set enable_hashagg = true;
set enable_sort = false;
-explain (costs off)
-select from generate_series(1,5) union select from generate_series(1,3);
+-- We've no way to check hashed UNION as the empty pathkeys in the Append are
+-- fine to make use of Unique, which is cheaper than HashAggregate and we've
+-- no means to disable Unique.
explain (costs off)
select from generate_series(1,5) intersect select from generate_series(1,3);
-select from generate_series(1,5) union select from generate_series(1,3);
select from generate_series(1,5) union all select from generate_series(1,3);
select from generate_series(1,5) intersect select from generate_series(1,3);
select from generate_series(1,5) intersect all select from generate_series(1,3);
@@ -330,6 +330,17 @@ select from generate_series(1,5) intersect all select from generate_series(1,3);
select from generate_series(1,5) except select from generate_series(1,3);
select from generate_series(1,5) except all select from generate_series(1,3);
+-- Try a variation of the above but with a CTE which contains a column, again
+-- with an empty final select list.
+
+-- Ensure we get the expected 1 row with 0 columns
+with cte as materialized (select s from generate_series(1,5) s)
+select from cte union select from cte;
+
+-- Ensure we get the same result as the above.
+with cte as not materialized (select s from generate_series(1,5) s)
+select from cte union select from cte;
+
reset enable_hashagg;
reset enable_sort;
@@ -361,6 +372,7 @@ INSERT INTO t2 VALUES ('ab'), ('xy');
set enable_seqscan = off;
set enable_indexscan = on;
set enable_bitmapscan = off;
+set enable_sort = off;
explain (costs off)
SELECT * FROM
@@ -407,6 +419,7 @@ explain (costs off)
reset enable_seqscan;
reset enable_indexscan;
reset enable_bitmapscan;
+reset enable_sort;
-- This simpler variant of the above test has been observed to fail differently