Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit144666f

Browse files
committed
Build column mapping for grouping sets in all required cases.
The previous coding frequently failed to fail because for one it'sunusual to have rollup clauses with one column, and for anothersometimes the wrong mapping didn't cause obvious problems.Author: Jeevan ChalkeReviewed-By: Andrew GierthDiscussion: CAM2+6=W=9=hQOipH0HAPbkun3Z3TFWij_EiHue0_6UX=oR=1kw@mail.gmail.comBackpatch: 9.5, where grouping sets were introduced
1 parentcf80dde commit144666f

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

‎src/backend/optimizer/plan/planner.c

Lines changed: 2 additions & 7 deletions
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

Lines changed: 23 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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 (selectv.a, four, ten,count(*)from onekgroup by cube(four,ten)) son trueorder byv.a,four,ten;
163163
select array(select row(v.a,s1.*)from (select two,four,count(*)from onekgroup by cube(two,four)order by two,four) s1)from (values (1),(2)) v(a);
164164

165+
-- Grouping on text columns
166+
selectsum(ten)from onekgroup by two, rollup(four::text)order by1;
167+
selectsum(ten)from onekgroup by rollup(four::text), twoorder by1;
168+
165169
-- end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp