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 1968 of file parse_agg.c.

1969 {
1970  ListCell *lc;
1971 
1972  foreach(lc, aggref->args)
1973  {
1974  HeapTuple typeTuple;
1975  Form_pg_type pt;
1976  TargetEntry *tle = (TargetEntry *) lfirst(lc);
1977  Oid type = exprType((Node *) tle->expr);
1978 
1979  typeTuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(type));
1980  if (!HeapTupleIsValid(typeTuple))
1981  elog(ERROR, "cache lookup failed for type %u", type);
1982 
1983  pt = (Form_pg_type) GETSTRUCT(typeTuple);
1984 
1985  if (!pt->typbyval &&
1986  (!OidIsValid(pt->typsend) || !OidIsValid(pt->typreceive)))
1987  {
1988  ReleaseSysCache(typeTuple);
1989  return false;
1990  }
1991  ReleaseSysCache(typeTuple);
1992  }
1993  return true;
1994 }
#define OidIsValid(objectId)
Definition: c.h:764
#define ERROR
Definition: elog.h:39
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:653
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:43
#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:252
unsigned int Oid
Definition: postgres_ext.h:31
List * args
Definition: primnodes.h:454
Definition: nodes.h:129
Expr * expr
Definition: primnodes.h:1922
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:267
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:219
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 2110 of file parse_agg.c.

