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.
This commit is contained in:
parent
f248e11f70
commit
93324355eb
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/parser/parse_agg.c,v 1.92 2010/02/26 02:00:49 momjian Exp $
|
* $PostgreSQL: pgsql/src/backend/parser/parse_agg.c,v 1.93 2010/03/17 16:52:38 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -44,10 +44,11 @@ static bool check_ungrouped_columns_walker(Node *node,
|
|||||||
* transformAggregateCall -
|
* transformAggregateCall -
|
||||||
* Finish initial transformation of an aggregate call
|
* Finish initial transformation of an aggregate call
|
||||||
*
|
*
|
||||||
* parse_func.c has recognized the function as an aggregate, and has set
|
* parse_func.c has recognized the function as an aggregate, and has set up
|
||||||
* up all the fields of the Aggref except aggdistinct and agglevelsup.
|
* all the fields of the Aggref except args, aggorder, aggdistinct and
|
||||||
* However, the args list is just bare expressions, and the aggorder list
|
* agglevelsup. The passed-in args list has been through standard expression
|
||||||
* hasn't been transformed at all.
|
* transformation, while the passed-in aggorder list hasn't been transformed
|
||||||
|
* at all.
|
||||||
*
|
*
|
||||||
* Here we convert the args list into a targetlist by inserting TargetEntry
|
* Here we convert the args list into a targetlist by inserting TargetEntry
|
||||||
* nodes, and then transform the aggorder and agg_distinct specifications to
|
* nodes, and then transform the aggorder and agg_distinct specifications to
|
||||||
@ -59,7 +60,8 @@ static bool check_ungrouped_columns_walker(Node *node,
|
|||||||
* pstate level.
|
* pstate level.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
transformAggregateCall(ParseState *pstate, Aggref *agg, bool agg_distinct)
|
transformAggregateCall(ParseState *pstate, Aggref *agg,
|
||||||
|
List *args, List *aggorder, bool agg_distinct)
|
||||||
{
|
{
|
||||||
List *tlist;
|
List *tlist;
|
||||||
List *torder;
|
List *torder;
|
||||||
@ -75,7 +77,7 @@ transformAggregateCall(ParseState *pstate, Aggref *agg, bool agg_distinct)
|
|||||||
*/
|
*/
|
||||||
tlist = NIL;
|
tlist = NIL;
|
||||||
attno = 1;
|
attno = 1;
|
||||||
foreach(lc, agg->args)
|
foreach(lc, args)
|
||||||
{
|
{
|
||||||
Expr *arg = (Expr *) lfirst(lc);
|
Expr *arg = (Expr *) lfirst(lc);
|
||||||
TargetEntry *tle = makeTargetEntry(arg, attno++, NULL, false);
|
TargetEntry *tle = makeTargetEntry(arg, attno++, NULL, false);
|
||||||
@ -96,7 +98,7 @@ transformAggregateCall(ParseState *pstate, Aggref *agg, bool agg_distinct)
|
|||||||
pstate->p_next_resno = attno;
|
pstate->p_next_resno = attno;
|
||||||
|
|
||||||
torder = transformSortClause(pstate,
|
torder = transformSortClause(pstate,
|
||||||
agg->aggorder,
|
aggorder,
|
||||||
&tlist,
|
&tlist,
|
||||||
true /* fix unknowns */ ,
|
true /* fix unknowns */ ,
|
||||||
true /* force SQL99 rules */ );
|
true /* force SQL99 rules */ );
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/parser/parse_func.c,v 1.222 2010/02/26 02:00:52 momjian Exp $
|
* $PostgreSQL: pgsql/src/backend/parser/parse_func.c,v 1.223 2010/03/17 16:52:38 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -381,10 +381,7 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
|
|||||||
|
|
||||||
aggref->aggfnoid = funcid;
|
aggref->aggfnoid = funcid;
|
||||||
aggref->aggtype = rettype;
|
aggref->aggtype = rettype;
|
||||||
/* args and aggorder will be modified by transformAggregateCall */
|
/* args, aggorder, aggdistinct will be set by transformAggregateCall */
|
||||||
aggref->args = fargs;
|
|
||||||
aggref->aggorder = agg_order;
|
|
||||||
/* aggdistinct will be set by transformAggregateCall */
|
|
||||||
aggref->aggstar = agg_star;
|
aggref->aggstar = agg_star;
|
||||||
/* agglevelsup will be set by transformAggregateCall */
|
/* agglevelsup will be set by transformAggregateCall */
|
||||||
aggref->location = location;
|
aggref->location = location;
|
||||||
@ -419,7 +416,7 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
|
|||||||
parser_errposition(pstate, location)));
|
parser_errposition(pstate, location)));
|
||||||
|
|
||||||
/* parse_agg.c does additional aggregate-specific processing */
|
/* parse_agg.c does additional aggregate-specific processing */
|
||||||
transformAggregateCall(pstate, aggref, agg_distinct);
|
transformAggregateCall(pstate, aggref, fargs, agg_order, agg_distinct);
|
||||||
|
|
||||||
retval = (Node *) aggref;
|
retval = (Node *) aggref;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/include/parser/parse_agg.h,v 1.42 2010/02/26 02:01:26 momjian Exp $
|
* $PostgreSQL: pgsql/src/include/parser/parse_agg.h,v 1.43 2010/03/17 16:52:38 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -16,6 +16,7 @@
|
|||||||
#include "parser/parse_node.h"
|
#include "parser/parse_node.h"
|
||||||
|
|
||||||
extern void transformAggregateCall(ParseState *pstate, Aggref *agg,
|
extern void transformAggregateCall(ParseState *pstate, Aggref *agg,
|
||||||
|
List *args, List *aggorder,
|
||||||
bool agg_distinct);
|
bool agg_distinct);
|
||||||
extern void transformWindowFuncCall(ParseState *pstate, WindowFunc *wfunc,
|
extern void transformWindowFuncCall(ParseState *pstate, WindowFunc *wfunc,
|
||||||
WindowDef *windef);
|
WindowDef *windef);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user