55#include "utils/fmgroids.h"
166 int nargs,
List *args);
244 lists->numWindowFuncs = 0;
245 lists->maxWinRef = maxWinRef;
262 elog(
ERROR,
"WindowFunc contains out-of-range winref %u",
267 lists->numWindowFuncs++;
306 if (expr->funcretset)
438 if (
cnst->constisnull)
775 root->glob->paramExecTypes ==
NIL)
789 foreach(l,
proot->init_plans)
1197#define CCDN_CASETESTEXPR_OK 0x0001
1499 foreach(l, (
List *) node)
1558 foreach(l, expr->
args)
1683 if (
phv->phlevelsup == 0 &&
1752 foreach(l, (
List *) node)
1816 foreach(l, expr->
args)
1951 foreach(l, (
List *) node)
2002 if (var &&
IsA(var,
Var) &&
2016 if (var &&
IsA(var,
Var) &&
2070 if (arrayexpr->elements !=
NIL && !arrayexpr->multidims)
2167 elog(
ERROR,
"cannot commute non-binary-operator clause");
2172 elog(
ERROR,
"could not find commutator for operator %u",
2215 if (attr->attisdropped ||
2282#define MIN_ARRAY_SIZE_FOR_HASHED_SAOP 9
2430#define ece_generic_processing(node) \
2431 expression_tree_mutator((Node *) (node), eval_const_expressions_mutator, \
2439#define ece_all_arguments_const(node) \
2440 (!expression_tree_walker((Node *) (node), contain_non_const_walker, NULL))
2443#define ece_evaluate_expr(node) \
2444 ((Node *) evaluate_expr((Expr *) (node), \
2445 exprType((Node *) (node)), \
2446 exprTypmod((Node *) (node)), \
2447 exprCollation((Node *) (node))))
2514 &typLen, &typByVal);
2515 if (
prm->isnull || typByVal)
2527 return (
Node *) con;
2556 elog(
ERROR,
"cache lookup failed for function %u", funcid);
2559 false, expr->wintype,
2570 aggfilter = (
Expr *)
2577 newexpr->wintype = expr->wintype;
2578 newexpr->wincollid = expr->wincollid;
2579 newexpr->inputcollid = expr->inputcollid;
2581 newexpr->aggfilter = aggfilter;
2582 newexpr->runCondition = expr->runCondition;
2584 newexpr->winstar = expr->winstar;
2585 newexpr->winagg = expr->winagg;
2606 expr->funcresulttype,
2616 return (
Node *) simple;
2626 newexpr->funcresulttype = expr->funcresulttype;
2627 newexpr->funcretset = expr->funcretset;
2628 newexpr->funcvariadic = expr->funcvariadic;
2629 newexpr->funcformat = expr->funcformat;
2630 newexpr->funccollid = expr->funccollid;
2631 newexpr->inputcollid = expr->inputcollid;
2659 expr->opresulttype, -1,
2668 return (
Node *) simple;
2681 return (
Node *) simple;
2691 newexpr->opfuncid = expr->opfuncid;
2692 newexpr->opresulttype = expr->opresulttype;
2693 newexpr->opretset = expr->opretset;
2694 newexpr->opcollid = expr->opcollid;
2695 newexpr->inputcollid = expr->inputcollid;
2763 expr->opresulttype, -1,
2792 newexpr->opfuncid = expr->opfuncid;
2793 newexpr->opresulttype = expr->opresulttype;
2794 newexpr->opretset = expr->opretset;
2795 newexpr->opcollid = expr->opcollid;
2796 newexpr->inputcollid = expr->inputcollid;
2829 return (
Node *) expr;
2848 return (
Node *) saop;
2938 Node *formatted_expr = (
Node *)
jve->formatted_expr;
2948 if (formatted_expr &&
IsA(formatted_expr,
Const))
2949 return formatted_expr;
2954 (
Expr *) formatted_expr,
3055 return (
Node *) simple;
3066 newexpr->resultcollid = expr->resultcollid;
3067 newexpr->coerceformat = expr->coerceformat;
3426 ((
Var *)
arg)->varlevelsup == 0)
3441 ((
Var *)
arg)->varlevelsup);
3443 newvar->varreturningtype = ((
Var *)
arg)->varreturningtype;
3445 newvar->varnullingrels = ((
Var *)
arg)->varnullingrels;
3509 foreach(l, rarg->
args)
3521 if (
carg->constisnull ?
3569 switch (
ntest->nulltesttype)
3572 result =
carg->constisnull;
3575 result = !
carg->constisnull;
3578 elog(
ERROR,
"unrecognized nulltesttype: %d",
3579 (
int)
ntest->nulltesttype);
3591 switch (
ntest->nulltesttype)
3600 elog(
ERROR,
"unrecognized nulltesttype: %d",
3601 (
int)
ntest->nulltesttype);
3636 switch (
btest->booltesttype)
3639 result = (!
carg->constisnull &&
3643 result = (
carg->constisnull ||
3647 result = (!
carg->constisnull &&
3651 result = (
carg->constisnull ||
3655 result =
carg->constisnull;
3658 result = !
carg->constisnull;
3661 elog(
ERROR,
"unrecognized booltesttype: %d",
3662 (
int)
btest->booltesttype);
3749 newcre->convertformat =
cre->convertformat;
4155 elog(
ERROR,
"cache lookup failed for function %u", funcid);
4194 fexpr.funcid = funcid;
4195 fexpr.funcresulttype = result_type;
4202 fexpr.location = -1;
4252 req.aggref = aggref;
4267 return (
Node *) aggref;
4359 return !((
Const *) expr)->constisnull;
4521 elog(
ERROR,
"proallargtypes is not a 1-D Oid array or it contains nulls");
4578 elog(
ERROR,
"too many function arguments");
4612 foreach(
lc, defaults)
4650 elog(
ERROR,
"not enough default arguments");
4704 elog(
ERROR,
"too many function arguments");
4718 if (rettype != result_type)
4719 elog(
ERROR,
"function's resolved result type changed during planning");
4818 newexpr->funcresulttype = result_type;
4929 fexpr->funcid = funcid;
4930 fexpr->funcresulttype = result_type;
4931 fexpr->funcretset =
false;
4937 fexpr->location = -1;
4948 callback_arg.
prosrc = src;
5053 result_type, rettupdesc,
5121 if (usecounts[
i] == 0)
5127 else if (usecounts[
i] != 1)
5224 context.
nargs = nargs;
5225 context.
args = args;
5400 if (
rte->funcordinality)
5459 "inline_function_in_from",
5477 req.rtfunc = rtfunc;
5493 callback_arg.
prosrc = src;
5552 root->glob->dependsOnRole =
true;
5599 if (!
fexpr->funcretset)
5659 fexpr->inputcollid);
5684 if (rtfunc->funccolnames !=
NIL)
5688 rtfunc->funccoltypes,
5689 rtfunc->funccoltypmods,
5690 rtfunc->funccolcollations);
5716 fexpr->funcresulttype, rettupdesc,
5744 context.
nargs = nargs;
5745 context.
args = args;
5769 context->sublevels_up--;
5878 elems[
i] =
value->constvalue;
5879 nulls[
i++] =
value->constisnull;
5883 coltype, typlen, typbyval,
typalign);
5900 saopexpr->inputcollid = inputcollid;
Datum querytree(PG_FUNCTION_ARGS)
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
#define DatumGetArrayTypeP(X)
ArrayType * construct_md_array(Datum *elems, bool *nulls, int ndims, int *dims, int *lbs, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
int ArrayGetNItems(int ndim, const int *dims)
#define InvalidAttrNumber
Bitmapset * bms_make_singleton(int x)
Bitmapset * bms_int_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
void bms_free(Bitmapset *a)
int bms_num_members(const Bitmapset *a)
bool bms_is_member(int x, const Bitmapset *a)
Bitmapset * bms_add_member(Bitmapset *a, int x)
Bitmapset * bms_add_members(Bitmapset *a, const Bitmapset *b)
BMS_Membership bms_membership(const Bitmapset *a)
Bitmapset * bms_join(Bitmapset *a, Bitmapset *b)
#define TextDatumGetCString(d)
#define Assert(condition)
#define OidIsValid(objectId)
static bool contain_subplans_walker(Node *node, void *context)
#define CCDN_CASETESTEXPR_OK
static List * simplify_or_arguments(List *args, eval_const_expressions_context *context, bool *haveNull, bool *forceTrue)
static bool is_strict_saop(ScalarArrayOpExpr *expr, bool falseOK)
bool contain_volatile_functions_not_nextval(Node *clause)
List * find_forced_null_vars(Node *node)
static bool contain_leaked_vars_checker(Oid func_id, void *context)
static bool rowtype_field_matches(Oid rowtypeid, int fieldnum, Oid expectedtype, int32 expectedtypmod, Oid expectedcollation)
Query * inline_function_in_from(PlannerInfo *root, RangeTblEntry *rte)
static bool contain_nonstrict_functions_walker(Node *node, void *context)
static List * add_function_defaults(List *args, int pronargs, HeapTuple func_tuple)
#define ece_all_arguments_const(node)
#define ece_evaluate_expr(node)
static bool max_parallel_hazard_checker(Oid func_id, void *context)
static bool max_parallel_hazard_test(char proparallel, max_parallel_hazard_context *context)
bool contain_agg_clause(Node *clause)
static bool contain_agg_clause_walker(Node *node, void *context)
static bool contain_nonstrict_functions_checker(Oid func_id, void *context)
int NumRelids(PlannerInfo *root, Node *clause)
bool contain_mutable_functions(Node *clause)
bool is_pseudo_constant_clause(Node *clause)
static bool max_parallel_hazard_walker(Node *node, max_parallel_hazard_context *context)
bool contain_window_function(Node *clause)
#define ece_generic_processing(node)
Node * estimate_expression_value(PlannerInfo *root, Node *node)
static Expr * evaluate_function(Oid funcid, Oid result_type, int32 result_typmod, Oid result_collid, Oid input_collid, List *args, bool funcvariadic, HeapTuple func_tuple, eval_const_expressions_context *context)
static Node * substitute_actual_parameters_mutator(Node *node, substitute_actual_parameters_context *context)
static bool contain_mutable_functions_checker(Oid func_id, void *context)
Var * find_forced_null_var(Node *node)
bool is_pseudo_constant_clause_relids(Node *clause, Relids relids)
static bool ece_function_is_safe(Oid funcid, eval_const_expressions_context *context)
static bool contain_volatile_functions_checker(Oid func_id, void *context)
static List * simplify_and_arguments(List *args, eval_const_expressions_context *context, bool *haveNull, bool *forceFalse)
WindowFuncLists * find_window_functions(Node *clause, Index maxWinRef)
static Expr * simplify_function(Oid funcid, Oid result_type, int32 result_typmod, Oid result_collid, Oid input_collid, List **args_p, bool funcvariadic, bool process_args, bool allow_non_const, eval_const_expressions_context *context)
Node * eval_const_expressions(PlannerInfo *root, Node *node)
bool contain_volatile_functions_after_planning(Expr *expr)
static Expr * inline_function(Oid funcid, Oid result_type, Oid result_collid, Oid input_collid, List *args, bool funcvariadic, HeapTuple func_tuple, eval_const_expressions_context *context)
static List * reorder_function_arguments(List *args, int pronargs, HeapTuple func_tuple)
static Node * simplify_aggref(Aggref *aggref, eval_const_expressions_context *context)
static Node * substitute_actual_parameters(Node *expr, int nargs, List *args, int *usecounts)
static bool contain_mutable_functions_walker(Node *node, void *context)
static Query * substitute_actual_parameters_in_from(Query *expr, int nargs, List *args)
bool contain_mutable_functions_after_planning(Expr *expr)
static bool contain_volatile_functions_walker(Node *node, void *context)
bool contain_leaked_vars(Node *clause)
List * find_nonnullable_vars(Node *clause)
static Relids find_nonnullable_rels_walker(Node *node, bool top_level)
void convert_saop_to_hashed_saop(Node *node)
static void sql_inline_error_callback(void *arg)
static bool contain_volatile_functions_not_nextval_walker(Node *node, void *context)
static bool contain_leaked_vars_walker(Node *node, void *context)
static bool contain_non_const_walker(Node *node, void *context)
static bool contain_context_dependent_node(Node *clause)
Relids find_nonnullable_rels(Node *clause)
static void recheck_cast_function_args(List *args, Oid result_type, Oid *proargtypes, int pronargs, HeapTuple func_tuple)
static bool find_window_functions_walker(Node *node, WindowFuncLists *lists)
List * expand_function_arguments(List *args, bool include_out_arguments, Oid result_type, HeapTuple func_tuple)
char max_parallel_hazard(Query *parse)
bool is_parallel_safe(PlannerInfo *root, Node *node)
bool contain_nonstrict_functions(Node *clause)
static bool contain_volatile_functions_not_nextval_checker(Oid func_id, void *context)
static List * find_nonnullable_vars_walker(Node *node, bool top_level)
static Node * substitute_actual_parameters_in_from_mutator(Node *node, substitute_actual_parameters_in_from_context *context)
static Query * inline_sql_function_in_from(PlannerInfo *root, RangeTblFunction *rtfunc, FuncExpr *fexpr, HeapTuple func_tuple, Form_pg_proc funcform, const char *src)
bool contain_subplans(Node *clause)
static Node * simplify_boolean_equality(Oid opno, List *args)
static bool contain_exec_param_walker(Node *node, List *param_ids)
Bitmapset * pull_paramids(Expr *expr)
void CommuteOpExpr(OpExpr *clause)
ScalarArrayOpExpr * make_SAOP_expr(Oid oper, Node *leftexpr, Oid coltype, Oid arraycollid, Oid inputcollid, List *exprs, bool haveNonConst)
static Node * eval_const_expressions_mutator(Node *node, eval_const_expressions_context *context)
static bool pull_paramids_walker(Node *node, Bitmapset **context)
Expr * evaluate_expr(Expr *expr, Oid result_type, int32 result_typmod, Oid result_collation)
static bool convert_saop_to_hashed_saop_walker(Node *node, void *context)
bool expr_is_nonnullable(PlannerInfo *root, Expr *expr, bool use_rel_info)
static List * fetch_function_defaults(HeapTuple func_tuple)
bool contain_volatile_functions(Node *clause)
double expression_returns_set_rows(PlannerInfo *root, Node *clause)
bool var_is_nonnullable(PlannerInfo *root, Var *var, bool use_rel_info)
static bool contain_context_dependent_node_walker(Node *node, int *flags)
bool contain_exec_param(Node *clause, List *param_ids)
#define MIN_ARRAY_SIZE_FOR_HASHED_SAOP
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
double clamp_row_est(double nrows)
Datum datumCopy(Datum value, bool typByVal, int typLen)
int internalerrquery(const char *query)
int internalerrposition(int cursorpos)
ErrorContextCallback * error_context_stack
int errposition(int cursorpos)
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
void FreeExecutorState(EState *estate)
EState * CreateExecutorState(void)
#define GetPerTupleExprContext(estate)
static Datum ExecEvalExprSwitchContext(ExprState *state, ExprContext *econtext, bool *isNull)
#define palloc_object(type)
#define palloc_array(type, count)
#define OidFunctionCall1(functionId, arg1)
#define PG_DETOAST_DATUM_COPY(datum)
#define FmgrHookIsNeeded(fn_oid)
TypeFuncClass get_expr_result_type(Node *expr, Oid *resultTypeId, TupleDesc *resultTupleDesc)
@ TYPEFUNC_COMPOSITE_DOMAIN
bool check_sql_fn_retval(List *queryTreeLists, Oid rettype, TupleDesc rettupdesc, char prokind, bool insertDroppedCols)
void sql_fn_parser_setup(struct ParseState *pstate, SQLFunctionParseInfoPtr pinfo)
SQLFunctionParseInfoPtr prepare_sql_fn_parse_info(HeapTuple procedureTuple, Node *call_expr, Oid inputCollation)
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
#define HeapTupleIsValid(tuple)
static void * GETSTRUCT(const HeapTupleData *tuple)
bool to_json_is_immutable(Oid typoid)
bool to_jsonb_is_immutable(Oid typoid)
bool jspIsMutable(JsonPath *path, List *varnames, List *varexprs)
static JsonPath * DatumGetJsonPathP(Datum d)
List * lappend(List *list, void *datum)
List * list_delete_first(List *list)
List * list_concat(List *list1, const List *list2)
List * list_concat_copy(const List *list1, const List *list2)
List * list_copy(const List *oldlist)
List * lappend_oid(List *list, Oid datum)
List * list_delete_last(List *list)
void list_free(List *list)
bool list_member_int(const List *list, int datum)
bool list_member_oid(const List *list, Oid datum)
List * list_delete_first_n(List *list, int n)
char func_parallel(Oid funcid)
RegProcedure get_func_support(Oid funcid)
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
RegProcedure get_opcode(Oid opno)
void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)
char func_volatile(Oid funcid)
bool func_strict(Oid funcid)
bool get_func_leakproof(Oid funcid)
const struct SubscriptRoutines * getSubscriptingRoutines(Oid typid, Oid *typelemp)
bool get_op_hash_functions(Oid opno, RegProcedure *lhs_procno, RegProcedure *rhs_procno)
Oid get_array_type(Oid typid)
Oid get_negator(Oid opno)
Oid get_commutator(Oid opno)
Expr * make_orclause(List *orclauses)
Var * makeVar(int varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
Const * makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid)
Node * makeBoolConst(bool value, bool isnull)
Expr * make_andclause(List *andclauses)
JsonValueExpr * makeJsonValueExpr(Expr *raw_expr, Expr *formatted_expr, JsonFormat *format)
Const * makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
List * mbms_add_members(List *a, const List *b)
List * mbms_add_member(List *a, int listidx, int bitidx)
List * mbms_int_members(List *a, const List *b)
Oid exprType(const Node *expr)
int32 exprTypmod(const Node *expr)
bool check_functions_in_node(Node *node, check_function_callback checker, void *context)
Oid exprCollation(const Node *expr)
Node * applyRelabelType(Node *arg, Oid rtype, int32 rtypmod, Oid rcollid, CoercionForm rformat, int rlocation, bool overwrite_ok)
void fix_opfuncids(Node *node)
void set_sa_opfuncid(ScalarArrayOpExpr *opexpr)
void set_opfuncid(OpExpr *opexpr)
#define expression_tree_mutator(n, m, c)
static bool is_andclause(const void *clause)
static bool is_orclause(const void *clause)
#define query_tree_walker(q, w, c, f)
static bool is_opclause(const void *clause)
#define expression_tree_walker(n, w, c)
#define query_tree_mutator(q, m, c, f)
#define IsA(nodeptr, _type_)
#define castNode(_type_, nodeptr)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
void(* ParserSetupHook)(ParseState *pstate, void *arg)
Oid enforce_generic_type_consistency(const Oid *actual_arg_types, Oid *declared_arg_types, int nargs, Oid rettype, bool allow_poly)
void make_fn_arguments(ParseState *pstate, List *fargs, Oid *actual_arg_types, Oid *declared_arg_types)
void free_parsestate(ParseState *pstate)
ParseState * make_parsestate(ParseState *parentParseState)
Operator oper(ParseState *pstate, List *opname, Oid ltypeId, Oid rtypeId, bool noError, int location)
Query * transformTopLevelStmt(ParseState *pstate, RawStmt *parseTree)
#define planner_rt_fetch(rti, root)
FormData_pg_attribute * Form_pg_attribute
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define linitial_node(type, l)
#define foreach_ptr(type, var, lst)
#define forthree(cell1, list1, cell2, list2, cell3, list3)
static void * list_nth(const List *list, int n)
#define list_make3(x1, x2, x3)
#define foreach_node(type, var, lst)
#define list_make2(x1, x2)
FormData_pg_proc * Form_pg_proc
double get_function_rows(PlannerInfo *root, Oid funcid, Node *node)
Bitmapset * find_relation_notnullatts(PlannerInfo *root, Oid relid)
Expr * expression_planner(Expr *expr)
List * pg_analyze_and_rewrite_withcb(RawStmt *parsetree, const char *query_string, ParserSetupHook parserSetup, void *parserSetupArg, QueryEnvironment *queryEnv)
List * pg_parse_query(const char *query_string)
List * pg_rewrite_query(Query *query)
static bool DatumGetBool(Datum X)
static Datum PointerGetDatum(const void *X)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
static Pointer DatumGetPointer(Datum X)
static Datum Int32GetDatum(int32 X)
Node * negate_clause(Node *node)
void * stringToNode(const char *str)
RelOptInfo * find_base_rel(PlannerInfo *root, int relid)
void AcquireRewriteLocks(Query *parsetree, bool forExecute, bool forUpdatePushedDown)
bool contain_windowfuncs(Node *node)
void IncrementVarSublevelsUp(Node *node, int delta_sublevels_up, int min_sublevels_up)
void record_plan_type_dependency(PlannerInfo *root, Oid typid)
void record_plan_function_dependency(PlannerInfo *root, Oid funcid)
void check_stack_depth(void)
BoolTestType booltesttype
MemoryContext es_query_cxt
struct ErrorContextCallback * previous
NullTestType nulltesttype
ParamExternData params[FLEXIBLE_ARRAY_MEMBER]
ParamFetchHook paramFetch
const char * p_sourcetext
VolatileFunctionStatus has_volatile_expr
Bitmapset * notnullattnums
ParamListInfo boundParams
#define FirstLowInvalidHeapAttributeNumber
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)
TupleDesc BuildDescFromLists(const List *names, const List *types, const List *typmods, const List *collations)
#define ReleaseTupleDesc(tupdesc)
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
TupleDesc lookup_rowtype_tupdesc_domain(Oid type_id, int32 typmod, bool noError)
bool DomainHasConstraints(Oid type_id)
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
#define TYPECACHE_CMP_PROC
bool contain_var_clause(Node *node)
Relids pull_varnos(PlannerInfo *root, Node *node)