Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 144666f

Browse files
committed
Build column mapping for grouping sets in all required cases.
The previous coding frequently failed to fail because for one it's unusual to have rollup clauses with one column, and for another sometimes the wrong mapping didn't cause obvious problems. Author: Jeevan Chalke Reviewed-By: Andrew Gierth Discussion: CAM2+6=W=9=hQOipH0HAPbkun3Z3TFWij_EiHue0_6UX=oR=1kw@mail.gmail.com Backpatch: 9.5, where grouping sets were introduced
1 parent cf80dde commit 144666f

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

src/backend/optimizer/plan/planner.c

+2-7
Original file line numberDiff line numberDiff line change
@@ -2401,13 +2401,8 @@ build_grouping_chain(PlannerInfo *root,
24012401
* Prepare the grpColIdx for the real Agg node first, because we may need
24022402
* it for sorting
24032403
*/
2404-
if (list_length(rollup_groupclauses) > 1)
2405-
{
2406-
Assert(rollup_lists && llast(rollup_lists));
2407-
2408-
top_grpColIdx =
2409-
remap_groupColIdx(root, llast(rollup_groupclauses));
2410-
}
2404+
if (parse->groupingSets)
2405+
top_grpColIdx = remap_groupColIdx(root, llast(rollup_groupclauses));
24112406

24122407
/*
24132408
* If we need a Sort operation on the input, generate that.

src/test/regress/expected/groupingsets.out

+23
Original file line numberDiff line numberDiff line change
@@ -587,4 +587,27 @@ select array(select row(v.a,s1.*) from (select two,four, count(*) from onek grou
587587
{"(2,0,0,250)","(2,0,2,250)","(2,0,,500)","(2,1,1,250)","(2,1,3,250)","(2,1,,500)","(2,,0,250)","(2,,1,250)","(2,,2,250)","(2,,3,250)","(2,,,1000)"}
588588
(2 rows)
589589

590+
-- Grouping on text columns
591+
select sum(ten) from onek group by two, rollup(four::text) order by 1;
592+
sum
593+
------
594+
1000
595+
1000
596+
1250
597+
1250
598+
2000
599+
2500
600+
(6 rows)
601+
602+
select sum(ten) from onek group by rollup(four::text), two order by 1;
603+
sum
604+
------
605+
1000
606+
1000
607+
1250
608+
1250
609+
2000
610+
2500
611+
(6 rows)
612+
590613
-- end

src/test/regress/sql/groupingsets.sql

+4
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,8 @@ group by rollup(ten);
162162
select * from (values (1),(2)) v(a) left join lateral (select v.a, four, ten, count(*) from onek group by cube(four,ten)) s on true order by v.a,four,ten;
163163
select array(select row(v.a,s1.*) from (select two,four, count(*) from onek group by cube(two,four) order by two,four) s1) from (values (1),(2)) v(a);
164164

165+
-- Grouping on text columns
166+
select sum(ten) from onek group by two, rollup(four::text) order by 1;
167+
select sum(ten) from onek group by rollup(four::text), two order by 1;
168+
165169
-- end

0 commit comments

Comments
 (0)