agora inbox for pgsql-bugs@postgresql.org
help / color / mirror / Atom feedBUG #19684: Assertion in tuplesort_begin_heap() falsified by parallel plan with sort
5+ messages / 3 participants
[nested] [flat]
* BUG #19684: Assertion in tuplesort_begin_heap() falsified by parallel plan with sort
@ 2026-09-11 20:00 PG Bug reporting form <noreply@postgresql.org>
0 siblings, 1 reply; 5+ messages in thread
From: PG Bug reporting form @ 2026-09-11 20:00 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: exclusion@gmail.com
The following bug has been logged on the website:
Bug reference: 19684
Logged by: Alexander Lakhin
Email address: exclusion@gmail.com
PostgreSQL version: 19beta3
Operating system: Ubuntu 24.04
Description:
The following script:
SET cpu_tuple_cost = 1000;
SET min_parallel_table_scan_size = 1;
CREATE TABLE t(i int);
SELECT FROM t UNION SELECT FROM t;
triggers:
TRAP: failed Assert("nkeys > 0"), File: "tuplesortvariants.c", Line: 195,
PID: 1465852
EXPLAIN shows:
QUERY PLAN
-----------------------------------------------------------------------------------------------
Unique (cost=3188844.07..3188856.82 rows=2 width=0)
-> Sort (cost=3188844.07..3188856.82 rows=5100 width=0)
-> Gather (cost=1000.00..3188530.00 rows=5100 width=0)
Workers Planned: 2
-> Parallel Append (cost=0.00..3187020.00 rows=2124
width=0)
-> Parallel Seq Scan on t (cost=0.00..1062510.00
rows=1062 width=0)
-> Parallel Seq Scan on t t_1 (cost=0.00..1062510.00
rows=1062 width=0)
Without asserts enabled, SELECT succeeds and EXPLAIN (ANALYZE) shows the
same plan.
Reproduced starting from 66c0185a3/12933dc60.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: BUG #19684: Assertion in tuplesort_begin_heap() falsified by parallel plan with sort
@ 2026-09-12 16:45 Ayush Tiwari <ayushtiwari.slg01@gmail.com>
parent: PG Bug reporting form <noreply@postgresql.org>
0 siblings, 2 replies; 5+ messages in thread
From: Ayush Tiwari @ 2026-09-12 16:45 UTC (permalink / raw)
To: exclusion@gmail.com; pgsql-bugs@lists.postgresql.org; +Cc: Robert Haas <robertmhaas@gmail.com>
Hi,
On Sat, 12 Sept 2026 at 20:33, PG Bug reporting form
<noreply@postgresql.org> wrote:
>
> The following bug has been logged on the website:
>
> Bug reference: 19684
> Logged by: Alexander Lakhin
> Email address: exclusion@gmail.com
> PostgreSQL version: 19beta3
> Operating system: Ubuntu 24.04
> Description:
>
> The following script:
> SET cpu_tuple_cost = 1000;
> SET min_parallel_table_scan_size = 1;
>
> CREATE TABLE t(i int);
> SELECT FROM t UNION SELECT FROM t;
>
> triggers:
> TRAP: failed Assert("nkeys > 0"), File: "tuplesortvariants.c", Line: 195,
> PID: 1465852
>
> EXPLAIN shows:
> QUERY PLAN
> -----------------------------------------------------------------------------------------------
> Unique (cost=3188844.07..3188856.82 rows=2 width=0)
> -> Sort (cost=3188844.07..3188856.82 rows=5100 width=0)
> -> Gather (cost=1000.00..3188530.00 rows=5100 width=0)
> Workers Planned: 2
> -> Parallel Append (cost=0.00..3187020.00 rows=2124
> width=0)
> -> Parallel Seq Scan on t (cost=0.00..1062510.00
> rows=1062 width=0)
> -> Parallel Seq Scan on t t_1 (cost=0.00..1062510.00
> rows=1062 width=0)
>
> Without asserts enabled, SELECT succeeds and EXPLAIN (ANALYZE) shows the
> same plan.
>
> Reproduced starting from 66c0185a3/12933dc60.
Thanks for the report!
It looks like the Gather path is missing the check already used for the
non-parallel Append path. For a zero-column UNION, groupList is NIL, but
the Gather path still creates a Sort and eventually calls
tuplesort_begin_heap() with zero sort keys.
I added the same "if (groupList != NIL)" condition around
create_sort_path() for the Gather path. With the patch, the reported test
and a variant using a populated table both complete successfully.
I wonder if we should also add an Assert(pathkeys != NIL) inside
create_sort_path()?
Regards,
Ayush
Attachments:
[application/octet-stream] v1-0001-Fix-zero-column-UNION-with-parallel-plans.patch (3.2K, ../../CAJTYsWWYE=BUx7oQLt2-NHe-rpZyiYuzPSOGxYX4MTW_wXYGnQ@mail.gmail.com/2-v1-0001-Fix-zero-column-UNION-with-parallel-plans.patch)
download | inline diff:
From be603a87641bf14eacb87113f1aa4c89dd2c0f32 Mon Sep 17 00:00:00 2001
From: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Date: Sat, 12 Sep 2026 21:34:17 +0530
Subject: [PATCH v1] Fix zero-column UNION with parallel plans
generate_union_paths() skips adding a Sort above an Append path for a
zero-column UNION, since such a set operation has no grouping columns.
The Gather path did not have the same check and could therefore produce
a Sort with no sort keys. tuplesort_begin_heap() does not support that
and fails its nkeys > 0 assertion.
Apply the same guard to the Gather path. Test with populated relations
so the test also exercises tuple processing in non-assert builds.
Reported-by: Alexander Lakhin <exclusion@gmail.com>
Bug: #19684
Backpatch-through: 17
---
src/backend/optimizer/prep/prepunion.c | 3 ++-
src/test/regress/expected/union.out | 21 +++++++++++++++++++++
src/test/regress/sql/union.sql | 11 +++++++++++
3 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/src/backend/optimizer/prep/prepunion.c b/src/backend/optimizer/prep/prepunion.c
index b136f12ff3b..0270f1e6b39 100644
--- a/src/backend/optimizer/prep/prepunion.c
+++ b/src/backend/optimizer/prep/prepunion.c
@@ -987,7 +987,8 @@ generate_union_paths(SetOperationStmt *op, PlannerInfo *root,
{
path = gpath;
- path = (Path *) create_sort_path(root, result_rel, path,
+ if (groupList != NIL)
+ path = (Path *) create_sort_path(root, result_rel, path,
make_pathkeys_for_sortclauses(root, groupList, tlist),
-1.0);
diff --git a/src/test/regress/expected/union.out b/src/test/regress/expected/union.out
index 84abcd6b14f..defc111478f 100644
--- a/src/test/regress/expected/union.out
+++ b/src/test/regress/expected/union.out
@@ -1085,6 +1085,27 @@ select from cte union select from cte;
--
(1 row)
+-- Ensure no sort is added to a parallel plan with no sort keys
+set cpu_tuple_cost = 1000;
+set min_parallel_table_scan_size = 1;
+explain (costs off)
+select from tenk1 union select from tenk1;
+ QUERY PLAN
+------------------------------------------------------
+ Unique
+ -> Gather
+ Workers Planned: 2
+ -> Parallel Append
+ -> Parallel Seq Scan on tenk1
+ -> Parallel Seq Scan on tenk1 tenk1_1
+(6 rows)
+
+select from tenk1 union select from tenk1;
+--
+(1 row)
+
+reset cpu_tuple_cost;
+reset min_parallel_table_scan_size;
reset enable_hashagg;
reset enable_groupagg;
--
diff --git a/src/test/regress/sql/union.sql b/src/test/regress/sql/union.sql
index c8de276c2b5..c1f00ef171d 100644
--- a/src/test/regress/sql/union.sql
+++ b/src/test/regress/sql/union.sql
@@ -362,6 +362,17 @@ select from cte union select from cte;
with cte as not materialized (select s from generate_series(1,5) s)
select from cte union select from cte;
+-- Ensure no sort is added to a parallel plan with no sort keys
+set cpu_tuple_cost = 1000;
+set min_parallel_table_scan_size = 1;
+
+explain (costs off)
+select from tenk1 union select from tenk1;
+select from tenk1 union select from tenk1;
+
+reset cpu_tuple_cost;
+reset min_parallel_table_scan_size;
+
reset enable_hashagg;
reset enable_groupagg;
--
2.34.1
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: BUG #19684: Assertion in tuplesort_begin_heap() falsified by parallel plan with sort
@ 2026-09-12 19:06 Samriddha Kumar Tripathi <sumitkumartripathi0@gmail.com>
parent: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
1 sibling, 0 replies; 5+ messages in thread
From: Samriddha Kumar Tripathi @ 2026-09-12 19:06 UTC (permalink / raw)
To: Ayush Tiwari <ayushtiwari.slg01@gmail.com>; +Cc: exclusion@gmail.com, pgsql-bugs@lists.postgresql.org, Robert Haas <robertmhaas@gmail.com>
Hi Ayush,
Thanks for the patch. I applied it and tested against the repro:
On unpatched master (with --enable-cassert), it crashes with the exact
reported assertion (Assert("nkeys > 0") in tuplesortvariants.c:195). With
your patch applied, the same query completes cleanly with (0 rows), no
crash.
On the Assert(pathkeys != NIL) question:
I tested it directly: with your guard temporarily removed but the assert
added to create_sort_path(), the same bug is caught immediately at
pathnode.c:2915 instead of downstream at tuplesortvariants.c:195. With the
guard back in place and the assert added, all 240 regression tests pass.
So the assert is safe to add, and it would make failures easier to diagnose
if some future caller makes the same mistake. That said, I'm not sure if
it's necessary, your guard already fixes the actual bug at its source, and
this call site is the only one that had the problem.
Regards,
Samriddha
On Sat, Sep 12, 2026 at 10:15 PM Ayush Tiwari <ayushtiwari.slg01@gmail.com>
wrote:
> Hi,
>
> On Sat, 12 Sept 2026 at 20:33, PG Bug reporting form
> <noreply@postgresql.org> wrote:
> >
> > The following bug has been logged on the website:
> >
> > Bug reference: 19684
> > Logged by: Alexander Lakhin
> > Email address: exclusion@gmail.com
> > PostgreSQL version: 19beta3
> > Operating system: Ubuntu 24.04
> > Description:
> >
> > The following script:
> > SET cpu_tuple_cost = 1000;
> > SET min_parallel_table_scan_size = 1;
> >
> > CREATE TABLE t(i int);
> > SELECT FROM t UNION SELECT FROM t;
> >
> > triggers:
> > TRAP: failed Assert("nkeys > 0"), File: "tuplesortvariants.c", Line: 195,
> > PID: 1465852
> >
> > EXPLAIN shows:
> > QUERY PLAN
> >
> -----------------------------------------------------------------------------------------------
> > Unique (cost=3188844.07..3188856.82 rows=2 width=0)
> > -> Sort (cost=3188844.07..3188856.82 rows=5100 width=0)
> > -> Gather (cost=1000.00..3188530.00 rows=5100 width=0)
> > Workers Planned: 2
> > -> Parallel Append (cost=0.00..3187020.00 rows=2124
> > width=0)
> > -> Parallel Seq Scan on t (cost=0.00..1062510.00
> > rows=1062 width=0)
> > -> Parallel Seq Scan on t t_1
> (cost=0.00..1062510.00
> > rows=1062 width=0)
> >
> > Without asserts enabled, SELECT succeeds and EXPLAIN (ANALYZE) shows the
> > same plan.
> >
> > Reproduced starting from 66c0185a3/12933dc60.
>
> Thanks for the report!
>
> It looks like the Gather path is missing the check already used for the
> non-parallel Append path. For a zero-column UNION, groupList is NIL, but
> the Gather path still creates a Sort and eventually calls
> tuplesort_begin_heap() with zero sort keys.
>
> I added the same "if (groupList != NIL)" condition around
> create_sort_path() for the Gather path. With the patch, the reported test
> and a variant using a populated table both complete successfully.
>
> I wonder if we should also add an Assert(pathkeys != NIL) inside
> create_sort_path()?
>
> Regards,
> Ayush
>
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: BUG #19684: Assertion in tuplesort_begin_heap() falsified by parallel plan with sort
@ 2026-09-13 06:36 Ayush Tiwari <ayushtiwari.slg01@gmail.com>
parent: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
1 sibling, 1 reply; 5+ messages in thread
From: Ayush Tiwari @ 2026-09-13 06:36 UTC (permalink / raw)
To: exclusion@gmail.com; pgsql-bugs@lists.postgresql.org; +Cc: Robert Haas <robertmhaas@gmail.com>
Hi,
On Sat, 12 Sept 2026 at 22:15, Ayush Tiwari <ayushtiwari.slg01@gmail.com> wrote:
>
> Hi,
>
> On Sat, 12 Sept 2026 at 20:33, PG Bug reporting form
> <noreply@postgresql.org> wrote:
> >
> > The following bug has been logged on the website:
> >
> > Bug reference: 19684
> > Logged by: Alexander Lakhin
> > Email address: exclusion@gmail.com
> > PostgreSQL version: 19beta3
> > Operating system: Ubuntu 24.04
> > Description:
> >
> > The following script:
> > SET cpu_tuple_cost = 1000;
> > SET min_parallel_table_scan_size = 1;
> >
> > CREATE TABLE t(i int);
> > SELECT FROM t UNION SELECT FROM t;
> >
> > triggers:
> > TRAP: failed Assert("nkeys > 0"), File: "tuplesortvariants.c", Line: 195,
> > PID: 1465852
> >
> > EXPLAIN shows:
> > QUERY PLAN
> > -----------------------------------------------------------------------------------------------
> > Unique (cost=3188844.07..3188856.82 rows=2 width=0)
> > -> Sort (cost=3188844.07..3188856.82 rows=5100 width=0)
> > -> Gather (cost=1000.00..3188530.00 rows=5100 width=0)
> > Workers Planned: 2
> > -> Parallel Append (cost=0.00..3187020.00 rows=2124
> > width=0)
> > -> Parallel Seq Scan on t (cost=0.00..1062510.00
> > rows=1062 width=0)
> > -> Parallel Seq Scan on t t_1 (cost=0.00..1062510.00
> > rows=1062 width=0)
> >
> > Without asserts enabled, SELECT succeeds and EXPLAIN (ANALYZE) shows the
> > same plan.
> >
> > Reproduced starting from 66c0185a3/12933dc60.
>
> Thanks for the report!
>
> It looks like the Gather path is missing the check already used for the
> non-parallel Append path. For a zero-column UNION, groupList is NIL, but
> the Gather path still creates a Sort and eventually calls
> tuplesort_begin_heap() with zero sort keys.
>
> I added the same "if (groupList != NIL)" condition around
> create_sort_path() for the Gather path. With the patch, the reported test
> and a variant using a populated table both complete successfully.
>
> I wonder if we should also add an Assert(pathkeys != NIL) inside
> create_sort_path()?
Attached v2.
The code change is unchanged. I adjusted the regression query because v1
caused unrelated Gather advice warnings under test_plan_advice.
Regards,
Ayush
Attachments:
[application/octet-stream] v2-0001-Fix-zero-column-UNION-with-parallel-plans.patch (3.1K, ../../CAJTYsWW4nJ++hX_DRspfPgiPFYg0iiRKUB_6PgQXjJzZqYHO1Q@mail.gmail.com/2-v2-0001-Fix-zero-column-UNION-with-parallel-plans.patch)
download | inline diff:
From c6be8c9ca7973214cedba601b0ecf4470f127a56 Mon Sep 17 00:00:00 2001
From: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Date: Sun, 13 Sep 2026 11:56:23 +0530
Subject: [PATCH v2] Fix zero-column UNION with parallel plans
generate_union_paths() skips adding a Sort above an Append path for a
zero-column UNION, since such a set operation has no grouping columns.
The Gather path did not have the same check and could therefore produce
a Sort with no sort keys. tuplesort_begin_heap() does not support that
and fails its nkeys > 0 assertion.
Apply the same guard to the Gather path. Test both the resulting plan
and execution using populated input.
Reported-by: Alexander Lakhin <exclusion@gmail.com>
Bug: #19684
Backpatch-through: 17
---
src/backend/optimizer/prep/prepunion.c | 3 ++-
src/test/regress/expected/union.out | 19 +++++++++++++++++++
src/test/regress/sql/union.sql | 11 +++++++++++
3 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/src/backend/optimizer/prep/prepunion.c b/src/backend/optimizer/prep/prepunion.c
index b136f12ff3b..0270f1e6b39 100644
--- a/src/backend/optimizer/prep/prepunion.c
+++ b/src/backend/optimizer/prep/prepunion.c
@@ -987,7 +987,8 @@ generate_union_paths(SetOperationStmt *op, PlannerInfo *root,
{
path = gpath;
- path = (Path *) create_sort_path(root, result_rel, path,
+ if (groupList != NIL)
+ path = (Path *) create_sort_path(root, result_rel, path,
make_pathkeys_for_sortclauses(root, groupList, tlist),
-1.0);
diff --git a/src/test/regress/expected/union.out b/src/test/regress/expected/union.out
index 84abcd6b14f..f513f5786b5 100644
--- a/src/test/regress/expected/union.out
+++ b/src/test/regress/expected/union.out
@@ -1085,6 +1085,25 @@ select from cte union select from cte;
--
(1 row)
+-- Ensure no sort is added to a parallel plan with no sort keys
+set cpu_tuple_cost = 1000;
+set min_parallel_table_scan_size = 1;
+explain (costs off)
+select from tenk1 union select from tenk2 where false;
+ QUERY PLAN
+----------------------------------------
+ Unique
+ -> Gather
+ Workers Planned: 2
+ -> Parallel Seq Scan on tenk1
+(4 rows)
+
+select from tenk1 union select from tenk2 where false;
+--
+(1 row)
+
+reset cpu_tuple_cost;
+reset min_parallel_table_scan_size;
reset enable_hashagg;
reset enable_groupagg;
--
diff --git a/src/test/regress/sql/union.sql b/src/test/regress/sql/union.sql
index c8de276c2b5..01444bd0c83 100644
--- a/src/test/regress/sql/union.sql
+++ b/src/test/regress/sql/union.sql
@@ -362,6 +362,17 @@ select from cte union select from cte;
with cte as not materialized (select s from generate_series(1,5) s)
select from cte union select from cte;
+-- Ensure no sort is added to a parallel plan with no sort keys
+set cpu_tuple_cost = 1000;
+set min_parallel_table_scan_size = 1;
+
+explain (costs off)
+select from tenk1 union select from tenk2 where false;
+select from tenk1 union select from tenk2 where false;
+
+reset cpu_tuple_cost;
+reset min_parallel_table_scan_size;
+
reset enable_hashagg;
reset enable_groupagg;
--
2.34.1
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: BUG #19684: Assertion in tuplesort_begin_heap() falsified by parallel plan with sort
@ 2026-09-14 09:34 Ayush Tiwari <ayushtiwari.slg01@gmail.com>
parent: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
0 siblings, 0 replies; 5+ messages in thread
From: Ayush Tiwari @ 2026-09-14 09:34 UTC (permalink / raw)
To: exclusion@gmail.com; pgsql-bugs@lists.postgresql.org; +Cc: Robert Haas <robertmhaas@gmail.com>
On Sun, 13 Sept 2026 at 12:06, Ayush Tiwari <ayushtiwari.slg01@gmail.com> wrote:
>
> Hi,
>
> On Sat, 12 Sept 2026 at 22:15, Ayush Tiwari <ayushtiwari.slg01@gmail.com> wrote:
> >
> > Hi,
> >
> > On Sat, 12 Sept 2026 at 20:33, PG Bug reporting form
> > <noreply@postgresql.org> wrote:
> > >
> > > The following bug has been logged on the website:
> > >
> > > Bug reference: 19684
> > > Logged by: Alexander Lakhin
> > > Email address: exclusion@gmail.com
> > > PostgreSQL version: 19beta3
> > > Operating system: Ubuntu 24.04
> > > Description:
> > >
> > > The following script:
> > > SET cpu_tuple_cost = 1000;
> > > SET min_parallel_table_scan_size = 1;
> > >
> > > CREATE TABLE t(i int);
> > > SELECT FROM t UNION SELECT FROM t;
> > >
> > > triggers:
> > > TRAP: failed Assert("nkeys > 0"), File: "tuplesortvariants.c", Line: 195,
> > > PID: 1465852
> > >
> > > EXPLAIN shows:
> > > QUERY PLAN
> > > -----------------------------------------------------------------------------------------------
> > > Unique (cost=3188844.07..3188856.82 rows=2 width=0)
> > > -> Sort (cost=3188844.07..3188856.82 rows=5100 width=0)
> > > -> Gather (cost=1000.00..3188530.00 rows=5100 width=0)
> > > Workers Planned: 2
> > > -> Parallel Append (cost=0.00..3187020.00 rows=2124
> > > width=0)
> > > -> Parallel Seq Scan on t (cost=0.00..1062510.00
> > > rows=1062 width=0)
> > > -> Parallel Seq Scan on t t_1 (cost=0.00..1062510.00
> > > rows=1062 width=0)
> > >
> > > Without asserts enabled, SELECT succeeds and EXPLAIN (ANALYZE) shows the
> > > same plan.
> > >
> > > Reproduced starting from 66c0185a3/12933dc60.
> >
> > Thanks for the report!
> >
> > It looks like the Gather path is missing the check already used for the
> > non-parallel Append path. For a zero-column UNION, groupList is NIL, but
> > the Gather path still creates a Sort and eventually calls
> > tuplesort_begin_heap() with zero sort keys.
> >
> > I added the same "if (groupList != NIL)" condition around
> > create_sort_path() for the Gather path. With the patch, the reported test
> > and a variant using a populated table both complete successfully.
> >
> > I wonder if we should also add an Assert(pathkeys != NIL) inside
> > create_sort_path()?
Attached is v3 with a minor correction to the regression test, so that
it exercises the affected path. The code change is unchanged.
Regards,
Ayush
Attachments:
[application/octet-stream] v3-0001-Fix-zero-column-UNION-with-parallel-plans.patch (3.4K, ../../CAJTYsWXnTQgH3m5a_bc4C+pumKj_fiEs4ZqaCjs8L8wvcrsy3g@mail.gmail.com/2-v3-0001-Fix-zero-column-UNION-with-parallel-plans.patch)
download | inline diff:
From 2f7dc4dc3491a6c4c46fea714844bb4e4e7e47c5 Mon Sep 17 00:00:00 2001
From: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Date: Mon, 14 Sep 2026 14:40:28 +0530
Subject: [PATCH v3] Fix zero-column UNION with parallel plans
generate_union_paths() skips adding a Sort above an Append path for a
zero-column UNION, since such a set operation has no grouping columns.
The Gather path did not have the same check and could therefore produce
a Sort with no sort keys. tuplesort_begin_heap() does not support that
and fails its nkeys > 0 assertion.
Apply the same guard to the Gather path. Test both the resulting plan
and execution using populated input.
Reported-by: Alexander Lakhin <exclusion@gmail.com>
Bug: #19684
Backpatch-through: 17
---
src/backend/optimizer/prep/prepunion.c | 3 ++-
src/test/regress/expected/union.out | 24 ++++++++++++++++++++++++
src/test/regress/sql/union.sql | 14 ++++++++++++++
3 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/src/backend/optimizer/prep/prepunion.c b/src/backend/optimizer/prep/prepunion.c
index b136f12ff3b..0270f1e6b39 100644
--- a/src/backend/optimizer/prep/prepunion.c
+++ b/src/backend/optimizer/prep/prepunion.c
@@ -987,7 +987,8 @@ generate_union_paths(SetOperationStmt *op, PlannerInfo *root,
{
path = gpath;
- path = (Path *) create_sort_path(root, result_rel, path,
+ if (groupList != NIL)
+ path = (Path *) create_sort_path(root, result_rel, path,
make_pathkeys_for_sortclauses(root, groupList, tlist),
-1.0);
diff --git a/src/test/regress/expected/union.out b/src/test/regress/expected/union.out
index 84abcd6b14f..1611ae60ee5 100644
--- a/src/test/regress/expected/union.out
+++ b/src/test/regress/expected/union.out
@@ -1085,6 +1085,30 @@ select from cte union select from cte;
--
(1 row)
+-- Ensure no sort is added to a parallel plan with no sort keys
+-- test_plan_advice cannot enforce Gather advice for a set operation
+set client_min_messages = error;
+set cpu_tuple_cost = 1000;
+set min_parallel_table_scan_size = 1;
+explain (costs off)
+select from tenk1 union select from tenk2;
+ QUERY PLAN
+----------------------------------------------
+ Unique
+ -> Gather
+ Workers Planned: 2
+ -> Parallel Append
+ -> Parallel Seq Scan on tenk1
+ -> Parallel Seq Scan on tenk2
+(6 rows)
+
+select from tenk1 union select from tenk2;
+--
+(1 row)
+
+reset cpu_tuple_cost;
+reset min_parallel_table_scan_size;
+reset client_min_messages;
reset enable_hashagg;
reset enable_groupagg;
--
diff --git a/src/test/regress/sql/union.sql b/src/test/regress/sql/union.sql
index c8de276c2b5..9c3061946e0 100644
--- a/src/test/regress/sql/union.sql
+++ b/src/test/regress/sql/union.sql
@@ -362,6 +362,20 @@ select from cte union select from cte;
with cte as not materialized (select s from generate_series(1,5) s)
select from cte union select from cte;
+-- Ensure no sort is added to a parallel plan with no sort keys
+-- test_plan_advice cannot enforce Gather advice for a set operation
+set client_min_messages = error;
+set cpu_tuple_cost = 1000;
+set min_parallel_table_scan_size = 1;
+
+explain (costs off)
+select from tenk1 union select from tenk2;
+select from tenk1 union select from tenk2;
+
+reset cpu_tuple_cost;
+reset min_parallel_table_scan_size;
+reset client_min_messages;
+
reset enable_hashagg;
reset enable_groupagg;
--
2.34.1
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2026-09-14 09:34 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-09-11 20:00 BUG #19684: Assertion in tuplesort_begin_heap() falsified by parallel plan with sort PG Bug reporting form <noreply@postgresql.org>
2026-09-12 16:45 ` Ayush Tiwari <ayushtiwari.slg01@gmail.com>
2026-09-12 19:06 ` Samriddha Kumar Tripathi <sumitkumartripathi0@gmail.com>
2026-09-13 06:36 ` Ayush Tiwari <ayushtiwari.slg01@gmail.com>
2026-09-14 09:34 ` Ayush Tiwari <ayushtiwari.slg01@gmail.com>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox