PostgreSQL Source Code git master
parse_agg.h File Reference
Include dependency graph for parse_agg.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void transformAggregateCall (ParseState *pstate, Aggref *agg, List *args, List *aggorder, bool agg_distinct)
 
NodetransformGroupingFunc (ParseState *pstate, GroupingFunc *p)
 
void transformWindowFuncCall (ParseState *pstate, WindowFunc *wfunc, WindowDef *windef)
 
void parseCheckAggregates (ParseState *pstate, Query *qry)
 
Listexpand_grouping_sets (List *groupingSets, bool groupDistinct, int limit)
 
int get_aggregate_argtypes (Aggref *aggref, Oid *inputTypes)
 
Oid resolve_aggregate_transtype (Oid aggfuncid, Oid aggtranstype, Oid *inputTypes, int numArguments)
 
bool agg_args_support_sendreceive (Aggref *aggref)
 
void build_aggregate_transfn_expr (Oid *agg_input_types, int agg_num_inputs, int agg_num_direct_inputs, bool agg_variadic, Oid agg_state_type, Oid agg_input_collation, Oid transfn_oid, Oid invtransfn_oid, Expr **transfnexpr, Expr **invtransfnexpr)
 
void build_aggregate_serialfn_expr (Oid serialfn_oid, Expr **serialfnexpr)
 
void build_aggregate_deserialfn_expr (Oid deserialfn_oid, Expr **deserialfnexpr)
 
void build_aggregate_finalfn_expr (Oid *agg_input_types, int num_finalfn_inputs, Oid agg_state_type, Oid agg_result_type, Oid agg_input_collation, Oid finalfn_oid, Expr **finalfnexpr)
 

Function Documentation

◆ agg_args_support_sendreceive()

bool agg_args_support_sendreceive ( Aggref aggref)

Definition at line 2059 of file parse_agg.c.

2060{
2061 ListCell *lc;
2062
2063 foreach(lc, aggref->args)
2064 {
2065 HeapTuple typeTuple;
2066 Form_pg_type pt;
2067 TargetEntry *tle = (TargetEntry *) lfirst(lc);
2068 Oid type = exprType((Node *) tle->expr);
2069
2070 typeTuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(type));
2071 if (!HeapTupleIsValid(typeTuple))
2072 elog(ERROR, "cache lookup failed for type %u", type);
2073
2074 pt = (Form_pg_type) GETSTRUCT(typeTuple);
2075
2076 if (!pt->typbyval &&
2077 (!OidIsValid(pt->typsend) || !OidIsValid(pt->typreceive)))
2078 {
2079 ReleaseSysCache(typeTuple);
2080 return false;
2081 }
2082 ReleaseSysCache(typeTuple);
2083 }
2084 return true;
2085}
#define OidIsValid(objectId)
Definition: c.h:732
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
Definition: htup_details.h:728
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
#define lfirst(lc)
Definition: pg_list.h:172
FormData_pg_type * Form_pg_type
Definition: pg_type.h:261
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:257
unsigned int Oid
Definition: postgres_ext.h:32
List * args
Definition: primnodes.h:485
Definition: nodes.h:129
Expr * expr
Definition: primnodes.h:2219
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:269
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:221
const char * type

References Aggref::args, elog, ERROR, TargetEntry::expr, exprType(), GETSTRUCT(), HeapTupleIsValid, lfirst, ObjectIdGetDatum(), OidIsValid, ReleaseSysCache(), SearchSysCache1(), and type.

Referenced by preprocess_aggref().

◆ build_aggregate_deserialfn_expr()

void build_aggregate_deserialfn_expr ( Oid  deserialfn_oid,
Expr **  deserialfnexpr 
)

Definition at line 2201 of file parse_agg.c.

2203{
2204 List *args;
2205 FuncExpr *fexpr;
2206
2207 /* deserialfn always takes BYTEA, INTERNAL and returns INTERNAL */
2209 make_agg_arg(INTERNALOID, InvalidOid));
2210
2211 fexpr = makeFuncExpr(deserialfn_oid,
2212 INTERNALOID,
2213 args,
2214 InvalidOid,
2215 InvalidOid,
2217 *deserialfnexpr = (Expr *) fexpr;
2218}
FuncExpr * makeFuncExpr(Oid funcid, Oid rettype, List *args, Oid funccollid, Oid inputcollid, CoercionForm fformat)
Definition: makefuncs.c:547
static Node * make_agg_arg(Oid argtype, Oid argcollation)
Definition: parse_agg.c:2265
#define list_make2(x1, x2)
Definition: pg_list.h:214
#define InvalidOid
Definition: postgres_ext.h:37
@ COERCE_EXPLICIT_CALL
Definition: primnodes.h:751
Definition: pg_list.h:54

References generate_unaccent_rules::args, COERCE_EXPLICIT_CALL, InvalidOid, list_make2, make_agg_arg(), and makeFuncExpr().

Referenced by build_pertrans_for_aggref().

◆ build_aggregate_finalfn_expr()

void build_aggregate_finalfn_expr ( Oid agg_input_types,
int  num_finalfn_inputs,
Oid  agg_state_type,
Oid  agg_result_type,
Oid  agg_input_collation,
Oid  finalfn_oid,
Expr **  finalfnexpr 
)

Definition at line 2225 of file parse_agg.c.

