* Transform a grouping set and (recursively) its content. * * The grouping set might be a GROUPING SETS node with other grouping sets * inside it, but SETS within SETS have already been flattened out before * reaching here. * * Returns the transformed node, which now contains SIMPLE nodes with lists * of ressortgrouprefs rather than expressions. * * flatresult reference to flat list of So
| 2612 | * toplevel false if within any grouping set |
| 2613 | */ |
| 2614 | static Node * |
| 2615 | transformGroupingSet(List **flatresult, |
| 2616 | ParseState *pstate, GroupingSet *gset, |
| 2617 | List **targetlist, List *sortClause, |
| 2618 | ParseExprKind exprKind, bool useSQL99, bool toplevel) |
| 2619 | { |
| 2620 | ListCell *gl; |
| 2621 | List *content = NIL; |
| 2622 | |
| 2623 | Assert(toplevel || gset->kind != GROUPING_SET_SETS); |
| 2624 | |
| 2625 | foreach(gl, gset->content) |
| 2626 | { |
| 2627 | Node *n = lfirst(gl); |
| 2628 | |
| 2629 | if (IsA(n, List)) |
| 2630 | { |
| 2631 | List *l = transformGroupClauseList(flatresult, |
| 2632 | pstate, (List *) n, |
| 2633 | targetlist, sortClause, |
| 2634 | exprKind, useSQL99, false); |
| 2635 | |
| 2636 | content = lappend(content, makeGroupingSet(GROUPING_SET_SIMPLE, |
| 2637 | l, |
| 2638 | exprLocation(n))); |
| 2639 | } |
| 2640 | else if (IsA(n, GroupingSet)) |
| 2641 | { |
| 2642 | GroupingSet *gset2 = (GroupingSet *) lfirst(gl); |
| 2643 | |
| 2644 | content = lappend(content, transformGroupingSet(flatresult, |
| 2645 | pstate, gset2, |
| 2646 | targetlist, sortClause, |
| 2647 | exprKind, useSQL99, false)); |
| 2648 | } |
| 2649 | else |
| 2650 | { |
| 2651 | Index ref = transformGroupClauseExpr(flatresult, |
| 2652 | NULL, |
| 2653 | pstate, |
| 2654 | n, |
| 2655 | targetlist, |
| 2656 | sortClause, |
| 2657 | exprKind, |
| 2658 | useSQL99, |
| 2659 | false); |
| 2660 | |
| 2661 | content = lappend(content, makeGroupingSet(GROUPING_SET_SIMPLE, |
| 2662 | list_make1_int(ref), |
| 2663 | exprLocation(n))); |
| 2664 | } |
| 2665 | } |
| 2666 | |
| 2667 | /* Arbitrarily cap the size of CUBE, which has exponential growth */ |
| 2668 | if (gset->kind == GROUPING_SET_CUBE) |
| 2669 | { |
| 2670 | if (list_length(content) > 12) |
| 2671 | ereport(ERROR, |
no test coverage detected