* Build transition/combine function invocations for all aggregate transition * / combination function invocations in a grouping sets phase. This has to * invoke all sort based transitions in a phase (if doSort is true), all hash * based transitions (if doHash is true), or both (both true). * * The resulting expression will, for each set of transition values, first * check for filters, evalua
| 3570 | * the array of AggStatePerGroup, and skip evaluation if so. |
| 3571 | */ |
| 3572 | ExprState * |
| 3573 | ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase, |
| 3574 | bool doSort, bool doHash, bool nullcheck) |
| 3575 | { |
| 3576 | ExprState *state = makeNode(ExprState); |
| 3577 | PlanState *parent = &aggstate->ss.ps; |
| 3578 | ExprEvalStep scratch = {0}; |
| 3579 | LastAttnumInfo deform = {0, 0, 0}; |
| 3580 | |
| 3581 | state->expr = (Expr *) aggstate; |
| 3582 | state->parent = parent; |
| 3583 | |
| 3584 | scratch.resvalue = &state->resvalue; |
| 3585 | scratch.resnull = &state->resnull; |
| 3586 | |
| 3587 | /* |
| 3588 | * First figure out which slots, and how many columns from each, we're |
| 3589 | * going to need. |
| 3590 | */ |
| 3591 | for (int transno = 0; transno < aggstate->numtrans; transno++) |
| 3592 | { |
| 3593 | AggStatePerTrans pertrans = &aggstate->pertrans[transno]; |
| 3594 | |
| 3595 | if (!bms_is_member(transno, aggstate->aggs_used)) |
| 3596 | continue; |
| 3597 | get_last_attnums_walker((Node *) pertrans->aggref->aggdirectargs, |
| 3598 | &deform); |
| 3599 | get_last_attnums_walker((Node *) pertrans->aggref->args, |
| 3600 | &deform); |
| 3601 | get_last_attnums_walker((Node *) pertrans->aggref->aggorder, |
| 3602 | &deform); |
| 3603 | get_last_attnums_walker((Node *) pertrans->aggref->aggdistinct, |
| 3604 | &deform); |
| 3605 | get_last_attnums_walker((Node *) pertrans->aggref->aggfilter, |
| 3606 | &deform); |
| 3607 | |
| 3608 | if (aggstate->AggExprId_AttrNum > 0) |
| 3609 | deform.last_outer = Max(deform.last_outer, |
| 3610 | aggstate->AggExprId_AttrNum); |
| 3611 | } |
| 3612 | ExecPushExprSlots(state, &deform); |
| 3613 | |
| 3614 | /* |
| 3615 | * Emit instructions for each transition value / grouping set combination. |
| 3616 | */ |
| 3617 | for (int transno = 0; transno < aggstate->numtrans; transno++) |
| 3618 | { |
| 3619 | AggStatePerTrans pertrans = &aggstate->pertrans[transno]; |
| 3620 | FunctionCallInfo trans_fcinfo = pertrans->transfn_fcinfo; |
| 3621 | List *adjust_bailout = NIL; |
| 3622 | NullableDatum *strictargs = NULL; |
| 3623 | bool *strictnulls = NULL; |
| 3624 | int argno; |
| 3625 | ListCell *bail; |
| 3626 | if (!bms_is_member(transno, aggstate->aggs_used)) |
| 3627 | continue; |
| 3628 | |
| 3629 | bool isCombine = DO_AGGSPLIT_COMBINE(pertrans->aggref->aggsplit); |
no test coverage detected