2232{
2233 List *args;
2234 int i;
2235
2236 /*
2237 * Build expr tree for final function
2238 */
2239 args = list_make1(make_agg_arg(agg_state_type, agg_input_collation));
2240
2241 /* finalfn may take additional args, which match agg's input types */
2242 for (i = 0; i < num_finalfn_inputs - 1; i++)
2243 {
2244 args = lappend(args,
2245 make_agg_arg(agg_input_types[i], agg_input_collation));
2246 }
2247
2248 *finalfnexpr = (Expr *) makeFuncExpr(finalfn_oid,
2249 agg_result_type,
2250 args,
2251 InvalidOid,
2252 agg_input_collation,
2254 /* finalfn is currently never treated as variadic */
2255}
int i
Definition: isn.c:72
List * lappend(List *list, void *datum)
Definition: list.c:339
#define list_make1(x1)
Definition: pg_list.h:212

References generate_unaccent_rules::args, COERCE_EXPLICIT_CALL, i, InvalidOid, lappend(), list_make1, make_agg_arg(), and makeFuncExpr().

Referenced by ExecInitAgg(), and initialize_peragg().

◆ build_aggregate_serialfn_expr()

void build_aggregate_serialfn_expr ( Oid  serialfn_oid,
Expr **  serialfnexpr 
)

Definition at line 2178 of file parse_agg.c.

2180{
2181 List *args;
2182 FuncExpr *fexpr;
2183
2184 /* serialfn always takes INTERNAL and returns BYTEA */
2185 args = list_make1(make_agg_arg(INTERNALOID, InvalidOid));
2186
2187 fexpr = makeFuncExpr(serialfn_oid,
2188 BYTEAOID,
2189 args,
2190 InvalidOid,
2191 InvalidOid,
2193 *serialfnexpr = (Expr *) fexpr;
2194}

References generate_unaccent_rules::args, COERCE_EXPLICIT_CALL, InvalidOid, list_make1, make_agg_arg(), and makeFuncExpr().

Referenced by build_pertrans_for_aggref().

◆ build_aggregate_transfn_expr()

void build_aggregate_transfn_expr ( Oid agg_input_types,
int  agg_num_inputs,
int  agg_num_direct_inputs,
bool  agg_variadic,
Oid  agg_state_type,
Oid  agg_input_collation,
Oid  transfn_oid,
Oid  invtransfn_oid,
Expr **  transfnexpr,
Expr **  invtransfnexpr 
)

Definition at line 2117 of file parse_agg.c.

2127{
2128 List *args;
2129 FuncExpr *fexpr;
2130 int i;
2131
2132 /*
2133 * Build arg list to use in the transfn FuncExpr node.
2134 */
2135 args = list_make1(make_agg_arg(agg_state_type, agg_input_collation));
2136
2137 for (i = agg_num_direct_inputs; i < agg_num_inputs; i++)
2138 {
2139 args = lappend(args,
2140 make_agg_arg(agg_input_types[i], agg_input_collation));
2141 }
2142
2143 fexpr = makeFuncExpr(transfn_oid,
2144 agg_state_type,
2145 args,
2146 InvalidOid,
2147 agg_input_collation,
2149 fexpr->funcvariadic = agg_variadic;
2150 *transfnexpr = (Expr *) fexpr;
2151
2152 /*
2153 * Build invtransfn expression if requested, with same args as transfn
2154 */
2155 if (invtransfnexpr != NULL)
2156 {
2157 if (OidIsValid(invtransfn_oid))
2158 {
2159 fexpr = makeFuncExpr(invtransfn_oid,
2160 agg_state_type,
2161 args,
2162 InvalidOid,
2163 agg_input_collation,
2165 fexpr->funcvariadic = agg_variadic;
2166 *invtransfnexpr = (Expr *) fexpr;
2167 }
2168 else
2169 *invtransfnexpr = NULL;
2170 }
2171}

References generate_unaccent_rules::args, COERCE_EXPLICIT_CALL, i, InvalidOid, lappend(), list_make1, make_agg_arg(), makeFuncExpr(), and OidIsValid.

Referenced by build_pertrans_for_aggref(), and initialize_peragg().

◆ expand_grouping_sets()

List * expand_grouping_sets ( List groupingSets,
bool  groupDistinct,
int  limit 
)

Definition at line 1894 of file parse_agg.c.

1895{
1896 List *expanded_groups = NIL;
1897 List *result = NIL;
1898 double numsets = 1;
1899 ListCell *lc;
1900
1901 if (groupingSets == NIL)
1902 return NIL;
1903
1904 foreach(lc, groupingSets)
1905 {
1906 List *current_result = NIL;
1907 GroupingSet *gs = lfirst(lc);
1908
1909 current_result = expand_groupingset_node(gs);
1910
1911 Assert(current_result != NIL);
1912
1913 numsets *= list_length(current_result);
1914
1915 if (limit >= 0 && numsets > limit)
1916 return NIL;
1917
1918 expanded_groups = lappend(expanded_groups, current_result);
1919 }
1920
1921 /*
1922 * Do cartesian product between sublists of expanded_groups. While at it,
1923 * remove any duplicate elements from individual grouping sets (we must
1924 * NOT change the number of sets though)
1925 */
1926
1927 foreach(lc, (List *) linitial(expanded_groups))
1928 {
1929 result = lappend(result, list_union_int(NIL, (List *) lfirst(lc)));
1930 }
1931
1932 for_each_from(lc, expanded_groups, 1)
1933 {
1934 List *p = lfirst(lc);
1935 List *new_result = NIL;
1936 ListCell *lc2;
1937
1938 foreach(lc2, result)
1939 {
1940 List *q = lfirst(lc2);
1941 ListCell *lc3;
1942
1943 foreach(lc3, p)
1944 {
1945 new_result = lappend(new_result,
1946 list_union_int(q, (List *) lfirst(lc3)));
1947 }
1948 }
1949 result = new_result;
1950 }
1951
1952 /* Now sort the lists by length and deduplicate if necessary */
1953 if (!groupDistinct || list_length(result) < 2)
1954 list_sort(result, cmp_list_len_asc);
1955 else
1956 {
1957 ListCell *cell;
1958 List *prev;
1959
1960 /* Sort each groupset individually */
1961 foreach(cell, result)
1963
1964 /* Now sort the list of groupsets by length and contents */
1966
1967 /* Finally, remove duplicates */
1968 prev = linitial(result);
1969 for_each_from(cell, result, 1)
1970 {
1971 if (equal(lfirst(cell), prev))
1972 result = foreach_delete_current(result, cell);
1973 else
1974 prev = lfirst(cell);
1975 }
1976 }
1977
1978 return result;
1979}
#define Assert(condition)
Definition: c.h:815
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:223
void list_sort(List *list, list_sort_comparator cmp)
Definition: list.c:1674
int list_int_cmp(const ListCell *p1, const ListCell *p2)
Definition: list.c:1691
List * list_union_int(const List *list1, const List *list2)
Definition: list.c:1113
static int cmp_list_len_asc(const ListCell *a, const ListCell *b)
Definition: parse_agg.c:1850
static int cmp_list_len_contents_asc(const ListCell *a, const ListCell *b)
Definition: parse_agg.c:1860
static List * expand_groupingset_node(GroupingSet *gs)
Definition: parse_agg.c:1748
static int list_length(const List *l)
Definition: pg_list.h:152
#define NIL
Definition: pg_list.h:68
#define foreach_delete_current(lst, var_or_cell)
Definition: pg_list.h:391
#define for_each_from(cell, lst, N)
Definition: pg_list.h:414
#define linitial(l)
Definition: pg_list.h:178

References Assert, cmp_list_len_asc(), cmp_list_len_contents_asc(), equal(), expand_groupingset_node(), for_each_from, foreach_delete_current, lappend(), lfirst, linitial, list_int_cmp(), list_length(), list_sort(), list_union_int(), and NIL.

Referenced by parseCheckAggregates(), and preprocess_grouping_sets().

◆ get_aggregate_argtypes()

int get_aggregate_argtypes ( Aggref aggref,
Oid inputTypes 
)

Definition at line 1997 of file parse_agg.c.

1998{
1999 int numArguments = 0;
2000 ListCell *lc;
2001
2002 Assert(list_length(aggref->aggargtypes) <= FUNC_MAX_ARGS);
2003
2004 foreach(lc, aggref->aggargtypes)
2005 {
2006 inputTypes[numArguments++] = lfirst_oid(lc);
2007 }
2008
2009 return numArguments;
2010}
#define FUNC_MAX_ARGS
#define lfirst_oid(lc)
Definition: pg_list.h:174

References Assert, FUNC_MAX_ARGS, lfirst_oid, and list_length().

Referenced by ExecInitAgg(), get_agg_expr_helper(), and preprocess_aggref().

◆ parseCheckAggregates()

void parseCheckAggregates ( ParseState pstate,
Query qry 
)

Definition at line 1085 of file parse_agg.c.

1086{
1087 List *gset_common = NIL;
1088 List *groupClauses = NIL;
1089 List *groupClauseCommonVars = NIL;
1090 bool have_non_var_grouping;
1091 List *func_grouped_rels = NIL;
1092 ListCell *l;
1093 bool hasJoinRTEs;
1094 bool hasSelfRefRTEs;
1095 Node *clause;
1096
1097 /* This should only be called if we found aggregates or grouping */
1098 Assert(pstate->p_hasAggs || qry->groupClause || qry->havingQual || qry->groupingSets);
1099
1100 /*
1101 * If we have grouping sets, expand them and find the intersection of all
1102 * sets.
1103 */
1104 if (qry->groupingSets)
1105 {
1106 /*
1107 * The limit of 4096 is arbitrary and exists simply to avoid resource
1108 * issues from pathological constructs.
1109 */
1110 List *gsets = expand_grouping_sets(qry->groupingSets, qry->groupDistinct, 4096);
1111
1112 if (!gsets)
1113 ereport(ERROR,
1114 (errcode(ERRCODE_STATEMENT_TOO_COMPLEX),
1115 errmsg("too many grouping sets present (maximum 4096)"),
1116 parser_errposition(pstate,
1117 qry->groupClause
1118 ? exprLocation((Node *) qry->groupClause)
1119 : exprLocation((Node *) qry->groupingSets))));
1120
1121 /*
1122 * The intersection will often be empty, so help things along by
1123 * seeding the intersect with the smallest set.
1124 */
1125 gset_common = linitial(gsets);
1126
1127 if (gset_common)
1128 {
1129 for_each_from(l, gsets, 1)
1130 {
1131 gset_common = list_intersection_int(gset_common, lfirst(l));
1132 if (!gset_common)
1133 break;
1134 }
1135 }
1136
1137 /*
1138 * If there was only one grouping set in the expansion, AND if the
1139 * groupClause is non-empty (meaning that the grouping set is not
1140 * empty either), then we can ditch the grouping set and pretend we
1141 * just had a normal GROUP BY.
1142 */
1143 if (list_length(gsets) == 1 && qry->groupClause)
1144 qry->groupingSets = NIL;
1145 }
1146
1147 /*
1148 * Scan the range table to see if there are JOIN or self-reference CTE
1149 * entries. We'll need this info below.
1150 */
1151 hasJoinRTEs = hasSelfRefRTEs = false;
1152 foreach(l, pstate->p_rtable)
1153 {
1154 RangeTblEntry *rte = (RangeTblEntry *) lfirst(l);
1155
1156 if (rte->rtekind == RTE_JOIN)
1157 hasJoinRTEs = true;
1158 else if (rte->rtekind == RTE_CTE && rte->self_reference)
1159 hasSelfRefRTEs = true;
1160 }
1161
1162 /*
1163 * Build a list of the acceptable GROUP BY expressions for use by
1164 * substitute_grouped_columns().
1165 *
1166 * We get the TLE, not just the expr, because GROUPING wants to know the
1167 * sortgroupref.
1168 */
1169 foreach(l, qry->groupClause)
1170 {
1171 SortGroupClause *grpcl = (SortGroupClause *) lfirst(l);
1172 TargetEntry *expr;
1173
1174 expr = get_sortgroupclause_tle(grpcl, qry->targetList);
1175 if (expr == NULL)
1176 continue; /* probably cannot happen */
1177
1178 groupClauses = lappend(groupClauses, expr);
1179 }
1180
1181 /*
1182 * If there are join alias vars involved, we have to flatten them to the
1183 * underlying vars, so that aliased and unaliased vars will be correctly
1184 * taken as equal. We can skip the expense of doing this if no rangetable
1185 * entries are RTE_JOIN kind.
1186 */
1187 if (hasJoinRTEs)
1188 groupClauses = (List *) flatten_join_alias_vars(NULL, qry,
1189 (Node *) groupClauses);
1190
1191 /*
1192 * Detect whether any of the grouping expressions aren't simple Vars; if
1193 * they're all Vars then we don't have to work so hard in the recursive
1194 * scans. (Note we have to flatten aliases before this.)
1195 *
1196 * Track Vars that are included in all grouping sets separately in
1197 * groupClauseCommonVars, since these are the only ones we can use to
1198 * check for functional dependencies.
1199 */
1200 have_non_var_grouping = false;
1201 foreach(l, groupClauses)
1202 {
1203 TargetEntry *tle = lfirst(l);
1204
1205 if (!IsA(tle->expr, Var))
1206 {
1207 have_non_var_grouping = true;
1208 }
1209 else if (!qry->groupingSets ||
1210 list_member_int(gset_common, tle->ressortgroupref))
1211 {
1212 groupClauseCommonVars = lappend(groupClauseCommonVars, tle->expr);
1213 }
1214 }
1215
1216 /*
1217 * If there are any acceptable GROUP BY expressions, build an RTE and
1218 * nsitem for the result of the grouping step.
1219 */
1220 if (groupClauses)
1221 {
1222 pstate->p_grouping_nsitem =
1223 addRangeTableEntryForGroup(pstate, groupClauses);
1224
1225 /* Set qry->rtable again in case it was previously NIL */
1226 qry->rtable = pstate->p_rtable;
1227 /* Mark the Query as having RTE_GROUP RTE */
1228 qry->hasGroupRTE = true;
1229 }
1230
1231 /*
1232 * Replace grouped variables in the targetlist and HAVING clause with Vars
1233 * that reference the RTE_GROUP RTE. Emit an error message if we find any
1234 * ungrouped variables.
1235 *
1236 * Note: because we check resjunk tlist elements as well as regular ones,
1237 * this will also find ungrouped variables that came from ORDER BY and
1238 * WINDOW clauses. For that matter, it's also going to examine the
1239 * grouping expressions themselves --- but they'll all pass the test ...
1240 *
1241 * We also finalize GROUPING expressions, but for that we need to traverse
1242 * the original (unflattened) clause in order to modify nodes.
1243 */
1244 clause = (Node *) qry->targetList;
1245 finalize_grouping_exprs(clause, pstate, qry,
1246 groupClauses, hasJoinRTEs,
1247 have_non_var_grouping);
1248 if (hasJoinRTEs)
1249 clause = flatten_join_alias_vars(NULL, qry, clause);
1250 qry->targetList = (List *)
1251 substitute_grouped_columns(clause, pstate, qry,
1252 groupClauses, groupClauseCommonVars,
1253 gset_common,
1254 have_non_var_grouping,
1255 &func_grouped_rels);
1256
1257 clause = (Node *) qry->havingQual;
1258 finalize_grouping_exprs(clause, pstate, qry,
1259 groupClauses, hasJoinRTEs,
1260 have_non_var_grouping);
1261 if (hasJoinRTEs)
1262 clause = flatten_join_alias_vars(NULL, qry, clause);
1263 qry->havingQual =
1264 substitute_grouped_columns(clause, pstate, qry,
1265 groupClauses, groupClauseCommonVars,
1266 gset_common,
1267 have_non_var_grouping,
1268 &func_grouped_rels);
1269
1270 /*
1271 * Per spec, aggregates can't appear in a recursive term.
1272 */
1273 if (pstate->p_hasAggs && hasSelfRefRTEs)
1274 ereport(ERROR,
1275 (errcode(ERRCODE_INVALID_RECURSION),
1276 errmsg("aggregate functions are not allowed in a recursive query's recursive term"),
1277 parser_errposition(pstate,
1278 locate_agg_of_level((Node *) qry, 0))));
1279}
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ereport(elevel,...)
Definition: elog.h:149
List * list_intersection_int(const List *list1, const List *list2)
Definition: list.c:1200
bool list_member_int(const List *list, int datum)
Definition: list.c:702
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1388
#define IsA(nodeptr, _type_)
Definition: nodes.h:158
static void finalize_grouping_exprs(Node *node, ParseState *pstate, Query *qry, List *groupClauses, bool hasJoinRTEs, bool have_non_var_grouping)
Definition: parse_agg.c:1541
List * expand_grouping_sets(List *groupingSets, bool groupDistinct, int limit)
Definition: parse_agg.c:1894
static Node * substitute_grouped_columns(Node *node, ParseState *pstate, Query *qry, List *groupClauses, List *groupClauseCommonVars, List *gset_common, bool have_non_var_grouping, List **func_grouped_rels)
Definition: parse_agg.c:1305
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:106
ParseNamespaceItem * addRangeTableEntryForGroup(ParseState *pstate, List *groupClauses)
@ RTE_JOIN
Definition: parsenodes.h:1028
@ RTE_CTE
Definition: parsenodes.h:1032
int locate_agg_of_level(Node *node, int levelsup)
Definition: rewriteManip.c:150
ParseNamespaceItem * p_grouping_nsitem
Definition: parse_node.h:227
List * p_rtable
Definition: parse_node.h:212
bool p_hasAggs
Definition: parse_node.h:242
bool groupDistinct
Definition: parsenodes.h:212
List * groupClause
Definition: parsenodes.h:211
Node * havingQual
Definition: parsenodes.h:216
List * rtable
Definition: parsenodes.h:170
List * targetList
Definition: parsenodes.h:193
List * groupingSets
Definition: parsenodes.h:214
RTEKind rtekind
Definition: parsenodes.h:1056
Index ressortgroupref
Definition: primnodes.h:2225
Definition: primnodes.h:262
TargetEntry * get_sortgroupclause_tle(SortGroupClause *sgClause, List *targetList)
Definition: tlist.c:367
Node * flatten_join_alias_vars(PlannerInfo *root, Query *query, Node *node)
Definition: var.c:789

References addRangeTableEntryForGroup(), Assert, ereport, errcode(), errmsg(), ERROR, expand_grouping_sets(), TargetEntry::expr, exprLocation(), finalize_grouping_exprs(), flatten_join_alias_vars(), for_each_from, get_sortgroupclause_tle(), Query::groupClause, Query::groupDistinct, Query::groupingSets, Query::havingQual, IsA, lappend(), lfirst, linitial, list_intersection_int(), list_length(), list_member_int(), locate_agg_of_level(), NIL, ParseState::p_grouping_nsitem, ParseState::p_hasAggs, ParseState::p_rtable, parser_errposition(), TargetEntry::ressortgroupref, Query::rtable, RTE_CTE, RTE_JOIN, RangeTblEntry::rtekind, substitute_grouped_columns(), and Query::targetList.

Referenced by transformDeleteStmt(), transformPLAssignStmt(), transformSelectStmt(), and transformSetOperationStmt().

◆ resolve_aggregate_transtype()

Oid resolve_aggregate_transtype ( Oid  aggfuncid,
Oid  aggtranstype,
Oid inputTypes,
int  numArguments 
)

Definition at line 2023 of file parse_agg.c.

2027{
2028 /* resolve actual type of transition state, if polymorphic */
2029 if (IsPolymorphicType(aggtranstype))
2030 {
2031 /* have to fetch the agg's declared input types... */
2032 Oid *declaredArgTypes;
2033 int agg_nargs;
2034
2035 (void) get_func_signature(aggfuncid, &declaredArgTypes, &agg_nargs);
2036
2037 /*
2038 * VARIADIC ANY aggs could have more actual than declared args, but
2039 * such extra args can't affect polymorphic type resolution.
2040 */
2041 Assert(agg_nargs <= numArguments);
2042
2043 aggtranstype = enforce_generic_type_consistency(inputTypes,
2044 declaredArgTypes,
2045 agg_nargs,
2046 aggtranstype,
2047 false);
2048 pfree(declaredArgTypes);
2049 }
2050 return aggtranstype;
2051}
Oid get_func_signature(Oid funcid, Oid **argtypes, int *nargs)
Definition: lsyscache.c:1723
void pfree(void *pointer)
Definition: mcxt.c:1521
Oid enforce_generic_type_consistency(const Oid *actual_arg_types, Oid *declared_arg_types, int nargs, Oid rettype, bool allow_poly)

References Assert, enforce_generic_type_consistency(), get_func_signature(), and pfree().

Referenced by initialize_peragg(), and preprocess_aggref().

◆ transformAggregateCall()

void transformAggregateCall ( ParseState pstate,
Aggref agg,
List args,
List aggorder,
bool  agg_distinct 
)

Definition at line 109 of file parse_agg.c.

111{
112 List *argtypes = NIL;
113 List *tlist = NIL;
114 List *torder = NIL;
115 List *tdistinct = NIL;
116 AttrNumber attno = 1;
117 int save_next_resno;
118 ListCell *lc;
119
120 if (AGGKIND_IS_ORDERED_SET(agg->aggkind))
121 {
122 /*
123 * For an ordered-set agg, the args list includes direct args and
124 * aggregated args; we must split them apart.
125 */
126 int numDirectArgs = list_length(args) - list_length(aggorder);
127 List *aargs;
128 ListCell *lc2;
129
130 Assert(numDirectArgs >= 0);
131
132 aargs = list_copy_tail(args, numDirectArgs);
133 agg->aggdirectargs = list_truncate(args, numDirectArgs);
134
135 /*
136 * Build a tlist from the aggregated args, and make a sortlist entry
137 * for each one. Note that the expressions in the SortBy nodes are
138 * ignored (they are the raw versions of the transformed args); we are
139 * just looking at the sort information in the SortBy nodes.
140 */
141 forboth(lc, aargs, lc2, aggorder)
142 {
143 Expr *arg = (Expr *) lfirst(lc);
144 SortBy *sortby = (SortBy *) lfirst(lc2);
145 TargetEntry *tle;
146
147 /* We don't bother to assign column names to the entries */
148 tle = makeTargetEntry(arg, attno++, NULL, false);
149 tlist = lappend(tlist, tle);
150
151 torder = addTargetToSortList(pstate, tle,
152 torder, tlist, sortby);
153 }
154
155 /* Never any DISTINCT in an ordered-set agg */
156 Assert(!agg_distinct);
157 }
158 else
159 {
160 /* Regular aggregate, so it has no direct args */
161 agg->aggdirectargs = NIL;
162
163 /*
164 * Transform the plain list of Exprs into a targetlist.
165 */
166 foreach(lc, args)
167 {
168 Expr *arg = (Expr *) lfirst(lc);
169 TargetEntry *tle;
170
171 /* We don't bother to assign column names to the entries */
172 tle = makeTargetEntry(arg, attno++, NULL, false);
173 tlist = lappend(tlist, tle);
174 }
175
176 /*
177 * If we have an ORDER BY, transform it. This will add columns to the
178 * tlist if they appear in ORDER BY but weren't already in the arg
179 * list. They will be marked resjunk = true so we can tell them apart
180 * from regular aggregate arguments later.
181 *
182 * We need to mess with p_next_resno since it will be used to number
183 * any new targetlist entries.
184 */
185 save_next_resno = pstate->p_next_resno;
186 pstate->p_next_resno = attno;
187
188 torder = transformSortClause(pstate,
189 aggorder,
190 &tlist,
192 true /* force SQL99 rules */ );
193
194 /*
195 * If we have DISTINCT, transform that to produce a distinctList.
196 */
197 if (agg_distinct)
198 {
199 tdistinct = transformDistinctClause(pstate, &tlist, torder, true);
200
201 /*
202 * Remove this check if executor support for hashed distinct for
203 * aggregates is ever added.
204 */
205 foreach(lc, tdistinct)
206 {
207 SortGroupClause *sortcl = (SortGroupClause *) lfirst(lc);
208
209 if (!OidIsValid(sortcl->sortop))
210 {
211 Node *expr = get_sortgroupclause_expr(sortcl, tlist);
212
214 (errcode(ERRCODE_UNDEFINED_FUNCTION),
215 errmsg("could not identify an ordering operator for type %s",
216 format_type_be(exprType(expr))),
217 errdetail("Aggregates with DISTINCT must be able to sort their inputs."),
218 parser_errposition(pstate, exprLocation(expr))));
219 }
220 }
221 }
222
223 pstate->p_next_resno = save_next_resno;
224 }
225
226 /* Update the Aggref with the transformation results */
227 agg->args = tlist;
228 agg->aggorder = torder;
229 agg->aggdistinct = tdistinct;
230
231 /*
232 * Now build the aggargtypes list with the type OIDs of the direct and
233 * aggregated args, ignoring any resjunk entries that might have been
234 * added by ORDER BY/DISTINCT processing. We can't do this earlier
235 * because said processing can modify some args' data types, in particular
236 * by resolving previously-unresolved "unknown" literals.
237 */
238 foreach(lc, agg->aggdirectargs)
239 {
240 Expr *arg = (Expr *) lfirst(lc);
241
242 argtypes = lappend_oid(argtypes, exprType((Node *) arg));
243 }
244 foreach(lc, tlist)
245 {
246 TargetEntry *tle = (TargetEntry *) lfirst(lc);
247
248 if (tle->resjunk)
249 continue; /* ignore junk */
250 argtypes = lappend_oid(argtypes, exprType((Node *) tle->expr));
251 }
252 agg->aggargtypes = argtypes;
253
254 check_agglevels_and_constraints(pstate, (Node *) agg);
255}
int16 AttrNumber
Definition: attnum.h:21
int errdetail(const char *fmt,...)
Definition: elog.c:1203
char * format_type_be(Oid type_oid)
Definition: format_type.c:343
List * list_copy_tail(const List *oldlist, int nskip)
Definition: list.c:1613
List * lappend_oid(List *list, Oid datum)
Definition: list.c:375
List * list_truncate(List *list, int new_size)
Definition: list.c:631
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Definition: makefuncs.c:242
static void check_agglevels_and_constraints(ParseState *pstate, Node *expr)
Definition: parse_agg.c:304
List * transformSortClause(ParseState *pstate, List *orderlist, List **targetlist, ParseExprKind exprKind, bool useSQL99)
List * transformDistinctClause(ParseState *pstate, List **targetlist, List *sortClause, bool is_agg)
List * addTargetToSortList(ParseState *pstate, TargetEntry *tle, List *sortlist, List *targetlist, SortBy *sortby)
@ EXPR_KIND_ORDER_BY
Definition: parse_node.h:60
void * arg
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:518
List * aggdistinct
Definition: primnodes.h:491
List * aggdirectargs
Definition: primnodes.h:482
List * aggorder
Definition: primnodes.h:488
int p_next_resno
Definition: parse_node.h:231
Node * get_sortgroupclause_expr(SortGroupClause *sgClause, List *targetList)
Definition: tlist.c:379

References addTargetToSortList(), Aggref::aggdirectargs, Aggref::aggdistinct, Aggref::aggorder, arg, generate_unaccent_rules::args, Aggref::args, Assert, check_agglevels_and_constraints(), ereport, errcode(), errdetail(), errmsg(), ERROR, TargetEntry::expr, EXPR_KIND_ORDER_BY, exprLocation(), exprType(), forboth, format_type_be(), get_sortgroupclause_expr(), lappend(), lappend_oid(), lfirst, list_copy_tail(), list_length(), list_truncate(), makeTargetEntry(), NIL, OidIsValid, ParseState::p_next_resno, parser_errposition(), SortGroupClause::sortop, transformDistinctClause(), and transformSortClause().

Referenced by ParseFuncOrColumn(), and transformJsonAggConstructor().

◆ transformGroupingFunc()

Node * transformGroupingFunc ( ParseState pstate,
GroupingFunc p 
)

Definition at line 265 of file parse_agg.c.

266{
267 ListCell *lc;
268 List *args = p->args;
269 List *result_list = NIL;
271
272 if (list_length(args) > 31)
274 (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
275 errmsg("GROUPING must have fewer than 32 arguments"),
276 parser_errposition(pstate, p->location)));
277
278 foreach(lc, args)
279 {
280 Node *current_result;
281
282 current_result = transformExpr(pstate, (Node *) lfirst(lc), pstate->p_expr_kind);
283
284 /* acceptability of expressions is checked later */
285
286 result_list = lappend(result_list, current_result);
287 }
288
289 result->args = result_list;
290 result->location = p->location;
291
292 check_agglevels_and_constraints(pstate, (Node *) result);
293
294 return (Node *) result;
295}
#define makeNode(_type_)
Definition: nodes.h:155
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
Definition: parse_expr.c:118
ParseLoc location
Definition: primnodes.h:571
ParseExprKind p_expr_kind
Definition: parse_node.h:230

References generate_unaccent_rules::args, check_agglevels_and_constraints(), ereport, errcode(), errmsg(), ERROR, lappend(), lfirst, list_length(), GroupingFunc::location, makeNode, NIL, ParseState::p_expr_kind, parser_errposition(), and transformExpr().

Referenced by transformExprRecurse().

◆ transformWindowFuncCall()

void transformWindowFuncCall ( ParseState pstate,
WindowFunc wfunc,
WindowDef windef 
)

Definition at line 825 of file parse_agg.c.

827{
828 const char *err;
829 bool errkind;
830
831 /*
832 * A window function call can't contain another one (but aggs are OK). XXX
833 * is this required by spec, or just an unimplemented feature?
834 *
835 * Note: we don't need to check the filter expression here, because the
836 * context checks done below and in transformAggregateCall would have
837 * already rejected any window funcs or aggs within the filter.
838 */
839 if (pstate->p_hasWindowFuncs &&
840 contain_windowfuncs((Node *) wfunc->args))
842 (errcode(ERRCODE_WINDOWING_ERROR),
843 errmsg("window function calls cannot be nested"),
844 parser_errposition(pstate,
845 locate_windowfunc((Node *) wfunc->args))));
846
847 /*
848 * Check to see if the window function is in an invalid place within the
849 * query.
850 *
851 * For brevity we support two schemes for reporting an error here: set
852 * "err" to a custom message, or set "errkind" true if the error context
853 * is sufficiently identified by what ParseExprKindName will return, *and*
854 * what it will return is just a SQL keyword. (Otherwise, use a custom
855 * message to avoid creating translation problems.)
856 */
857 err = NULL;
858 errkind = false;
859 switch (pstate->p_expr_kind)
860 {
861 case EXPR_KIND_NONE:
862 Assert(false); /* can't happen */
863 break;
864 case EXPR_KIND_OTHER:
865 /* Accept window func here; caller must throw error if wanted */
866 break;
869 err = _("window functions are not allowed in JOIN conditions");
870 break;
872 /* can't get here, but just in case, throw an error */
873 errkind = true;
874 break;
876 err = _("window functions are not allowed in functions in FROM");
877 break;
878 case EXPR_KIND_WHERE:
879 errkind = true;
880 break;
881 case EXPR_KIND_POLICY:
882 err = _("window functions are not allowed in policy expressions");
883 break;
884 case EXPR_KIND_HAVING:
885 errkind = true;
886 break;
887 case EXPR_KIND_FILTER:
888 errkind = true;
889 break;
895 err = _("window functions are not allowed in window definitions");
896 break;
898 /* okay */
899 break;
903 errkind = true;
904 break;
906 err = _("window functions are not allowed in MERGE WHEN conditions");
907 break;
909 errkind = true;
910 break;
912 /* okay */
913 break;
915 /* okay */
916 break;
917 case EXPR_KIND_LIMIT:
918 case EXPR_KIND_OFFSET:
919 errkind = true;
920 break;
923 errkind = true;
924 break;
925 case EXPR_KIND_VALUES:
927 errkind = true;
928 break;
931 err = _("window functions are not allowed in check constraints");
932 break;
935 err = _("window functions are not allowed in DEFAULT expressions");
936 break;
938 err = _("window functions are not allowed in index expressions");
939 break;
941 err = _("window functions are not allowed in statistics expressions");
942 break;
944 err = _("window functions are not allowed in index predicates");
945 break;
947 err = _("window functions are not allowed in transform expressions");
948 break;
950 err = _("window functions are not allowed in EXECUTE parameters");
951 break;
953 err = _("window functions are not allowed in trigger WHEN conditions");
954 break;
956 err = _("window functions are not allowed in partition bound");
957 break;
959 err = _("window functions are not allowed in partition key expressions");
960 break;
962 err = _("window functions are not allowed in CALL arguments");
963 break;
965 err = _("window functions are not allowed in COPY FROM WHERE conditions");
966 break;
968 err = _("window functions are not allowed in column generation expressions");
969 break;
971 errkind = true;
972 break;
973
974 /*
975 * There is intentionally no default: case here, so that the
976 * compiler will warn if we add a new ParseExprKind without
977 * extending this switch. If we do see an unrecognized value at
978 * runtime, the behavior will be the same as for EXPR_KIND_OTHER,
979 * which is sane anyway.
980 */
981 }
982 if (err)
984 (errcode(ERRCODE_WINDOWING_ERROR),
985 errmsg_internal("%s", err),
986 parser_errposition(pstate, wfunc->location)));
987 if (errkind)
989 (errcode(ERRCODE_WINDOWING_ERROR),
990 /* translator: %s is name of a SQL construct, eg GROUP BY */
991 errmsg("window functions are not allowed in %s",
993 parser_errposition(pstate, wfunc->location)));
994
995 /*
996 * If the OVER clause just specifies a window name, find that WINDOW
997 * clause (which had better be present). Otherwise, try to match all the
998 * properties of the OVER clause, and make a new entry in the p_windowdefs
999 * list if no luck.
1000 */
1001 if (windef->name)
1002 {
1003 Index winref = 0;
1004 ListCell *lc;
1005
1006 Assert(windef->refname == NULL &&
1007 windef->partitionClause == NIL &&
1008 windef->orderClause == NIL &&
1010
1011 foreach(lc, pstate->p_windowdefs)
1012 {
1013 WindowDef *refwin = (WindowDef *) lfirst(lc);
1014
1015 winref++;
1016 if (refwin->name && strcmp(refwin->name, windef->name) == 0)
1017 {
1018 wfunc->winref = winref;
1019 break;
1020 }
1021 }
1022 if (lc == NULL) /* didn't find it? */
1023 ereport(ERROR,
1024 (errcode(ERRCODE_UNDEFINED_OBJECT),
1025 errmsg("window \"%s\" does not exist", windef->name),
1026 parser_errposition(pstate, windef->location)));
1027 }
1028 else
1029 {
1030 Index winref = 0;
1031 ListCell *lc;
1032
1033 foreach(lc, pstate->p_windowdefs)
1034 {
1035 WindowDef *refwin = (WindowDef *) lfirst(lc);
1036
1037 winref++;
1038 if (refwin->refname && windef->refname &&
1039 strcmp(refwin->refname, windef->refname) == 0)
1040 /* matched on refname */ ;
1041 else if (!refwin->refname && !windef->refname)
1042 /* matched, no refname */ ;
1043 else
1044 continue;
1045
1046 /*
1047 * Also see similar de-duplication code in optimize_window_clauses
1048 */
1049 if (equal(refwin->partitionClause, windef->partitionClause) &&
1050 equal(refwin->orderClause, windef->orderClause) &&
1051 refwin->frameOptions == windef->frameOptions &&
1052 equal(refwin->startOffset, windef->startOffset) &&
1053 equal(refwin->endOffset, windef->endOffset))
1054 {
1055 /* found a duplicate window specification */
1056 wfunc->winref = winref;
1057 break;
1058 }
1059 }
1060 if (lc == NULL) /* didn't find it? */
1061 {
1062 pstate->p_windowdefs = lappend(pstate->p_windowdefs, windef);
1063 wfunc->winref = list_length(pstate->p_windowdefs);
1064 }
1065 }
1066
1067 pstate->p_hasWindowFuncs = true;
1068}
unsigned int Index
Definition: c.h:571
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1157
#define _(x)
Definition: elog.c:90
void err(int eval, const char *fmt,...)
Definition: err.c:43
const char * ParseExprKindName(ParseExprKind exprKind)
Definition: parse_expr.c:3121
@ EXPR_KIND_EXECUTE_PARAMETER
Definition: parse_node.h:76
@ EXPR_KIND_DOMAIN_CHECK
Definition: parse_node.h:69
@ EXPR_KIND_COPY_WHERE
Definition: parse_node.h:82
@ EXPR_KIND_COLUMN_DEFAULT
Definition: parse_node.h:70
@ EXPR_KIND_DISTINCT_ON
Definition: parse_node.h:61
@ EXPR_KIND_MERGE_WHEN
Definition: parse_node.h:58
@ EXPR_KIND_STATS_EXPRESSION
Definition: parse_node.h:74
@ EXPR_KIND_INDEX_EXPRESSION
Definition: parse_node.h:72
@ EXPR_KIND_MERGE_RETURNING
Definition: parse_node.h:65
@ EXPR_KIND_PARTITION_BOUND
Definition: parse_node.h:79
@ EXPR_KIND_FUNCTION_DEFAULT
Definition: parse_node.h:71
@ EXPR_KIND_WINDOW_FRAME_RANGE
Definition: parse_node.h:51
@ EXPR_KIND_VALUES
Definition: parse_node.h:66
@ EXPR_KIND_FROM_SUBSELECT
Definition: parse_node.h:44
@ EXPR_KIND_POLICY
Definition: parse_node.h:78
@ EXPR_KIND_WINDOW_FRAME_GROUPS
Definition: parse_node.h:53
@ EXPR_KIND_PARTITION_EXPRESSION
Definition: parse_node.h:80
@ EXPR_KIND_JOIN_USING
Definition: parse_node.h:43
@ EXPR_KIND_INDEX_PREDICATE
Definition: parse_node.h:73
@ EXPR_KIND_OFFSET
Definition: parse_node.h:63
@ EXPR_KIND_JOIN_ON
Definition: parse_node.h:42
@ EXPR_KIND_HAVING
Definition: parse_node.h:47
@ EXPR_KIND_INSERT_TARGET
Definition: parse_node.h:55
@ EXPR_KIND_ALTER_COL_TRANSFORM
Definition: parse_node.h:75
@ EXPR_KIND_LIMIT
Definition: parse_node.h:62
@ EXPR_KIND_WHERE
Definition: parse_node.h:46
@ EXPR_KIND_UPDATE_TARGET
Definition: parse_node.h:57
@ EXPR_KIND_SELECT_TARGET
Definition: parse_node.h:54
@ EXPR_KIND_RETURNING
Definition: parse_node.h:64
@ EXPR_KIND_GENERATED_COLUMN
Definition: parse_node.h:83
@ EXPR_KIND_NONE
Definition: parse_node.h:40
@ EXPR_KIND_CALL_ARGUMENT
Definition: parse_node.h:81
@ EXPR_KIND_GROUP_BY
Definition: parse_node.h:59
@ EXPR_KIND_OTHER
Definition: parse_node.h:41
@ EXPR_KIND_FROM_FUNCTION
Definition: parse_node.h:45
@ EXPR_KIND_TRIGGER_WHEN
Definition: parse_node.h:77
@ EXPR_KIND_FILTER
Definition: parse_node.h:48
@ EXPR_KIND_UPDATE_SOURCE
Definition: parse_node.h:56
@ EXPR_KIND_CHECK_CONSTRAINT
Definition: parse_node.h:68
@ EXPR_KIND_WINDOW_PARTITION
Definition: parse_node.h:49
@ EXPR_KIND_CYCLE_MARK
Definition: parse_node.h:84
@ EXPR_KIND_WINDOW_FRAME_ROWS
Definition: parse_node.h:52
@ EXPR_KIND_WINDOW_ORDER
Definition: parse_node.h:50
@ EXPR_KIND_VALUES_SINGLE
Definition: parse_node.h:67
#define FRAMEOPTION_DEFAULTS
Definition: parsenodes.h:619
bool contain_windowfuncs(Node *node)
Definition: rewriteManip.c:215
int locate_windowfunc(Node *node)
Definition: rewriteManip.c:252
bool p_hasWindowFuncs
Definition: parse_node.h:243
List * p_windowdefs
Definition: parse_node.h:229
List * orderClause
Definition: parsenodes.h:578
ParseLoc location
Definition: parsenodes.h:582
List * partitionClause
Definition: parsenodes.h:577
Node * startOffset
Definition: parsenodes.h:580
char * refname
Definition: parsenodes.h:576
Node * endOffset
Definition: parsenodes.h:581
int frameOptions
Definition: parsenodes.h:579
char * name
Definition: parsenodes.h:575
List * args
Definition: primnodes.h:592
Index winref
Definition: primnodes.h:598
ParseLoc location
Definition: primnodes.h:604

References _, WindowFunc::args, Assert, contain_windowfuncs(), WindowDef::endOffset, equal(), ereport, err(), errcode(), errmsg(), errmsg_internal(), ERROR, EXPR_KIND_ALTER_COL_TRANSFORM, EXPR_KIND_CALL_ARGUMENT, EXPR_KIND_CHECK_CONSTRAINT, EXPR_KIND_COLUMN_DEFAULT, EXPR_KIND_COPY_WHERE, EXPR_KIND_CYCLE_MARK, EXPR_KIND_DISTINCT_ON, EXPR_KIND_DOMAIN_CHECK, EXPR_KIND_EXECUTE_PARAMETER, EXPR_KIND_FILTER, EXPR_KIND_FROM_FUNCTION, EXPR_KIND_FROM_SUBSELECT, EXPR_KIND_FUNCTION_DEFAULT, EXPR_KIND_GENERATED_COLUMN, EXPR_KIND_GROUP_BY, EXPR_KIND_HAVING, EXPR_KIND_INDEX_EXPRESSION, EXPR_KIND_INDEX_PREDICATE, EXPR_KIND_INSERT_TARGET, EXPR_KIND_JOIN_ON, EXPR_KIND_JOIN_USING, EXPR_KIND_LIMIT, EXPR_KIND_MERGE_RETURNING, EXPR_KIND_MERGE_WHEN, EXPR_KIND_NONE, EXPR_KIND_OFFSET, EXPR_KIND_ORDER_BY, EXPR_KIND_OTHER, EXPR_KIND_PARTITION_BOUND, EXPR_KIND_PARTITION_EXPRESSION, EXPR_KIND_POLICY, EXPR_KIND_RETURNING, EXPR_KIND_SELECT_TARGET, EXPR_KIND_STATS_EXPRESSION, EXPR_KIND_TRIGGER_WHEN, EXPR_KIND_UPDATE_SOURCE, EXPR_KIND_UPDATE_TARGET, EXPR_KIND_VALUES, EXPR_KIND_VALUES_SINGLE, EXPR_KIND_WHERE, EXPR_KIND_WINDOW_FRAME_GROUPS, EXPR_KIND_WINDOW_FRAME_RANGE, EXPR_KIND_WINDOW_FRAME_ROWS, EXPR_KIND_WINDOW_ORDER, EXPR_KIND_WINDOW_PARTITION, FRAMEOPTION_DEFAULTS, WindowDef::frameOptions, lappend(), lfirst, list_length(), locate_windowfunc(), WindowDef::location, WindowFunc::location, WindowDef::name, NIL, WindowDef::orderClause, ParseState::p_expr_kind, ParseState::p_hasWindowFuncs, ParseState::p_windowdefs, ParseExprKindName(), parser_errposition(), WindowDef::partitionClause, WindowDef::refname, WindowDef::startOffset, and WindowFunc::winref.

Referenced by ParseFuncOrColumn(), and transformJsonAggConstructor().