1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-18 17:42:25 +03:00

Fix mishandling of sortgroupref labels while splitting SRF targetlists.

split_pathtarget_at_srfs() neglected to worry about sortgroupref labels
in the intermediate PathTargets it constructs.  I think we'd supposed
that their labeling didn't matter, but it does at least for the case that
GroupAggregate/GatherMerge nodes appear immediately under the ProjectSet
step(s).  This results in "ERROR: ORDER/GROUP BY expression not found in
targetlist" during create_plan(), as reported by Rajkumar Raghuwanshi.

To fix, make this logic track the sortgroupref labeling of expressions,
not just their contents.  This also restores the pre-v10 behavior that
separate GROUP BY expressions will be kept distinct even if they are
textually equal().

Discussion: https://postgr.es/m/CAKcux6=1_Ye9kx8YLBPmJs_xE72PPc6vNi5q2AOHowMaCWjJ2w@mail.gmail.com
This commit is contained in:
Tom Lane
2018-06-21 10:58:42 -04:00
parent bee6a683a5
commit 07e5a21352
3 changed files with 198 additions and 17 deletions

View File

@ -659,6 +659,68 @@ explain (costs off, verbose)
(11 rows)
drop function sp_simple_func(integer);
-- test handling of SRFs in targetlist (bug in 10.0)
explain (costs off)
select count(*), generate_series(1,2) from tenk1 group by twenty;
QUERY PLAN
----------------------------------------------------------
ProjectSet
-> Finalize GroupAggregate
Group Key: twenty
-> Gather Merge
Workers Planned: 4
-> Partial GroupAggregate
Group Key: twenty
-> Sort
Sort Key: twenty
-> Parallel Seq Scan on tenk1
(10 rows)
select count(*), generate_series(1,2) from tenk1 group by twenty;
count | generate_series
-------+-----------------
500 | 1
500 | 2
500 | 1
500 | 2
500 | 1
500 | 2
500 | 1
500 | 2
500 | 1
500 | 2
500 | 1
500 | 2
500 | 1
500 | 2
500 | 1
500 | 2
500 | 1
500 | 2
500 | 1
500 | 2
500 | 1
500 | 2
500 | 1
500 | 2
500 | 1
500 | 2
500 | 1
500 | 2
500 | 1
500 | 2
500 | 1
500 | 2
500 | 1
500 | 2
500 | 1
500 | 2
500 | 1
500 | 2
500 | 1
500 | 2
(40 rows)
-- test gather merge with parallel leader participation disabled
set parallel_leader_participation = off;
explain (costs off)

View File

@ -261,6 +261,13 @@ explain (costs off, verbose)
drop function sp_simple_func(integer);
-- test handling of SRFs in targetlist (bug in 10.0)
explain (costs off)
select count(*), generate_series(1,2) from tenk1 group by twenty;
select count(*), generate_series(1,2) from tenk1 group by twenty;
-- test gather merge with parallel leader participation disabled
set parallel_leader_participation = off;