int aggno;
bool hasGroupingSets = aggstate->numsets > 0;
int numGroupingSets = Max(aggstate->numsets, 1);
- int currentSet = 0;
- int nextSetSize = 0;
- int numReset = 1;
+ int currentSet;
+ int nextSetSize;
+ int numReset;
int i;
/*
/*
* Determine how many grouping sets need to be reset at this boundary.
*/
- if (aggstate->projected_set >= 0 && aggstate->projected_set < numGroupingSets)
+ if (aggstate->projected_set >= 0 &&
+ aggstate->projected_set < numGroupingSets)
numReset = aggstate->projected_set + 1;
else
numReset = numGroupingSets;
ReScanExprContext(aggstate->aggcontexts[i]);
}
- /* Check if input is complete and there are no more groups to project. */
- if (aggstate->input_done == true
- && aggstate->projected_set >= (numGroupingSets - 1))
+ /*
+ * Check if input is complete and there are no more groups to project.
+ */
+ if (aggstate->input_done == true &&
+ aggstate->projected_set >= (numGroupingSets - 1))
{
aggstate->agg_done = true;
break;
* projected one (if any). This is the number of columns to compare to
* see if we reached the boundary of that set too.
*/
- if (aggstate->projected_set >= 0 && aggstate->projected_set < (numGroupingSets - 1))
+ if (aggstate->projected_set >= 0 &&
+ aggstate->projected_set < (numGroupingSets - 1))
nextSetSize = aggstate->gset_lengths[aggstate->projected_set + 1];
else
nextSetSize = 0;
* - the previous and pending rows differ on the grouping columns
* of the next grouping set
*/
- if (aggstate->input_done
- || (node->aggstrategy == AGG_SORTED
- && aggstate->projected_set != -1
- && aggstate->projected_set < (numGroupingSets - 1)
- && nextSetSize > 0
- && !execTuplesMatch(econtext->ecxt_outertuple,
- tmpcontext->ecxt_outertuple,
- nextSetSize,
- node->grpColIdx,
- aggstate->eqfunctions,
- tmpcontext->ecxt_per_tuple_memory)))
+ if (aggstate->input_done ||
+ (node->aggstrategy == AGG_SORTED &&
+ aggstate->projected_set != -1 &&
+ aggstate->projected_set < (numGroupingSets - 1) &&
+ nextSetSize > 0 &&
+ !execTuplesMatch(econtext->ecxt_outertuple,
+ tmpcontext->ecxt_outertuple,
+ nextSetSize,
+ node->grpColIdx,
+ aggstate->eqfunctions,
+ tmpcontext->ecxt_per_tuple_memory)))
{
aggstate->projected_set += 1;
aggstate->projected_set = 0;
/*
- * If we don't already have the first tuple of the new group, fetch
- * it from the outer plan.
+ * If we don't already have the first tuple of the new group,
+ * fetch it from the outer plan.
*/
if (aggstate->grp_firstTuple == NULL)
{
if (!TupIsNull(outerslot))
{
/*
- * Make a copy of the first input tuple; we will use this for
- * comparisons (in group mode) and for projection.
+ * Make a copy of the first input tuple; we will use this
+ * for comparisons (in group mode) and for projection.
*/
aggstate->grp_firstTuple = ExecCopySlotTuple(outerslot);
}
econtext->ecxt_outertuple = firstSlot;
- while (!TupIsNull(firstSlot)
- && (TupIsNull(outerslot)
- || !execTuplesMatch(firstSlot,
- outerslot,
- aggstate->gset_lengths[currentSet],
- node->grpColIdx,
- aggstate->eqfunctions,
- tmpcontext->ecxt_per_tuple_memory)))
+ while (!TupIsNull(firstSlot) &&
+ (TupIsNull(outerslot) ||
+ !execTuplesMatch(firstSlot,
+ outerslot,
+ aggstate->gset_lengths[currentSet],
+ node->grpColIdx,
+ aggstate->eqfunctions,
+ tmpcontext->ecxt_per_tuple_memory)))
{
aggstate->current_set = aggstate->projected_set = currentSet;
/*
* set_group_vars
- * Modify any Var references in the target list of a non-trivial
- * (i.e. contains grouping sets) Agg node to use GroupedVar instead,
- * which will conditionally replace them with nulls at runtime.
+ * Modify any Var references in the target list of a grouping sets
+ * containing Agg node to use GroupedVar instead, which will conditionally
+ * replace them with nulls at runtime.
*/
static void
set_group_vars(PlannerInfo *root, Agg *agg)
set_group_vars_context context;
AttrNumber *groupColIdx = root->groupColIdx;
int numCols = list_length(root->parse->groupClause);
- int i;
+ int i;
Bitmapset *cols = NULL;
if (!agg->groupingSets)
context.groupedcols = cols;
- agg->plan.targetlist = (List *) set_group_vars_mutator((Node *) agg->plan.targetlist,
- &context);
- agg->plan.qual = (List *) set_group_vars_mutator((Node *) agg->plan.qual,
- &context);
+ agg->plan.targetlist = (List *)
+ set_group_vars_mutator((Node *) agg->plan.targetlist,
+ &context);
+ agg->plan.qual = (List *)
+ set_group_vars_mutator((Node *) agg->plan.qual,
+ &context);
}
static Node *
{
Var *var = (Var *) node;
- if (var->varno == OUTER_VAR
- && bms_is_member(var->varattno, context->groupedcols))
+ if (var->varno == OUTER_VAR &&
+ bms_is_member(var->varattno, context->groupedcols))
{
var = copyVar(var);
var->xpr.type = T_GroupedVar;