Skip to content

Commit 9332435

Browse files
committed
Pass incompletely-transformed aggregate argument lists as separate parameters
to transformAggregateCall, instead of abusing fields in Aggref to carry them temporarily. No change in functionality but hopefully the code is a bit clearer now. Per gripe from Gokulakannan Somasundaram.
1 parent f248e11 commit 9332435

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

src/backend/parser/parse_agg.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/parser/parse_agg.c,v 1.92 2010/02/26 02:00:49 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/parser/parse_agg.c,v 1.93 2010/03/17 16:52:38 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -44,10 +44,11 @@ static bool check_ungrouped_columns_walker(Node *node,
4444
* transformAggregateCall -
4545
* Finish initial transformation of an aggregate call
4646
*
47-
* parse_func.c has recognized the function as an aggregate, and has set
48-
* up all the fields of the Aggref except aggdistinct and agglevelsup.
49-
* However, the args list is just bare expressions, and the aggorder list
50-
* hasn't been transformed at all.
47+
* parse_func.c has recognized the function as an aggregate, and has set up
48+
* all the fields of the Aggref except args, aggorder, aggdistinct and
49+
* agglevelsup. The passed-in args list has been through standard expression
50+
* transformation, while the passed-in aggorder list hasn't been transformed
51+
* at all.
5152
*
5253
* Here we convert the args list into a targetlist by inserting TargetEntry
5354
* nodes, and then transform the aggorder and agg_distinct specifications to
@@ -59,7 +60,8 @@ static bool check_ungrouped_columns_walker(Node *node,
5960
* pstate level.
6061
*/
6162
void
62-
transformAggregateCall(ParseState *pstate, Aggref *agg, bool agg_distinct)
63+
transformAggregateCall(ParseState *pstate, Aggref *agg,
64+
List *args, List *aggorder, bool agg_distinct)
6365
{
6466
List *tlist;
6567
List *torder;
@@ -75,7 +77,7 @@ transformAggregateCall(ParseState *pstate, Aggref *agg, bool agg_distinct)
7577
*/
7678
tlist = NIL;
7779
attno = 1;
78-
foreach(lc, agg->args)
80+
foreach(lc, args)
7981
{
8082
Expr *arg = (Expr *) lfirst(lc);
8183
TargetEntry *tle = makeTargetEntry(arg, attno++, NULL, false);
@@ -96,7 +98,7 @@ transformAggregateCall(ParseState *pstate, Aggref *agg, bool agg_distinct)
9698
pstate->p_next_resno = attno;
9799

98100
torder = transformSortClause(pstate,
99-
agg->aggorder,
101+
aggorder,
100102
&tlist,
101103
true /* fix unknowns */ ,
102104
true /* force SQL99 rules */ );

src/backend/parser/parse_func.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/parser/parse_func.c,v 1.222 2010/02/26 02:00:52 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/parser/parse_func.c,v 1.223 2010/03/17 16:52:38 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -381,10 +381,7 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
381381

382382
aggref->aggfnoid = funcid;
383383
aggref->aggtype = rettype;
384-
/* args and aggorder will be modified by transformAggregateCall */
385-
aggref->args = fargs;
386-
aggref->aggorder = agg_order;
387-
/* aggdistinct will be set by transformAggregateCall */
384+
/* args, aggorder, aggdistinct will be set by transformAggregateCall */
388385
aggref->aggstar = agg_star;
389386
/* agglevelsup will be set by transformAggregateCall */
390387
aggref->location = location;
@@ -419,7 +416,7 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
419416
parser_errposition(pstate, location)));
420417

421418
/* parse_agg.c does additional aggregate-specific processing */
422-
transformAggregateCall(pstate, aggref, agg_distinct);
419+
transformAggregateCall(pstate, aggref, fargs, agg_order, agg_distinct);
423420

424421
retval = (Node *) aggref;
425422
}

src/include/parser/parse_agg.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/parser/parse_agg.h,v 1.42 2010/02/26 02:01:26 momjian Exp $
9+
* $PostgreSQL: pgsql/src/include/parser/parse_agg.h,v 1.43 2010/03/17 16:52:38 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -16,6 +16,7 @@
1616
#include "parser/parse_node.h"
1717

1818
extern void transformAggregateCall(ParseState *pstate, Aggref *agg,
19+
List *args, List *aggorder,
1920
bool agg_distinct);
2021
extern void transformWindowFuncCall(ParseState *pstate, WindowFunc *wfunc,
2122
WindowDef *windef);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy