50 #include "utils/fmgroids.h" 124 bool *haveNull,
bool *forceTrue);
127 bool *haveNull,
bool *forceFalse);
130 Oid result_type,
int32 result_typmod,
131 Oid result_collid,
Oid input_collid,
List **args_p,
132 bool funcvariadic,
bool process_args,
bool allow_non_const,
236 context.
costs = costs;
270 elog(
ERROR,
"cache lookup failed for aggregate %u",
273 aggtransfn = aggform->aggtransfn;
274 aggfinalfn = aggform->aggfinalfn;
275 aggcombinefn = aggform->aggcombinefn;
276 aggserialfn = aggform->aggserialfn;
277 aggdeserialfn = aggform->aggdeserialfn;
278 aggtranstype = aggform->aggtranstype;
279 aggtransspace = aggform->aggtransspace;
334 else if (aggtranstype == INTERNALOID &&
415 if (aggtransspace > 0)
416 avgwidth = aggtransspace;
417 else if (aggtransfn == F_ARRAY_APPEND)
435 int32 aggtranstypmod = -1;
451 else if (aggtranstype == INTERNALOID)
462 if (aggtransspace > 0)
529 elog(
ERROR,
"WindowFunc contains out-of-range winref %u",
782 return (func_id != F_NEXTVAL_OID &&
879 for (proot = root; proot != NULL; proot = proot->
parent_root)
899 case PROPARALLEL_SAFE:
902 case PROPARALLEL_RESTRICTED:
910 case PROPARALLEL_UNSAFE:
915 elog(
ERROR,
"unrecognized proparallel value \"%c\"", proparallel);
1006 List *save_safe_param_ids;
1250 #define CCDN_CASETESTEXPR_OK 0x0001 1270 int save_flags = *flags;
1285 *flags = save_flags;
1300 save_flags = *flags;
1304 *flags = save_flags;
1403 larg, rcexpr->
largs,
1404 rarg, rcexpr->
rargs)
1532 foreach(l, (
List *) node)
1591 foreach(l, expr->
args)
1757 foreach(l, (
List *) node)
1816 foreach(l, expr->
args)
1940 foreach(l, (
List *) node)
1991 if (var &&
IsA(var,
Var) &&
2005 if (var &&
IsA(var,
Var) &&
2036 if (expr->
useOr && falseOK)
2041 if (rightop &&
IsA(rightop,
Const))
2043 Datum arraydatum = ((
Const *) rightop)->constvalue;
2044 bool arrayisnull = ((
Const *) rightop)->constisnull;
2154 elog(
ERROR,
"cannot commute non-binary-operator clause");
2159 elog(
ERROR,
"could not find commutator for operator %u",
2165 clause->
opno = opoid;
2186 Oid expectedtype,
int32 expectedtypmod,
2187 Oid expectedcollation)
2193 if (rowtypeid == RECORDOID)
2196 if (fieldnum <= 0 || fieldnum > tupdesc->
natts)
2202 if (attr->attisdropped ||
2203 attr->atttypid != expectedtype ||
2204 attr->atttypmod != expectedtypmod ||
2205 attr->attcollation != expectedcollation)
2261 context.
root = root;
2292 context.
root = NULL;
2308 #define ece_generic_processing(node) \ 2309 expression_tree_mutator((Node *) (node), eval_const_expressions_mutator, \ 2317 #define ece_all_arguments_const(node) \ 2318 (!expression_tree_walker((Node *) (node), contain_non_const_walker, NULL)) 2321 #define ece_evaluate_expr(node) \ 2322 ((Node *) evaluate_expr((Expr *) (node), \ 2323 exprType((Node *) (node)), \ 2324 exprTypmod((Node *) (node)), \ 2325 exprCollation((Node *) (node)))) 2387 &typLen, &typByVal);
2388 if (prm->
isnull || typByVal)
2427 elog(
ERROR,
"cache lookup failed for function %u", funcid);
2440 aggfilter = (
Expr *)
2457 return (
Node *) newexpr;
2484 return (
Node *) simple;
2502 return (
Node *) newexpr;
2531 return (
Node *) simple;
2538 if (expr->
opno == BooleanEqualOperator ||
2539 expr->
opno == BooleanNotEqualOperator)
2544 return (
Node *) simple;
2561 return (
Node *) newexpr;
2568 bool has_null_input =
false;
2569 bool all_null_input =
true;
2570 bool has_nonconst_input =
false;
2593 has_null_input |= ((
Const *)
lfirst(arg))->constisnull;
2594 all_null_input &= ((
Const *)
lfirst(arg))->constisnull;
2597 has_nonconst_input =
true;
2601 if (!has_nonconst_input)
2644 return (
Node *) csimple;
2662 return (
Node *) newexpr;
2681 return (
Node *) saop;
2692 bool haveNull =
false;
2693 bool forceTrue =
false;
2720 bool haveNull =
false;
2721 bool forceFalse =
false;
2804 return (
Node *) con;
2810 newrelabel->
arg = (
Expr *) arg;
2816 return (
Node *) newrelabel;
2824 bool outtypisvarlena;
2843 &outfunc, &outtypisvarlena);
2845 &infunc, &intypioparam);
2889 return (
Node *) simple;
2903 return (
Node *) newexpr;
2908 Node *save_case_val;
2969 return (
Node *) con;
2991 return (
Node *) relabel;
3028 Node *save_case_val;
3031 bool const_true_cond;
3032 Node *defresult = NULL;
3051 const_true_cond =
false;
3052 foreach(arg, caseexpr->
args)
3067 if (casecond &&
IsA(casecond,
Const))
3075 const_true_cond =
true;
3083 if (!const_true_cond)
3087 newcasewhen->
expr = (
Expr *) casecond;
3090 newargs =
lappend(newargs, newcasewhen);
3099 defresult = caseresult;
3104 if (!const_true_cond)
3120 newcase->
arg = (
Expr *) newarg;
3121 newcase->
args = newargs;
3124 return (
Node *) newcase;
3168 foreach(arg, coalesceexpr->
args)
3185 if (((
Const *) e)->constisnull)
3189 newargs =
lappend(newargs, e);
3192 newargs =
lappend(newargs, e);
3207 newcoalesce->
args = newargs;
3209 return (
Node *) newcoalesce;
3260 if (arg &&
IsA(arg,
Var) &&
3262 ((
Var *) arg)->varlevelsup == 0)
3274 ((
Var *) arg)->varlevelsup);
3298 newfselect->
arg = (
Expr *) arg;
3314 return (
Node *) newfselect;
3336 foreach(l, rarg->
args)
3362 newntest->
arg = (
Expr *) relem;
3366 newargs =
lappend(newargs, newntest);
3391 elog(
ERROR,
"unrecognized nulltesttype: %d",
3405 return (
Node *) newntest;
3452 elog(
ERROR,
"unrecognized booltesttype: %d",
3465 return (
Node *) newbtest;
3506 return (
Node *) con;
3512 newrelabel->
arg = (
Expr *) arg;
3518 return (
Node *) newrelabel;
3523 newcdomain->
arg = (
Expr *) arg;
3529 return (
Node *) newcdomain;
3590 if (arg != NULL &&
IsA(arg,
Const))
3592 return (
Node *) newcre;
3645 if (provolatile == PROVOLATILE_IMMUTABLE)
3647 if (context->
estimate && provolatile == PROVOLATILE_STABLE)
3674 bool *haveNull,
bool *forceTrue)
3677 List *unprocessed_args;
3691 while (unprocessed_args)
3701 List *oldlist = unprocessed_args;
3752 newargs =
lappend(newargs, arg);
3780 bool *haveNull,
bool *forceFalse)
3783 List *unprocessed_args;
3787 while (unprocessed_args)
3797 List *oldlist = unprocessed_args;
3848 newargs =
lappend(newargs, arg);
3883 if (opno == BooleanEqualOperator)
3898 if (rightop &&
IsA(rightop,
Const))
3901 if (opno == BooleanEqualOperator)
3942 Oid result_collid,
Oid input_collid,
List **args_p,
3943 bool funcvariadic,
bool process_args,
bool allow_non_const,
3965 elog(
ERROR,
"cache lookup failed for function %u", funcid);
3987 result_collid, input_collid,
3989 func_tuple, context);
3991 if (!newexpr && allow_non_const &&
OidIsValid(func_form->prosupport))
4026 if (!newexpr && allow_non_const)
4028 input_collid, args, funcvariadic,
4029 func_tuple, context);
4051 bool has_named_args =
false;
4061 has_named_args =
true;
4100 Assert(nargsprovided <= pronargs);
4102 elog(
ERROR,
"too many function arguments");
4103 MemSet(argarray, 0, pronargs *
sizeof(
Node *));
4114 Assert(argarray[i] == NULL);
4115 argarray[i++] =
arg;
4130 if (nargsprovided < pronargs)
4134 i = pronargs - funcform->pronargdefaults;
4135 foreach(lc, defaults)
4137 if (argarray[i] == NULL)
4147 Assert(argarray[i] != NULL);
4148 args =
lappend(args, argarray[i]);
4172 ndelete = nargsprovided +
list_length(defaults) - funcform->pronargs;
4174 elog(
ERROR,
"not enough default arguments");
4189 Datum proargdefaults;
4195 Anum_pg_proc_proargdefaults,
4198 elog(
ERROR,
"not enough default arguments");
4231 elog(
ERROR,
"too many function arguments");
4237 Assert(nargs == funcform->pronargs);
4238 memcpy(declared_arg_types, funcform->proargtypes.values,
4239 funcform->pronargs *
sizeof(
Oid));
4243 funcform->prorettype,
4246 if (rettype != result_type)
4247 elog(
ERROR,
"function's resolved result type changed during planning");
4272 bool has_nonconst_input =
false;
4273 bool has_null_input =
false;
4280 if (funcform->proretset)
4294 if (funcform->prorettype == RECORDOID)
4303 has_null_input |= ((
Const *)
lfirst(arg))->constisnull;
4305 has_nonconst_input =
true;
4314 if (funcform->proisstrict && has_null_input)
4323 if (has_nonconst_input)
4333 if (funcform->provolatile == PROVOLATILE_IMMUTABLE)
4335 else if (context->
estimate && funcform->provolatile == PROVOLATILE_STABLE)
4346 newexpr->
funcid = funcid;
4402 bool modifyTargetList;
4410 List *raw_parsetree_list;
4421 if (funcform->prolang != SQLlanguageId ||
4422 funcform->prokind != PROKIND_FUNCTION ||
4423 funcform->prosecdef ||
4424 funcform->proretset ||
4425 funcform->prorettype == RECORDOID ||
4454 Anum_pg_proc_prosrc,
4457 elog(
ERROR,
"null prosrc for function %u", funcid);
4465 callback_arg.
prosrc = src;
4468 sqlerrcontext.
arg = (
void *) &callback_arg;
4552 &modifyTargetList, NULL))
4566 if (
exprType(newexpr) != result_type)
4570 Assert(!modifyTargetList);
4580 if (funcform->provolatile == PROVOLATILE_IMMUTABLE &&
4583 else if (funcform->provolatile == PROVOLATILE_STABLE &&
4587 if (funcform->proisstrict &&
4604 usecounts = (
int *)
palloc0(funcform->pronargs *
sizeof(
int));
4614 if (usecounts[i] == 0)
4617 if (funcform->proisstrict)
4620 else if (usecounts[i] != 1)
4668 if (
OidIsValid(exprcoll) && exprcoll != result_collid)
4672 newnode->
arg = (
Expr *) newexpr;
4673 newnode->
collOid = result_collid;
4676 newexpr = (
Node *) newnode;
4697 return (
Expr *) newexpr;
4717 context.
nargs = nargs;
4757 int syntaxerrposition;
4761 if (syntaxerrposition > 0)
4779 Oid result_collation)
4787 bool resultTypByVal;
4834 if (resultTypLen == -1)
4837 const_val =
datumCopy(const_val, resultTypByVal, resultTypLen);
4846 return (
Expr *)
makeConst(result_type, result_typmod, result_collation,
4848 const_val, const_is_null,
4880 bool modifyTargetList;
4886 List *raw_parsetree_list;
4887 List *querytree_list;
4913 func_oid = fexpr->
funcid;
4949 elog(
ERROR,
"cache lookup failed for function %u", func_oid);
4962 if (funcform->prolang != SQLlanguageId ||
4963 funcform->prokind != PROKIND_FUNCTION ||
4964 funcform->proisstrict ||
4965 funcform->provolatile == PROVOLATILE_VOLATILE ||
4966 funcform->prorettype == VOIDOID ||
4967 funcform->prosecdef ||
4968 !funcform->proretset ||
4981 "inline_set_returning_function",
4988 Anum_pg_proc_prosrc,
4991 elog(
ERROR,
"null prosrc for function %u", func_oid);
4999 callback_arg.
prosrc = src;
5002 sqlerrcontext.
arg = (
void *) &callback_arg;
5013 fexpr->inputcollid);
5030 querytree =
linitial(querytree_list);
5054 &modifyTargetList, NULL) &&
5055 (
get_typtype(fexpr->funcresulttype) == TYPTYPE_COMPOSITE ||
5056 fexpr->funcresulttype == RECORDOID))
5064 if (modifyTargetList)
5075 if (fexpr->funcresulttype == RECORDOID &&
5134 context.
nargs = nargs;
5204 foreach(tlistitem, tlist)
5212 if (clistitem == NULL)
5216 clistitem =
lnext(coltypelist, clistitem);
5222 if (clistitem != NULL)
#define list_make3(x1, x2, x3)
Expr * evaluate_expr(Expr *expr, Oid result_type, int32 result_typmod, Oid result_collation)
void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root)
ParamExternData params[FLEXIBLE_ARRAY_MEMBER]
#define ece_generic_processing(node)
bool query_tree_walker(Query *query, bool(*walker)(), void *context, int flags)
double expression_returns_set_rows(PlannerInfo *root, Node *clause)
bool get_func_leakproof(Oid funcid)
bool contain_leaked_vars(Node *clause)
#define IsA(nodeptr, _type_)
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)
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
bool is_pseudo_constant_clause_relids(Node *clause, Relids relids)
bool contain_volatile_functions_not_nextval(Node *clause)
static Datum ExecEvalExprSwitchContext(ExprState *state, ExprContext *econtext, bool *isNull)
Oid enforce_generic_type_consistency(const Oid *actual_arg_types, Oid *declared_arg_types, int nargs, Oid rettype, bool allow_poly)
Node * negate_clause(Node *node)
Oid get_commutator(Oid opno)
Node * expression_tree_mutator(Node *node, Node *(*mutator)(), void *context)
#define PG_DETOAST_DATUM_COPY(datum)
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
List * expand_function_arguments(List *args, Oid result_type, HeapTuple func_tuple)
void IncrementVarSublevelsUp(Node *node, int delta_sublevels_up, int min_sublevels_up)
static bool contain_mutable_functions_walker(Node *node, void *context)
static ListCell * lnext(const List *l, const ListCell *c)
Node * estimate_expression_value(PlannerInfo *root, Node *node)
PlannerInfo * parent_root
static bool is_orclause(const void *clause)
#define castNode(_type_, nodeptr)
int32 exprTypmod(const Node *expr)
static bool contain_volatile_functions_not_nextval_walker(Node *node, void *context)
#define PointerGetDatum(X)
#define TupleDescAttr(tupdesc, i)
#define forthree(cell1, list1, cell2, list2, cell3, list3)
struct PlannerInfo * root
void fix_opfuncids(Node *node)
void sql_fn_parser_setup(struct ParseState *pstate, SQLFunctionParseInfoPtr pinfo)
void get_agg_clause_costs(PlannerInfo *root, Node *clause, AggSplit aggsplit, AggClauseCosts *costs)
int ArrayGetNItems(int ndim, const int *dims)
WindowFuncLists * find_window_functions(Node *clause, Index maxWinRef)
static bool is_andclause(const void *clause)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
List * list_copy(const List *oldlist)
static bool contain_agg_clause_walker(Node *node, void *context)
Query * inline_set_returning_function(PlannerInfo *root, RangeTblEntry *rte)
CoercionForm coercionformat
List * list_concat(List *list1, const List *list2)
void * stringToNode(const char *str)
bool check_sql_fn_retval(Oid func_id, Oid rettype, List *queryTreeList, bool *modifyTargetList, JunkFilter **junkFilter)
char get_typtype(Oid typid)
void CommuteOpExpr(OpExpr *clause)
#define MemSet(start, val, len)
Node * eval_const_expressions(PlannerInfo *root, Node *node)
static bool contain_mutable_functions_checker(Oid func_id, void *context)
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
static bool contain_nonstrict_functions_walker(Node *node, void *context)
void add_function_cost(PlannerInfo *root, Oid funcid, Node *node, QualCost *cost)
bool contain_var_clause(Node *node)
bool contain_volatile_functions(Node *clause)
void make_fn_arguments(ParseState *pstate, List *fargs, Oid *actual_arg_types, Oid *declared_arg_types)
List * list_copy_tail(const List *oldlist, int nskip)
Expr * make_orclause(List *orclauses)
Const * makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
void(* callback)(void *arg)
List * lappend_oid(List *list, Oid datum)
struct ErrorContextCallback * previous
#define OidIsValid(objectId)
#define FmgrHookIsNeeded(fn_oid)
#define DO_AGGSPLIT_COMBINE(as)
#define ece_all_arguments_const(node)
TupleDesc lookup_rowtype_tupdesc_domain(Oid type_id, int32 typmod, bool noError)
static bool get_agg_clause_costs_walker(Node *node, get_agg_clause_costs_context *context)
char max_parallel_hazard(Query *parse)
Const * makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid)
ParseState * make_parsestate(ParseState *parentParseState)
List * find_forced_null_vars(Node *node)
ErrorContextCallback * error_context_stack
bool DomainHasConstraints(Oid type_id)
bool check_functions_in_node(Node *node, check_function_callback checker, void *context)
static Node * substitute_actual_srf_parameters_mutator(Node *node, substitute_actual_srf_parameters_context *context)
bool get_typbyval(Oid typid)
bool contain_subplans(Node *clause)
void FreeExecutorState(EState *estate)
#define GetPerTupleExprContext(estate)
bool is_parallel_safe(PlannerInfo *root, Node *node)
static void recheck_cast_function_args(List *args, Oid result_type, HeapTuple func_tuple)
static bool contain_volatile_functions_walker(Node *node, void *context)
#define DO_AGGSPLIT_SERIALIZE(as)
static Node * eval_const_expressions_mutator(Node *node, eval_const_expressions_context *context)
ParamFetchHook paramFetch
void pfree(void *pointer)
MemoryContext es_query_cxt
ParamListInfo boundParams
#define ObjectIdGetDatum(X)
bool list_member(const List *list, const void *datum)
static bool rowtype_field_matches(Oid rowtypeid, int fieldnum, Oid expectedtype, int32 expectedtypmod, Oid expectedcollation)
static Node * substitute_actual_parameters_mutator(Node *node, substitute_actual_parameters_context *context)
static void * list_nth(const List *list, int n)
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Bitmapset * bms_join(Bitmapset *a, Bitmapset *b)
List * pg_parse_query(const char *query_string)
Node * makeBoolConst(bool value, bool isnull)
static bool max_parallel_hazard_test(char proparallel, max_parallel_hazard_context *context)
#define OidFunctionCall1(functionId, arg1)
#define ALLOCSET_DEFAULT_SIZES
#define lfirst_node(type, lc)
int bms_num_members(const Bitmapset *a)
bool list_member_int(const List *list, int datum)
void(* ParserSetupHook)(struct ParseState *pstate, void *arg)
Relids find_nonnullable_rels(Node *clause)
Bitmapset * bms_make_singleton(int x)
Expr * make_andclause(List *andclauses)