53 #include "utils/fmgroids.h"
122 bool *haveNull,
bool *forceTrue);
125 bool *haveNull,
bool *forceFalse);
128 Oid result_type,
int32 result_typmod,
129 Oid result_collid,
Oid input_collid,
List **args_p,
130 bool funcvariadic,
bool process_args,
bool allow_non_const,
252 elog(
ERROR,
"WindowFunc contains out-of-range winref %u",
397 foreach(lc, ctor->
args)
611 return (func_id != F_NEXTVAL &&
708 for (proot = root; proot != NULL; proot = proot->
parent_root)
728 case PROPARALLEL_SAFE:
731 case PROPARALLEL_RESTRICTED:
739 case PROPARALLEL_UNSAFE:
744 elog(
ERROR,
"unrecognized proparallel value \"%c\"", proparallel);
835 List *save_safe_param_ids;
1128 #define CCDN_CASETESTEXPR_OK 0x0001
1148 int save_flags = *flags;
1163 *flags = save_flags;
1178 save_flags = *flags;
1182 *flags = save_flags;
1300 larg, rcexpr->
largs,
1301 rarg, rcexpr->
rargs)
1429 foreach(l, (
List *) node)
1488 foreach(l, expr->
args)
1654 foreach(l, (
List *) node)
1713 foreach(l, expr->
args)
1837 foreach(l, (
List *) node)
1933 if (expr->
useOr && falseOK)
1938 if (rightop &&
IsA(rightop,
Const))
1940 Datum arraydatum = ((
Const *) rightop)->constvalue;
1941 bool arrayisnull = ((
Const *) rightop)->constisnull;
2051 elog(
ERROR,
"cannot commute non-binary-operator clause");
2056 elog(
ERROR,
"could not find commutator for operator %u",
2062 clause->
opno = opoid;
2083 Oid expectedtype,
int32 expectedtypmod,
2084 Oid expectedcollation)
2090 if (rowtypeid == RECORDOID)
2093 if (fieldnum <= 0 || fieldnum > tupdesc->
natts)
2099 if (attr->attisdropped ||
2100 attr->atttypid != expectedtype ||
2101 attr->atttypmod != expectedtypmod ||
2102 attr->attcollation != expectedcollation)
2158 context.
root = root;
2165 #define MIN_ARRAY_SIZE_FOR_HASHED_SAOP 9
2200 if (arrayarg &&
IsA(arrayarg,
Const) &&
2201 !((
Const *) arrayarg)->constisnull)
2206 lefthashfunc == righthashfunc)
2208 Datum arrdatum = ((
Const *) arrayarg)->constvalue;
2238 lefthashfunc == righthashfunc)
2240 Datum arrdatum = ((
Const *) arrayarg)->constvalue;
2296 context.
root = NULL;
2312 #define ece_generic_processing(node) \
2313 expression_tree_mutator((Node *) (node), eval_const_expressions_mutator, \
2321 #define ece_all_arguments_const(node) \
2322 (!expression_tree_walker((Node *) (node), contain_non_const_walker, NULL))
2325 #define ece_evaluate_expr(node) \
2326 ((Node *) evaluate_expr((Expr *) (node), \
2327 exprType((Node *) (node)), \
2328 exprTypmod((Node *) (node)), \
2329 exprCollation((Node *) (node))))
2392 &typLen, &typByVal);
2393 if (prm->
isnull || typByVal)
2405 return (
Node *) con;
2434 elog(
ERROR,
"cache lookup failed for function %u", funcid);
2448 aggfilter = (
Expr *)
2465 return (
Node *) newexpr;
2492 return (
Node *) simple;
2510 return (
Node *) newexpr;
2539 return (
Node *) simple;
2546 if (expr->
opno == BooleanEqualOperator ||
2547 expr->
opno == BooleanNotEqualOperator)
2552 return (
Node *) simple;
2569 return (
Node *) newexpr;
2576 bool has_null_input =
false;
2577 bool all_null_input =
true;
2578 bool has_nonconst_input =
false;
2605 has_nonconst_input =
true;
2609 if (!has_nonconst_input)
2652 return (
Node *) csimple;
2670 return (
Node *) newexpr;
2676 bool has_nonconst_input =
false;
2685 has_nonconst_input =
true;
2696 if (!has_nonconst_input &&
2700 return (
Node *) expr;
2719 return (
Node *) saop;
2730 bool haveNull =
false;
2731 bool forceTrue =
false;
2758 bool haveNull =
false;
2759 bool forceFalse =
false;
2836 bool outtypisvarlena;
2855 &outfunc, &outtypisvarlena);
2857 &infunc, &intypioparam);
2901 return (
Node *) simple;
2915 return (
Node *) newexpr;
2920 Node *save_case_val;
3018 Node *save_case_val;
3021 bool const_true_cond;
3022 Node *defresult = NULL;
3041 const_true_cond =
false;
3057 if (casecond &&
IsA(casecond,
Const))
3065 const_true_cond =
true;
3073 if (!const_true_cond)
3077 newcasewhen->
expr = (
Expr *) casecond;
3080 newargs =
lappend(newargs, newcasewhen);
3089 defresult = caseresult;
3094 if (!const_true_cond)
3110 newcase->
arg = (
Expr *) newarg;
3111 newcase->
args = newargs;
3114 return (
Node *) newcase;
3163 foreach(
arg, coalesceexpr->
args)
3180 if (((
Const *)
e)->constisnull)
3202 newcoalesce->
args = newargs;
3204 return (
Node *) newcoalesce;
3257 ((
Var *)
arg)->varlevelsup == 0)
3269 ((
Var *)
arg)->varlevelsup);
3309 return (
Node *) newfselect;
3331 foreach(l, rarg->
args)
3357 newntest->
arg = (
Expr *) relem;
3361 newargs =
lappend(newargs, newntest);
3386 elog(
ERROR,
"unrecognized nulltesttype: %d",
3400 return (
Node *) newntest;
3447 elog(
ERROR,
"unrecognized booltesttype: %d",
3460 return (
Node *) newbtest;
3505 return (
Node *) newcdomain;
3568 return (
Node *) newcre;
3588 if (formatted &&
IsA(formatted,
Const))
3644 if (provolatile == PROVOLATILE_IMMUTABLE)
3646 if (context->
estimate && provolatile == PROVOLATILE_STABLE)
3673 bool *haveNull,
bool *forceTrue)
3676 List *unprocessed_args;
3690 while (unprocessed_args)
3700 List *oldlist = unprocessed_args;
3779 bool *haveNull,
bool *forceFalse)
3782 List *unprocessed_args;
3786 while (unprocessed_args)
3796 List *oldlist = unprocessed_args;
3882 if (opno == BooleanEqualOperator)
3897 if (rightop &&
IsA(rightop,
Const))
3900 if (opno == BooleanEqualOperator)
3941 Oid result_collid,
Oid input_collid,
List **args_p,
3942 bool funcvariadic,
bool process_args,
bool allow_non_const,
3964 elog(
ERROR,
"cache lookup failed for function %u", funcid);
3986 result_collid, input_collid,
3988 func_tuple, context);
3990 if (!newexpr && allow_non_const &&
OidIsValid(func_form->prosupport))
4025 if (!newexpr && allow_non_const)
4027 input_collid,
args, funcvariadic,
4028 func_tuple, context);
4060 Oid *proargtypes = funcform->proargtypes.values;
4062 bool has_named_args =
false;
4073 if (include_out_arguments)
4075 Datum proallargtypes;
4079 Anum_pg_proc_proallargtypes,
4090 elog(
ERROR,
"proallargtypes is not a 1-D Oid array or it contains nulls");
4103 has_named_args =
true;
4147 elog(
ERROR,
"too many function arguments");
4160 argarray[
i++] =
arg;
4180 i =
pronargs - funcform->pronargdefaults;
4181 foreach(lc, defaults)
4183 if (argarray[
i] == NULL)
4219 elog(
ERROR,
"not enough default arguments");
4234 Datum proargdefaults;
4240 Anum_pg_proc_proargdefaults,
4243 elog(
ERROR,
"not enough default arguments");
4278 elog(
ERROR,
"too many function arguments");
4285 memcpy(declared_arg_types, proargtypes,
pronargs *
sizeof(
Oid));
4289 funcform->prorettype,
4292 if (rettype != result_type)
4293 elog(
ERROR,
"function's resolved result type changed during planning");
4318 bool has_nonconst_input =
false;
4319 bool has_null_input =
false;
4326 if (funcform->proretset)
4340 if (funcform->prorettype == RECORDOID)
4351 has_nonconst_input =
true;
4360 if (funcform->proisstrict && has_null_input)
4369 if (has_nonconst_input)
4379 if (funcform->provolatile == PROVOLATILE_IMMUTABLE)
4381 else if (context->
estimate && funcform->provolatile == PROVOLATILE_STABLE)
4392 newexpr->
funcid = funcid;
4456 List *raw_parsetree_list;
4457 List *querytree_list;
4468 if (funcform->prolang != SQLlanguageId ||
4469 funcform->prokind != PROKIND_FUNCTION ||
4470 funcform->prosecdef ||
4471 funcform->proretset ||
4472 funcform->prorettype == RECORDOID ||
4517 Anum_pg_proc_prosrc,
4520 elog(
ERROR,
"null prosrc for function %u", funcid);
4528 callback_arg.
prosrc = src;
4531 sqlerrcontext.
arg = (
void *) &callback_arg;
4538 Anum_pg_proc_prosqlbody,
4543 List *querytree_list;
4633 result_type, rettupdesc,
4655 if (
exprType(newexpr) != result_type)
4666 if (funcform->provolatile == PROVOLATILE_IMMUTABLE &&
4669 else if (funcform->provolatile == PROVOLATILE_STABLE &&
4673 if (funcform->proisstrict &&
4690 usecounts = (
int *)
palloc0(funcform->pronargs *
sizeof(
int));
4700 if (usecounts[
i] == 0)
4703 if (funcform->proisstrict)
4706 else if (usecounts[
i] != 1)
4754 if (
OidIsValid(exprcoll) && exprcoll != result_collid)
4758 newnode->
arg = (
Expr *) newexpr;
4759 newnode->
collOid = result_collid;
4762 newexpr = (
Node *) newnode;
4783 return (
Expr *) newexpr;
4803 context.
nargs = nargs;
4843 int syntaxerrposition;
4847 if (syntaxerrposition > 0)
4865 Oid result_collation)
4873 bool resultTypByVal;
4920 if (resultTypLen == -1)
4923 const_val =
datumCopy(const_val, resultTypByVal, resultTypLen);
4932 return (
Expr *)
makeConst(result_type, result_typmod, result_collation,
4934 const_val, const_is_null,
4973 List *raw_parsetree_list;
4974 List *querytree_list;
5000 func_oid = fexpr->
funcid;
5036 elog(
ERROR,
"cache lookup failed for function %u", func_oid);
5049 if (funcform->prolang != SQLlanguageId ||
5050 funcform->prokind != PROKIND_FUNCTION ||
5051 funcform->proisstrict ||
5052 funcform->provolatile == PROVOLATILE_VOLATILE ||
5053 funcform->prorettype == VOIDOID ||
5054 funcform->prosecdef ||
5055 !funcform->proretset ||
5068 "inline_set_returning_function",
5075 Anum_pg_proc_prosrc,
5078 elog(
ERROR,
"null prosrc for function %u", func_oid);
5086 callback_arg.
prosrc = src;
5089 sqlerrcontext.
arg = (
void *) &callback_arg;
5096 Anum_pg_proc_prosqlbody,
5127 fexpr->inputcollid);
5246 context.
nargs = nargs;
Datum querytree(PG_FUNCTION_ARGS)
AclResult pg_proc_aclcheck(Oid proc_oid, Oid roleid, AclMode mode)
#define DatumGetArrayTypeP(X)
int ArrayGetNItems(int ndim, const int *dims)
#define InvalidAttrNumber
Bitmapset * bms_join(Bitmapset *a, Bitmapset *b)
void bms_free(Bitmapset *a)
int bms_num_members(const Bitmapset *a)
Bitmapset * bms_make_singleton(int x)
Bitmapset * bms_add_member(Bitmapset *a, int x)
Bitmapset * bms_add_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_int_members(Bitmapset *a, const Bitmapset *b)
bool bms_is_empty(const Bitmapset *a)
BMS_Membership bms_membership(const Bitmapset *a)
#define TextDatumGetCString(d)
#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)
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)
WindowFuncLists * find_window_functions(Node *clause, Index maxWinRef)
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)
Expr * evaluate_expr(Expr *expr, Oid result_type, int32 result_typmod, Oid result_collation)
#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 Node * substitute_actual_srf_parameters_mutator(Node *node, substitute_actual_srf_parameters_context *context)
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)
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)
bool is_pseudo_constant_clause_relids(Node *clause, Relids relids)
List * expand_function_arguments(List *args, bool include_out_arguments, Oid result_type, HeapTuple func_tuple)
static Query * substitute_actual_srf_parameters(Query *expr, int nargs, List *args)
Var * find_forced_null_var(Node *node)
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)
List * find_forced_null_vars(Node *node)
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)
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 * substitute_actual_parameters(Node *expr, int nargs, List *args, int *usecounts)
static bool contain_mutable_functions_walker(Node *node, void *context)
Query * inline_set_returning_function(PlannerInfo *root, RangeTblEntry *rte)
static bool contain_volatile_functions_walker(Node *node, void *context)
bool contain_leaked_vars(Node *clause)
static Relids find_nonnullable_rels_walker(Node *node, bool top_level)
Bitmapset * pull_paramids(Expr *expr)
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 * find_nonnullable_vars(Node *clause)
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)
Node * eval_const_expressions(PlannerInfo *root, Node *node)
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)
void CommuteOpExpr(OpExpr *clause)
static Node * eval_const_expressions_mutator(Node *node, eval_const_expressions_context *context)
static bool pull_paramids_walker(Node *node, Bitmapset **context)
static bool convert_saop_to_hashed_saop_walker(Node *node, void *context)
static List * fetch_function_defaults(HeapTuple func_tuple)
bool contain_volatile_functions(Node *clause)
double expression_returns_set_rows(PlannerInfo *root, Node *clause)
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
Node * estimate_expression_value(PlannerInfo *root, Node *node)
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
double clamp_row_est(double nrows)
Datum datumCopy(Datum value, bool typByVal, int typLen)
static void PGresult * res
int internalerrquery(const char *query)
int internalerrposition(int cursorpos)
ErrorContextCallback * error_context_stack
int errposition(int cursorpos)
bool ExecEvalJsonNeedsSubTransaction(JsonExpr *jsexpr, struct JsonCoercionsState *coercions)
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
EState * CreateExecutorState(void)
void FreeExecutorState(EState *estate)
#define GetPerTupleExprContext(estate)
static Datum ExecEvalExprSwitchContext(ExprState *state, ExprContext *econtext, bool *isNull)
#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, bool insertDroppedCols, List **resultTargetList)
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)
bool to_json_is_immutable(Oid typoid)
bool to_jsonb_is_immutable(Oid typoid)
bool jspIsMutable(JsonPath *path, List *varnames, List *varexprs)
#define DatumGetJsonPathP(d)
Assert(fmt[strlen(fmt) - 1] !='\n')
List * list_delete_first_n(List *list, int n)