2112 {
2113  List *args;
2114  FuncExpr *fexpr;
2115 
2116  /* deserialfn always takes BYTEA, INTERNAL and returns INTERNAL */
2117  args = list_make2(make_agg_arg(BYTEAOID, InvalidOid),
2118  make_agg_arg(INTERNALOID, InvalidOid));
2119 
2120  fexpr = makeFuncExpr(deserialfn_oid,
2121  INTERNALOID,
2122  args,
2123  InvalidOid,
2124  InvalidOid,
2126  *deserialfnexpr = (Expr *) fexpr;
2127 }
FuncExpr * makeFuncExpr(Oid funcid, Oid rettype, List *args, Oid funccollid, Oid inputcollid, CoercionForm fformat)
Definition: makefuncs.c:522
static Node * make_agg_arg(Oid argtype, Oid argcollation)
Definition: parse_agg.c:2174
#define list_make2(x1, x2)
Definition: pg_list.h:214
#define InvalidOid
Definition: postgres_ext.h:36
@ COERCE_EXPLICIT_CALL
Definition: primnodes.h:669
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 2134 of file parse_agg.c.

2141 {
2142  List *args;
2143  int i;
2144 
2145  /*
2146  * Build expr tree for final function
2147  */
2148  args = list_make1(make_agg_arg(agg_state_type, agg_input_collation));
2149 
2150  /* finalfn may take additional args, which match agg's input types */
2151  for (i = 0; i < num_finalfn_inputs - 1; i++)
2152  {
2153  args = lappend(args,
2154  make_agg_arg(agg_input_types[i], agg_input_collation));
2155  }
2156 
2157  *finalfnexpr = (Expr *) makeFuncExpr(finalfn_oid,
2158  agg_result_type,
2159  args,
2160  InvalidOid,
2161  agg_input_collation,
2163  /* finalfn is currently never treated as variadic */
2164 }
int i
Definition: isn.c:73
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 2087 of file parse_agg.c.

2089 {
2090  List *args;
2091  FuncExpr *fexpr;
2092 
2093  /* serialfn always takes INTERNAL and returns BYTEA */
2094  args = list_make1(make_agg_arg(INTERNALOID, InvalidOid));
2095 
2096  fexpr = makeFuncExpr(serialfn_oid,
2097  BYTEAOID,
2098  args,
2099  InvalidOid,
2100  InvalidOid,
2102  *serialfnexpr = (Expr *) fexpr;
2103 }

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 2026 of file parse_agg.c.

2036 {
2037  List *args;
2038  FuncExpr *fexpr;
2039  int i;
2040 
2041  /*
2042  * Build arg list to use in the transfn FuncExpr node.
2043  */
2044  args = list_make1(make_agg_arg(agg_state_type, agg_input_collation));
2045 
2046  for (i = agg_num_direct_inputs; i < agg_num_inputs; i++)
2047  {
2048  args = lappend(args,
2049  make_agg_arg(agg_input_types[i], agg_input_collation));
2050  }
2051 
2052  fexpr = makeFuncExpr(transfn_oid,
2053  agg_state_type,
2054  args,
2055  InvalidOid,
2056  agg_input_collation,
2058  fexpr->funcvariadic = agg_variadic;
2059  *transfnexpr = (Expr *) fexpr;
2060 
2061  /*
2062  * Build invtransfn expression if requested, with same args as transfn
2063  */
2064  if (invtransfnexpr != NULL)
2065  {
2066  if (OidIsValid(invtransfn_oid))
2067  {
2068  fexpr = makeFuncExpr(invtransfn_oid,
2069  agg_state_type,
2070  args,
2071  InvalidOid,
2072  agg_input_collation,
2074  fexpr->funcvariadic = agg_variadic;
2075  *invtransfnexpr = (Expr *) fexpr;
2076  }
2077  else
2078  *invtransfnexpr = NULL;
2079  }
2080 }

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 1803 of file parse_agg.c.

1804 {
1805  List *expanded_groups = NIL;
1806  List *result = NIL;
1807  double numsets = 1;
1808  ListCell *lc;
1809 
1810  if (groupingSets == NIL)
1811  return NIL;
1812 
1813  foreach(lc, groupingSets)
1814  {
1815  List *current_result = NIL;
1816  GroupingSet *gs = lfirst(lc);
1817 
1818  current_result = expand_groupingset_node(gs);
1819 
1820  Assert(current_result != NIL);
1821 
1822  numsets *= list_length(current_result);
1823 
1824  if (limit >= 0 && numsets > limit)
1825  return NIL;
1826 
1827  expanded_groups = lappend(expanded_groups, current_result);
1828  }
1829 
1830  /*
1831  * Do cartesian product between sublists of expanded_groups. While at it,
1832  * remove any duplicate elements from individual grouping sets (we must
1833  * NOT change the number of sets though)
1834  */
1835 
1836  foreach(lc, (List *) linitial(expanded_groups))
1837  {
1838  result = lappend(result, list_union_int(NIL, (List *) lfirst(lc)));
1839  }
1840 
1841  for_each_from(lc, expanded_groups, 1)
1842  {
1843  List *p = lfirst(lc);
1844  List *new_result = NIL;
1845  ListCell *lc2;
1846 
1847  foreach(lc2, result)
1848  {
1849  List *q = lfirst(lc2);
1850  ListCell *lc3;
1851 
1852  foreach(lc3, p)
1853  {
1854  new_result = lappend(new_result,
1855  list_union_int(q, (List *) lfirst(lc3)));
1856  }
1857  }
1858  result = new_result;
1859  }
1860 
1861  /* Now sort the lists by length and deduplicate if necessary */
1862  if (!groupDistinct || list_length(result) < 2)
1863  list_sort(result, cmp_list_len_asc);
1864  else
1865  {
1866  ListCell *cell;
1867  List *prev;
1868 
1869  /* Sort each groupset individually */
1870  foreach(cell, result)
1871  list_sort(lfirst(cell), list_int_cmp);
1872 
1873  /* Now sort the list of groupsets by length and contents */
1875 
1876  /* Finally, remove duplicates */
1877  prev = linitial(result);
1878  for_each_from(cell, result, 1)
1879  {
1880  if (equal(lfirst(cell), prev))
1881  result = foreach_delete_current(result, cell);
1882  else
1883  prev = lfirst(cell);
1884  }
1885  }
1886 
1887  return result;
1888 }
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:223
Assert(fmt[strlen(fmt) - 1] !='\n')
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:1759
static int cmp_list_len_contents_asc(const ListCell *a, const ListCell *b)
Definition: parse_agg.c:1769
static List * expand_groupingset_node(GroupingSet *gs)
Definition: parse_agg.c:1657
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 1906 of file parse_agg.c.

1907 {
1908  int numArguments = 0;
1909  ListCell *lc;
1910 
1911  Assert(list_length(aggref->aggargtypes) <= FUNC_MAX_ARGS);
1912 
1913  foreach(lc, aggref->aggargtypes)
1914  {
1915  inputTypes[numArguments++] = lfirst_oid(lc);
1916  }
1917 
1918  return numArguments;
1919 }
#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 1078 of file parse_agg.c.

1079 {
1080  List *gset_common = NIL;
1081  List *groupClauses = NIL;
1082  List *groupClauseCommonVars = NIL;
1083  bool have_non_var_grouping;
1084  List *func_grouped_rels = NIL;
1085  ListCell *l;
1086  bool hasJoinRTEs;
1087  bool hasSelfRefRTEs;
1088  Node *clause;
1089 
1090  /* This should only be called if we found aggregates or grouping */
1091  Assert(pstate->p_hasAggs || qry->groupClause || qry->havingQual || qry->groupingSets);
1092 
1093  /*
1094  * If we have grouping sets, expand them and find the intersection of all
1095  * sets.
1096  */
1097  if (qry->groupingSets)
1098  {
1099  /*
1100  * The limit of 4096 is arbitrary and exists simply to avoid resource
1101  * issues from pathological constructs.
1102  */
1103  List *gsets = expand_grouping_sets(qry->groupingSets, qry->groupDistinct, 4096);
1104 
1105  if (!gsets)
1106  ereport(ERROR,
1107  (errcode(ERRCODE_STATEMENT_TOO_COMPLEX),
1108  errmsg("too many grouping sets present (maximum 4096)"),
1109  parser_errposition(pstate,
1110  qry->groupClause
1111  ? exprLocation((Node *) qry->groupClause)
1112  : exprLocation((Node *) qry->groupingSets))));
1113 
1114  /*
1115  * The intersection will often be empty, so help things along by
1116  * seeding the intersect with the smallest set.
1117  */
1118  gset_common = linitial(gsets);
1119 
1120  if (gset_common)
1121  {
1122  for_each_from(l, gsets, 1)
1123  {
1124  gset_common = list_intersection_int(gset_common, lfirst(l));
1125  if (!gset_common)
1126  break;
1127  }
1128  }
1129 
1130  /*
1131  * If there was only one grouping set in the expansion, AND if the
1132  * groupClause is non-empty (meaning that the grouping set is not
1133  * empty either), then we can ditch the grouping set and pretend we
1134  * just had a normal GROUP BY.
1135  */
1136  if (list_length(gsets) == 1 && qry->groupClause)
1137  qry->groupingSets = NIL;
1138  }
1139 
1140  /*
1141  * Scan the range table to see if there are JOIN or self-reference CTE
1142  * entries. We'll need this info below.
1143  */
1144  hasJoinRTEs = hasSelfRefRTEs = false;
1145  foreach(l, pstate->p_rtable)
1146  {
1147  RangeTblEntry *rte = (RangeTblEntry *) lfirst(l);
1148 
1149  if (rte->rtekind == RTE_JOIN)
1150  hasJoinRTEs = true;
1151  else if (rte->rtekind == RTE_CTE && rte->self_reference)
1152  hasSelfRefRTEs = true;
1153  }
1154 
1155  /*
1156  * Build a list of the acceptable GROUP BY expressions for use by
1157  * check_ungrouped_columns().
1158  *
1159  * We get the TLE, not just the expr, because GROUPING wants to know the
1160  * sortgroupref.
1161  */
1162  foreach(l, qry->groupClause)
1163  {
1164  SortGroupClause *grpcl = (SortGroupClause *) lfirst(l);
1165  TargetEntry *expr;
1166 
1167  expr = get_sortgroupclause_tle(grpcl, qry->targetList);
1168  if (expr == NULL)
1169  continue; /* probably cannot happen */
1170 
1171  groupClauses = lappend(groupClauses, expr);
1172  }
1173 
1174  /*
1175  * If there are join alias vars involved, we have to flatten them to the
1176  * underlying vars, so that aliased and unaliased vars will be correctly
1177  * taken as equal. We can skip the expense of doing this if no rangetable
1178  * entries are RTE_JOIN kind.
1179  */
1180  if (hasJoinRTEs)
1181  groupClauses = (List *) flatten_join_alias_vars(NULL, qry,
1182  (Node *) groupClauses);
1183 
1184  /*
1185  * Detect whether any of the grouping expressions aren't simple Vars; if
1186  * they're all Vars then we don't have to work so hard in the recursive
1187  * scans. (Note we have to flatten aliases before this.)
1188  *
1189  * Track Vars that are included in all grouping sets separately in
1190  * groupClauseCommonVars, since these are the only ones we can use to
1191  * check for functional dependencies.
1192  */
1193  have_non_var_grouping = false;
1194  foreach(l, groupClauses)
1195  {
1196  TargetEntry *tle = lfirst(l);
1197 
1198  if (!IsA(tle->expr, Var))
1199  {
1200  have_non_var_grouping = true;
1201  }
1202  else if (!qry->groupingSets ||
1203  list_member_int(gset_common, tle->ressortgroupref))
1204  {
1205  groupClauseCommonVars = lappend(groupClauseCommonVars, tle->expr);
1206  }
1207  }
1208 
1209  /*
1210  * Check the targetlist and HAVING clause for ungrouped variables.
1211  *
1212  * Note: because we check resjunk tlist elements as well as regular ones,
1213  * this will also find ungrouped variables that came from ORDER BY and
1214  * WINDOW clauses. For that matter, it's also going to examine the
1215  * grouping expressions themselves --- but they'll all pass the test ...
1216  *
1217  * We also finalize GROUPING expressions, but for that we need to traverse
1218  * the original (unflattened) clause in order to modify nodes.
1219  */
1220  clause = (Node *) qry->targetList;
1221  finalize_grouping_exprs(clause, pstate, qry,
1222  groupClauses, hasJoinRTEs,
1223  have_non_var_grouping);
1224  if (hasJoinRTEs)
1225  clause = flatten_join_alias_vars(NULL, qry, clause);
1226  check_ungrouped_columns(clause, pstate, qry,
1227  groupClauses, groupClauseCommonVars,
1228  have_non_var_grouping,
1229  &func_grouped_rels);
1230 
1231  clause = (Node *) qry->havingQual;
1232  finalize_grouping_exprs(clause, pstate, qry,
1233  groupClauses, hasJoinRTEs,
1234  have_non_var_grouping);
1235  if (hasJoinRTEs)
1236  clause = flatten_join_alias_vars(NULL, qry, clause);
1237  check_ungrouped_columns(clause, pstate, qry,
1238  groupClauses, groupClauseCommonVars,
1239  have_non_var_grouping,
1240  &func_grouped_rels);
1241 
1242  /*
1243  * Per spec, aggregates can't appear in a recursive term.
1244  */
1245  if (pstate->p_hasAggs && hasSelfRefRTEs)
1246  ereport(ERROR,
1247  (errcode(ERRCODE_INVALID_RECURSION),
1248  errmsg("aggregate functions are not allowed in a recursive query's recursive term"),
1249  parser_errposition(pstate,
1250  locate_agg_of_level((Node *) qry, 0))));
1251 }
int errcode(int sqlerrcode)
Definition: elog.c:860
int errmsg(const char *fmt,...)
Definition: elog.c:1075
#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:1312
#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:1483
static void check_ungrouped_columns(Node *node, ParseState *pstate, Query *qry, List *groupClauses, List *groupClauseCommonVars, bool have_non_var_grouping, List **func_grouped_rels)
Definition: parse_agg.c:1275
List * expand_grouping_sets(List *groupingSets, bool groupDistinct, int limit)
Definition: parse_agg.c:1803
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:111
@ RTE_JOIN
Definition: parsenodes.h:1008
@ RTE_CTE
Definition: parsenodes.h:1012
int locate_agg_of_level(Node *node, int levelsup)
Definition: rewriteManip.c:149
List * p_rtable
Definition: parse_node.h:193
bool p_hasAggs
Definition: parse_node.h:222
bool groupDistinct
Definition: parsenodes.h:191
List * groupClause
Definition: parsenodes.h:190
Node * havingQual
Definition: parsenodes.h:195
List * targetList
Definition: parsenodes.h:181
List * groupingSets
Definition: parsenodes.h:193
bool self_reference
Definition: parsenodes.h:1158
RTEKind rtekind
Definition: parsenodes.h:1025
Index ressortgroupref
Definition: primnodes.h:1928
Definition: primnodes.h:234
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:744

References Assert(), check_ungrouped_columns(), 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_hasAggs, ParseState::p_rtable, parser_errposition(), TargetEntry::ressortgroupref, RTE_CTE, RTE_JOIN, RangeTblEntry::rtekind, RangeTblEntry::self_reference, 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 1932 of file parse_agg.c.

1936 {
1937  /* resolve actual type of transition state, if polymorphic */
1938  if (IsPolymorphicType(aggtranstype))
1939  {
1940  /* have to fetch the agg's declared input types... */
1941  Oid *declaredArgTypes;
1942  int agg_nargs;
1943 
1944  (void) get_func_signature(aggfuncid, &declaredArgTypes, &agg_nargs);
1945 
1946  /*
1947  * VARIADIC ANY aggs could have more actual than declared args, but
1948  * such extra args can't affect polymorphic type resolution.
1949  */
1950  Assert(agg_nargs <= numArguments);
1951 
1952  aggtranstype = enforce_generic_type_consistency(inputTypes,
1953  declaredArgTypes,
1954  agg_nargs,
1955  aggtranstype,
1956  false);
1957  pfree(declaredArgTypes);
1958  }
1959  return aggtranstype;
1960 }
Oid get_func_signature(Oid funcid, Oid **argtypes, int *nargs)
Definition: lsyscache.c:1673
void pfree(void *pointer)
Definition: mcxt.c:1431
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 104 of file parse_agg.c.

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

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

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 821 of file parse_agg.c.

823 {
824  const char *err;
825  bool errkind;
826 
827  /*
828  * A window function call can't contain another one (but aggs are OK). XXX
829  * is this required by spec, or just an unimplemented feature?
830  *
831  * Note: we don't need to check the filter expression here, because the
832  * context checks done below and in transformAggregateCall would have
833  * already rejected any window funcs or aggs within the filter.
834  */
835  if (pstate->p_hasWindowFuncs &&
836  contain_windowfuncs((Node *) wfunc->args))
837  ereport(ERROR,
838  (errcode(ERRCODE_WINDOWING_ERROR),
839  errmsg("window function calls cannot be nested"),
840  parser_errposition(pstate,
841  locate_windowfunc((Node *) wfunc->args))));
842 
843  /*
844  * Check to see if the window function is in an invalid place within the
845  * query.
846  *
847  * For brevity we support two schemes for reporting an error here: set
848  * "err" to a custom message, or set "errkind" true if the error context
849  * is sufficiently identified by what ParseExprKindName will return, *and*
850  * what it will return is just a SQL keyword. (Otherwise, use a custom
851  * message to avoid creating translation problems.)
852  */
853  err = NULL;
854  errkind = false;
855  switch (pstate->p_expr_kind)
856  {
857  case EXPR_KIND_NONE:
858  Assert(false); /* can't happen */
859  break;
860  case EXPR_KIND_OTHER:
861  /* Accept window func here; caller must throw error if wanted */
862  break;
863  case EXPR_KIND_JOIN_ON:
865  err = _("window functions are not allowed in JOIN conditions");
866  break;
868  /* can't get here, but just in case, throw an error */
869  errkind = true;
870  break;
872  err = _("window functions are not allowed in functions in FROM");
873  break;
874  case EXPR_KIND_WHERE:
875  errkind = true;
876  break;
877  case EXPR_KIND_POLICY:
878  err = _("window functions are not allowed in policy expressions");
879  break;
880  case EXPR_KIND_HAVING:
881  errkind = true;
882  break;
883  case EXPR_KIND_FILTER:
884  errkind = true;
885  break;
891  err = _("window functions are not allowed in window definitions");
892  break;
894  /* okay */
895  break;
899  errkind = true;
900  break;
902  err = _("window functions are not allowed in MERGE WHEN conditions");
903  break;
904  case EXPR_KIND_GROUP_BY:
905  errkind = true;
906  break;
907  case EXPR_KIND_ORDER_BY:
908  /* okay */
909  break;
911  /* okay */
912  break;
913  case EXPR_KIND_LIMIT:
914  case EXPR_KIND_OFFSET:
915  errkind = true;
916  break;
917  case EXPR_KIND_RETURNING:
918  errkind = true;
919  break;
920  case EXPR_KIND_VALUES:
922  errkind = true;
923  break;
926  err = _("window functions are not allowed in check constraints");
927  break;
930  err = _("window functions are not allowed in DEFAULT expressions");
931  break;
933  err = _("window functions are not allowed in index expressions");
934  break;
936  err = _("window functions are not allowed in statistics expressions");
937  break;
939  err = _("window functions are not allowed in index predicates");
940  break;
942  err = _("window functions are not allowed in transform expressions");
943  break;
945  err = _("window functions are not allowed in EXECUTE parameters");
946  break;
948  err = _("window functions are not allowed in trigger WHEN conditions");
949  break;
951  err = _("window functions are not allowed in partition bound");
952  break;
954  err = _("window functions are not allowed in partition key expressions");
955  break;
957  err = _("window functions are not allowed in CALL arguments");
958  break;
960  err = _("window functions are not allowed in COPY FROM WHERE conditions");
961  break;
963  err = _("window functions are not allowed in column generation expressions");
964  break;
966  errkind = true;
967  break;
968 
969  /*
970  * There is intentionally no default: case here, so that the
971  * compiler will warn if we add a new ParseExprKind without
972  * extending this switch. If we do see an unrecognized value at
973  * runtime, the behavior will be the same as for EXPR_KIND_OTHER,
974  * which is sane anyway.
975  */
976  }
977  if (err)
978  ereport(ERROR,
979  (errcode(ERRCODE_WINDOWING_ERROR),
980  errmsg_internal("%s", err),
981  parser_errposition(pstate, wfunc->location)));
982  if (errkind)
983  ereport(ERROR,
984  (errcode(ERRCODE_WINDOWING_ERROR),
985  /* translator: %s is name of a SQL construct, eg GROUP BY */
986  errmsg("window functions are not allowed in %s",
987  ParseExprKindName(pstate->p_expr_kind)),
988  parser_errposition(pstate, wfunc->location)));
989 
990  /*
991  * If the OVER clause just specifies a window name, find that WINDOW
992  * clause (which had better be present). Otherwise, try to match all the
993  * properties of the OVER clause, and make a new entry in the p_windowdefs
994  * list if no luck.
995  */
996  if (windef->name)
997  {
998  Index winref = 0;
999  ListCell *lc;
1000 
1001  Assert(windef->refname == NULL &&
1002  windef->partitionClause == NIL &&
1003  windef->orderClause == NIL &&
1004  windef->frameOptions == FRAMEOPTION_DEFAULTS);
1005 
1006  foreach(lc, pstate->p_windowdefs)
1007  {
1008  WindowDef *refwin = (WindowDef *) lfirst(lc);
1009 
1010  winref++;
1011  if (refwin->name && strcmp(refwin->name, windef->name) == 0)
1012  {
1013  wfunc->winref = winref;
1014  break;
1015  }
1016  }
1017  if (lc == NULL) /* didn't find it? */
1018  ereport(ERROR,
1019  (errcode(ERRCODE_UNDEFINED_OBJECT),
1020  errmsg("window \"%s\" does not exist", windef->name),
1021  parser_errposition(pstate, windef->location)));
1022  }
1023  else
1024  {
1025  Index winref = 0;
1026  ListCell *lc;
1027 
1028  foreach(lc, pstate->p_windowdefs)
1029  {
1030  WindowDef *refwin = (WindowDef *) lfirst(lc);
1031 
1032  winref++;
1033  if (refwin->refname && windef->refname &&
1034  strcmp(refwin->refname, windef->refname) == 0)
1035  /* matched on refname */ ;
1036  else if (!refwin->refname && !windef->refname)
1037  /* matched, no refname */ ;
1038  else
1039  continue;
1040 
1041  /*
1042  * Also see similar de-duplication code in optimize_window_clauses
1043  */
1044  if (equal(refwin->partitionClause, windef->partitionClause) &&
1045  equal(refwin->orderClause, windef->orderClause) &&
1046  refwin->frameOptions == windef->frameOptions &&
1047  equal(refwin->startOffset, windef->startOffset) &&
1048  equal(refwin->endOffset, windef->endOffset))
1049  {
1050  /* found a duplicate window specification */
1051  wfunc->winref = winref;
1052  break;
1053  }
1054  }
1055  if (lc == NULL) /* didn't find it? */
1056  {
1057  pstate->p_windowdefs = lappend(pstate->p_windowdefs, windef);
1058  wfunc->winref = list_length(pstate->p_windowdefs);
1059  }
1060  }
1061 
1062  pstate->p_hasWindowFuncs = true;
1063 }
unsigned int Index
Definition: c.h:603
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1162
#define _(x)
Definition: elog.c:91
void err(int eval, const char *fmt,...)
Definition: err.c:43
const char * ParseExprKindName(ParseExprKind exprKind)
Definition: parse_expr.c:3064
@ EXPR_KIND_EXECUTE_PARAMETER
Definition: parse_node.h:75
@ EXPR_KIND_DOMAIN_CHECK
Definition: parse_node.h:68
@ EXPR_KIND_COPY_WHERE
Definition: parse_node.h:81
@ EXPR_KIND_COLUMN_DEFAULT
Definition: parse_node.h:69
@ 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:73
@ EXPR_KIND_INDEX_EXPRESSION
Definition: parse_node.h:71
@ EXPR_KIND_PARTITION_BOUND
Definition: parse_node.h:78
@ EXPR_KIND_FUNCTION_DEFAULT
Definition: parse_node.h:70
@ EXPR_KIND_WINDOW_FRAME_RANGE
Definition: parse_node.h:51
@ EXPR_KIND_VALUES
Definition: parse_node.h:65
@ EXPR_KIND_FROM_SUBSELECT
Definition: parse_node.h:44
@ EXPR_KIND_POLICY
Definition: parse_node.h:77
@ EXPR_KIND_WINDOW_FRAME_GROUPS
Definition: parse_node.h:53
@ EXPR_KIND_PARTITION_EXPRESSION
Definition: parse_node.h:79
@ EXPR_KIND_JOIN_USING
Definition: parse_node.h:43
@ EXPR_KIND_INDEX_PREDICATE
Definition: parse_node.h:72
@ 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:74
@ 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:82
@ EXPR_KIND_NONE
Definition: parse_node.h:40
@ EXPR_KIND_CALL_ARGUMENT
Definition: parse_node.h:80
@ 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:76
@ 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:67
@ EXPR_KIND_WINDOW_PARTITION
Definition: parse_node.h:49
@ EXPR_KIND_CYCLE_MARK
Definition: parse_node.h:83
@ 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:66
#define FRAMEOPTION_DEFAULTS
Definition: parsenodes.h:598
bool contain_windowfuncs(Node *node)
Definition: rewriteManip.c:215
int locate_windowfunc(Node *node)
Definition: rewriteManip.c:253
bool p_hasWindowFuncs
Definition: parse_node.h:223
List * p_windowdefs
Definition: parse_node.h:209
List * orderClause
Definition: parsenodes.h:557
List * partitionClause
Definition: parsenodes.h:556
Node * startOffset
Definition: parsenodes.h:559
char * refname
Definition: parsenodes.h:555
Node * endOffset
Definition: parsenodes.h:560
int frameOptions
Definition: parsenodes.h:558
int location
Definition: parsenodes.h:561
char * name
Definition: parsenodes.h:554
List * args
Definition: primnodes.h:561
Index winref
Definition: primnodes.h:565
int location
Definition: primnodes.h:571

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_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().