Minor cleanups from a patch read through.
authorAndres Freund <andres@anarazel.de>
Tue, 12 May 2015 23:51:58 +0000 (01:51 +0200)
committerAndres Freund <andres@anarazel.de>
Tue, 12 May 2015 23:51:58 +0000 (01:51 +0200)
src/backend/executor/nodeAgg.c
src/backend/optimizer/plan/setrefs.c
src/backend/parser/parse_agg.c
src/backend/parser/parse_clause.c

index 5c86c1f74684d4952b56f129dee49c7445f8ccc6..fcce30cdc176469167a3ff50c853a6c9dc4488b8 100644 (file)
@@ -1256,9 +1256,9 @@ agg_retrieve_direct(AggState *aggstate)
    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;
 
    /*
@@ -1303,7 +1303,8 @@ agg_retrieve_direct(AggState *aggstate)
        /*
         * 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;
@@ -1313,9 +1314,11 @@ agg_retrieve_direct(AggState *aggstate)
            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;
@@ -1326,7 +1329,8 @@ agg_retrieve_direct(AggState *aggstate)
         * 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;
@@ -1347,17 +1351,17 @@ agg_retrieve_direct(AggState *aggstate)
         *    - 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;
 
@@ -1374,8 +1378,8 @@ agg_retrieve_direct(AggState *aggstate)
            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)
            {
@@ -1383,8 +1387,8 @@ agg_retrieve_direct(AggState *aggstate)
                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);
                }
@@ -1613,14 +1617,14 @@ agg_retrieve_chained(AggState *aggstate)
 
    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;
 
index 73a9168e57bac012dd6583d9794bb55680d1f439..f1fa1510c31e7c65b4a6a062d6a58ed66776ccab 100644 (file)
@@ -1453,9 +1453,9 @@ fix_scan_expr_walker(Node *node, fix_scan_expr_context *context)
 
 /*
  * 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)
@@ -1463,7 +1463,7 @@ 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)
@@ -1482,10 +1482,12 @@ set_group_vars(PlannerInfo *root, Agg *agg)
 
    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 *
@@ -1497,8 +1499,8 @@ set_group_vars_mutator(Node *node, set_group_vars_context *context)
    {
        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;
index 19391d0f619ae9c27defebab4e3758ea8624e70a..f8d361de808de57a24ed1f1dfbddf465f03ace1b 100644 (file)
@@ -1058,8 +1058,8 @@ parseCheckAggregates(ParseState *pstate, Query *qry)
        {
            have_non_var_grouping = true;
        }
-       else if (!qry->groupingSets
-                || list_member_int(gset_common, tle->ressortgroupref))
+       else if (!qry->groupingSets ||
+                list_member_int(gset_common, tle->ressortgroupref))
        {
            groupClauseCommonVars = lappend(groupClauseCommonVars, tle->expr);
        }
@@ -1246,7 +1246,7 @@ check_ungrouped_columns_walker(Node *node,
        {
            foreach(gl, context->groupClauses)
            {
-               Var        *gvar = (Var *) ((TargetEntry *)lfirst(gl))->expr;
+               Var        *gvar = (Var *) ((TargetEntry *) lfirst(gl))->expr;
 
                if (IsA(gvar, Var) &&
                    gvar->varno == var->varno &&
index cfed28d423389ad45f6089691efcc85b1f08b9b5..d7d671f36a4b2eda17da78b66a961b8988c797e5 100644 (file)
@@ -1670,7 +1670,6 @@ findTargetlistEntrySQL99(ParseState *pstate, Node *node, List **tlist,
    return target_result;
 }
 
-
 /*
  * Flatten out parenthesized sublists in grouping lists, and some cases
  * of nested grouping sets.