1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-27 23:21:58 +03:00

Support ORDER BY within aggregate function calls, at long last providing a

non-kluge method for controlling the order in which values are fed to an
aggregate function.  At the same time eliminate the old implementation
restriction that DISTINCT was only supported for single-argument aggregates.

Possibly release-notable behavioral change: formerly, agg(DISTINCT x)
dropped null values of x unconditionally.  Now, it does so only if the
agg transition function is strict; otherwise nulls are treated as DISTINCT
normally would, ie, you get one copy.

Andrew Gierth, reviewed by Hitoshi Harada
This commit is contained in:
Tom Lane
2009-12-15 17:57:48 +00:00
parent 6a6efb9640
commit 34d26872ed
31 changed files with 1184 additions and 248 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/nodes/nodeFuncs.c,v 1.43 2009/10/08 02:39:21 tgl Exp $
* $PostgreSQL: pgsql/src/backend/nodes/nodeFuncs.c,v 1.44 2009/12/15 17:57:46 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -882,6 +882,7 @@ exprLocation(Node *expr)
FuncCall *fc = (FuncCall *) expr;
/* consider both function name and leftmost arg */
/* (we assume any ORDER BY nodes must be to right of name) */
loc = leftmostLoc(fc->location,
exprLocation((Node *) fc->args));
}
@ -1082,6 +1083,7 @@ expression_tree_walker(Node *node,
case T_SetToDefault:
case T_CurrentOfExpr:
case T_RangeTblRef:
case T_SortGroupClause:
/* primitive node types with no expression subnodes */
break;
case T_Aggref:
@ -1092,6 +1094,12 @@ expression_tree_walker(Node *node,
if (expression_tree_walker((Node *) expr->args,
walker, context))
return true;
if (expression_tree_walker((Node *) expr->aggorder,
walker, context))
return true;
if (expression_tree_walker((Node *) expr->aggdistinct,
walker, context))
return true;
}
break;
case T_WindowFunc:
@ -1591,6 +1599,7 @@ expression_tree_mutator(Node *node,
case T_SetToDefault:
case T_CurrentOfExpr:
case T_RangeTblRef:
case T_SortGroupClause:
return (Node *) copyObject(node);
case T_Aggref:
{
@ -1599,6 +1608,8 @@ expression_tree_mutator(Node *node,
FLATCOPY(newnode, aggref, Aggref);
MUTATE(newnode->args, aggref->args, List *);
MUTATE(newnode->aggorder, aggref->aggorder, List *);
MUTATE(newnode->aggdistinct, aggref->aggdistinct, List *);
return (Node *) newnode;
}
break;
@ -2403,6 +2414,8 @@ bool
if (walker(fcall->args, context))
return true;
if (walker(fcall->agg_order, context))
return true;
if (walker(fcall->over, context))
return true;
/* function name is deemed uninteresting */