From c85e4cd77d836b73201cefa47cfca776f26903f2 Mon Sep 17 00:00:00 2001 From: Shihao Date: Fri, 18 Sep 2026 22:44:39 -0400 Subject: [PATCH v1 2/2] Add test for Gather rescan with a changing tuple bound Rescan a Limit over Gather Merge, with a limit count that comes from the outer side of a nested loop and grows on the second scan. The leader does not take part, so the result shows whether the workers saw the new bound. Discussion: https://postgr.es/m/2701c83e33f3fe66320291fb5d1b74ca2cb90bd7.camel@j-davis.com --- src/test/regress/expected/select_parallel.out | 30 +++++++++++++++++++ src/test/regress/sql/select_parallel.sql | 13 ++++++++ 2 files changed, 43 insertions(+) diff --git a/src/test/regress/expected/select_parallel.out b/src/test/regress/expected/select_parallel.out index e1344215644..4467944e179 100644 --- a/src/test/regress/expected/select_parallel.out +++ b/src/test/regress/expected/select_parallel.out @@ -526,6 +526,36 @@ select count(*) from tenk1 --reset the value of workers for each table as it was before this test. alter table tenk1 set (parallel_workers = 4); alter table tenk2 reset (parallel_workers); +-- likewise, but the Limit's bound changes between rescans; the workers +-- must see the new bound, not the one from the first scan. +set parallel_leader_participation = off; +explain (costs off) +select v.n, ss.* from (values (1), (10)) v(n), + lateral (select count(*), sum(unique1) from + (select unique1 from tenk2 order by 1 limit v.n) x) ss; + QUERY PLAN +---------------------------------------------------------- + Nested Loop + -> Values Scan on "*VALUES*" + -> Aggregate + -> Limit + -> Gather Merge + Workers Planned: 4 + -> Sort + Sort Key: tenk2.unique1 + -> Parallel Seq Scan on tenk2 +(9 rows) + +select v.n, ss.* from (values (1), (10)) v(n), + lateral (select count(*), sum(unique1) from + (select unique1 from tenk2 order by 1 limit v.n) x) ss; + n | count | sum +----+-------+----- + 1 | 1 | 0 + 10 | 10 | 45 +(2 rows) + +reset parallel_leader_participation; reset enable_material; reset enable_bitmapscan; reset enable_indexonlyscan; diff --git a/src/test/regress/sql/select_parallel.sql b/src/test/regress/sql/select_parallel.sql index 71a75bc86ea..df7d0901193 100644 --- a/src/test/regress/sql/select_parallel.sql +++ b/src/test/regress/sql/select_parallel.sql @@ -196,10 +196,23 @@ select count(*) from tenk1 left join (select tenk2.unique1 from tenk2 order by 1 limit 1000) ss on tenk1.unique1 < ss.unique1 + 1 where tenk1.unique1 < 2; + --reset the value of workers for each table as it was before this test. alter table tenk1 set (parallel_workers = 4); alter table tenk2 reset (parallel_workers); +-- likewise, but the Limit's bound changes between rescans; the workers +-- must see the new bound, not the one from the first scan. +set parallel_leader_participation = off; +explain (costs off) +select v.n, ss.* from (values (1), (10)) v(n), + lateral (select count(*), sum(unique1) from + (select unique1 from tenk2 order by 1 limit v.n) x) ss; +select v.n, ss.* from (values (1), (10)) v(n), + lateral (select count(*), sum(unique1) from + (select unique1 from tenk2 order by 1 limit v.n) x) ss; +reset parallel_leader_participation; + reset enable_material; reset enable_bitmapscan; reset enable_indexonlyscan; -- 2.37.1 (Apple Git-137.1)