PostgreSQL Source Code
git master
|
#include "postgres.h"
#include "access/htup_details.h"
#include "catalog/pg_aggregate.h"
#include "catalog/pg_constraint.h"
#include "catalog/pg_type.h"
#include "common/int.h"
#include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
#include "optimizer/optimizer.h"
#include "parser/parse_agg.h"
#include "parser/parse_clause.h"
#include "parser/parse_coerce.h"
#include "parser/parse_expr.h"
#include "parser/parse_relation.h"
#include "parser/parsetree.h"
#include "rewrite/rewriteManip.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h"
Go to the source code of this file.
Data Structures | |
struct | check_agg_arguments_context |
struct | substitute_grouped_columns_context |
Functions | |
static int | check_agg_arguments (ParseState *pstate, List *directargs, List *args, Expr *filter) |
static bool | check_agg_arguments_walker (Node *node, check_agg_arguments_context *context) |
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) |
static Node * | substitute_grouped_columns_mutator (Node *node, substitute_grouped_columns_context *context) |
static void | finalize_grouping_exprs (Node *node, ParseState *pstate, Query *qry, List *groupClauses, bool hasJoinRTEs, bool have_non_var_grouping) |
static bool | finalize_grouping_exprs_walker (Node *node, substitute_grouped_columns_context *context) |
static Var * | buildGroupedVar (int attnum, Index ressortgroupref, substitute_grouped_columns_context *context) |
static void | check_agglevels_and_constraints (ParseState *pstate, Node *expr) |
static List * | expand_groupingset_node (GroupingSet *gs) |
static Node * | make_agg_arg (Oid argtype, Oid argcollation) |
void | transformAggregateCall (ParseState *pstate, Aggref *agg, List *args, List *aggorder, bool agg_distinct) |
Node * | transformGroupingFunc (ParseState *pstate, GroupingFunc *p) |
void | transformWindowFuncCall (ParseState *pstate, WindowFunc *wfunc, WindowDef *windef) |
void | parseCheckAggregates (ParseState *pstate, Query *qry) |
static int | cmp_list_len_asc (const ListCell *a, const ListCell *b) |
static int | cmp_list_len_contents_asc (const ListCell *a, const ListCell *b) |
List * | expand_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) |
bool agg_args_support_sendreceive | ( | Aggref * | aggref | ) |
Definition at line 2059 of file parse_agg.c.
References Aggref::args, elog, ERROR, TargetEntry::expr, exprType(), GETSTRUCT, HeapTupleIsValid, lfirst, ObjectIdGetDatum(), OidIsValid, ReleaseSysCache(), SearchSysCache1(), and type.
Referenced by preprocess_aggref().
Definition at line 2201 of file parse_agg.c.
References generate_unaccent_rules::args, COERCE_EXPLICIT_CALL, InvalidOid, list_make2, make_agg_arg(), and makeFuncExpr().
Referenced by build_pertrans_for_aggref().
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.
References generate_unaccent_rules::args, COERCE_EXPLICIT_CALL, i, InvalidOid, lappend(), list_make1, make_agg_arg(), and makeFuncExpr().
Referenced by ExecInitAgg(), and initialize_peragg().
Definition at line 2178 of file parse_agg.c.
References generate_unaccent_rules::args, COERCE_EXPLICIT_CALL, InvalidOid, list_make1, make_agg_arg(), and makeFuncExpr().
Referenced by build_pertrans_for_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 | ||
) |
Definition at line 2117 of file parse_agg.c.
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().
|
static |
Definition at line 1708 of file parse_agg.c.
References Assert, attnum, bms_add_member(), context, list_member_int(), makeVar(), ParseNamespaceItem::p_nscolumns, ParseNamespaceItem::p_rtindex, ParseNamespaceColumn::p_varattno, ParseNamespaceColumn::p_varattnosyn, ParseNamespaceColumn::p_varcollid, ParseNamespaceColumn::p_varno, ParseNamespaceColumn::p_varnosyn, ParseNamespaceColumn::p_vartype, and ParseNamespaceColumn::p_vartypmod.
Referenced by substitute_grouped_columns_mutator().
|
static |
Definition at line 641 of file parse_agg.c.
References generate_unaccent_rules::args, check_agg_arguments_walker(), context, ereport, errcode(), errmsg(), ERROR, locate_agg_of_level(), locate_var_of_level(), Min, and parser_errposition().
Referenced by check_agglevels_and_constraints().
|
static |
Definition at line 722 of file parse_agg.c.
References context, ereport, errcode(), errhint(), errmsg(), ERROR, expression_tree_walker, exprLocation(), IsA, parser_errposition(), and query_tree_walker.
Referenced by check_agg_arguments().
|
static |
Definition at line 304 of file parse_agg.c.
References _, Aggref::aggdirectargs, Aggref::aggfilter, GroupingFunc::agglevelsup, generate_unaccent_rules::args, Aggref::args, Assert, check_agg_arguments(), ereport, err(), errcode(), 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, IsA, Aggref::location, GroupingFunc::location, NIL, ParseState::p_expr_kind, ParseState::p_hasAggs, ParseState::parentParseState, ParseExprKindName(), and parser_errposition().
Referenced by transformAggregateCall(), and transformGroupingFunc().
Definition at line 1850 of file parse_agg.c.
References a, b, lfirst, list_length(), and pg_cmp_s32().
Referenced by cmp_list_len_contents_asc(), and expand_grouping_sets().
Definition at line 1860 of file parse_agg.c.
References a, b, cmp_list_len_asc(), forboth, lca(), lfirst, lfirst_int, and res.
Referenced by expand_grouping_sets().
Definition at line 1894 of file parse_agg.c.
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().
|
static |
Definition at line 1748 of file parse_agg.c.
References Assert, GroupingSet::content, GROUPING_SET_CUBE, GROUPING_SET_EMPTY, GROUPING_SET_ROLLUP, GROUPING_SET_SETS, GROUPING_SET_SIMPLE, i, lappend(), lfirst, list_concat(), list_length(), list_make1, and NIL.
Referenced by expand_grouping_sets().
|
static |
Definition at line 1541 of file parse_agg.c.
References context, finalize_grouping_exprs_walker(), and NIL.
Referenced by parseCheckAggregates().
|
static |
Definition at line 1561 of file parse_agg.c.
References Aggref::aggdirectargs, GroupingFunc::agglevelsup, Assert, context, equal(), ereport, errcode(), errmsg(), ERROR, TargetEntry::expr, expression_tree_walker, exprLocation(), flatten_join_alias_vars(), if(), IsA, lappend_int(), lfirst, NIL, parser_errposition(), query_tree_walker, TargetEntry::ressortgroupref, Var::varattno, Var::varlevelsup, and Var::varno.
Referenced by finalize_grouping_exprs().
Definition at line 1997 of file parse_agg.c.
References Assert, FUNC_MAX_ARGS, lfirst_oid, and list_length().
Referenced by ExecInitAgg(), get_agg_expr_helper(), and preprocess_aggref().
Definition at line 2265 of file parse_agg.c.
References Param::location, makeNode, PARAM_EXEC, Param::paramid, Param::paramkind, and Param::paramtype.
Referenced by build_aggregate_deserialfn_expr(), build_aggregate_finalfn_expr(), build_aggregate_serialfn_expr(), and build_aggregate_transfn_expr().
void parseCheckAggregates | ( | ParseState * | pstate, |
Query * | qry | ||
) |
Definition at line 1085 of file parse_agg.c.
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().
Oid resolve_aggregate_transtype | ( | Oid | aggfuncid, |
Oid | aggtranstype, | ||
Oid * | inputTypes, | ||
int | numArguments | ||
) |
Definition at line 2023 of file parse_agg.c.
References Assert, enforce_generic_type_consistency(), get_func_signature(), and pfree().
Referenced by initialize_peragg(), and preprocess_aggref().
|
static |
Definition at line 1305 of file parse_agg.c.
References context, and substitute_grouped_columns_mutator().
Referenced by parseCheckAggregates().
|
static |
Definition at line 1327 of file parse_agg.c.
References Aggref::aggdirectargs, GroupingFunc::agglevelsup, Assert, attname, attnum, buildGroupedVar(), check_functional_grouping(), context, copyObject, equal(), ereport, errcode(), errdetail(), errmsg(), ERROR, TargetEntry::expr, expression_tree_mutator, get_rte_attribute_name(), if(), IsA, lappend_int(), lfirst, list_length(), list_member_int(), Var::location, parser_errposition(), query_tree_mutator, RangeTblEntry::relid, TargetEntry::ressortgroupref, rt_fetch, RTE_RELATION, RangeTblEntry::rtekind, Var::varattno, Var::varlevelsup, and Var::varno.
Referenced by substitute_grouped_columns().
void transformAggregateCall | ( | ParseState * | pstate, |
Aggref * | agg, | ||
List * | args, | ||
List * | aggorder, | ||
bool | agg_distinct | ||
) |
Definition at line 109 of file parse_agg.c.
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().
Node* transformGroupingFunc | ( | ParseState * | pstate, |
GroupingFunc * | p | ||
) |
Definition at line 265 of file parse_agg.c.
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().
void transformWindowFuncCall | ( | ParseState * | pstate, |
WindowFunc * | wfunc, | ||
WindowDef * | windef | ||
) |
Definition at line 825 of file parse_agg.c.
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().