PostgreSQL Source Code  git master
clauses.h File Reference
#include "nodes/relation.h"
Include dependency graph for clauses.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  WindowFuncLists
 

Macros

#define is_opclause(clause)   ((clause) != NULL && IsA(clause, OpExpr))
 
#define is_funcclause(clause)   ((clause) != NULL && IsA(clause, FuncExpr))
 

Functions

Exprmake_opclause (Oid opno, Oid opresulttype, bool opretset, Expr *leftop, Expr *rightop, Oid opcollid, Oid inputcollid)
 
Nodeget_leftop (const Expr *clause)
 
Nodeget_rightop (const Expr *clause)
 
bool not_clause (Node *clause)
 
Exprmake_notclause (Expr *notclause)
 
Exprget_notclausearg (Expr *notclause)
 
bool or_clause (Node *clause)
 
Exprmake_orclause (List *orclauses)
 
bool and_clause (Node *clause)
 
Exprmake_andclause (List *andclauses)
 
Nodemake_and_qual (Node *qual1, Node *qual2)
 
Exprmake_ands_explicit (List *andclauses)
 
Listmake_ands_implicit (Expr *clause)
 
bool contain_agg_clause (Node *clause)
 
void get_agg_clause_costs (PlannerInfo *root, Node *clause, AggSplit aggsplit, AggClauseCosts *costs)
 
bool contain_window_function (Node *clause)
 
WindowFuncListsfind_window_functions (Node *clause, Index maxWinRef)
 
double expression_returns_set_rows (Node *clause)
 
bool contain_subplans (Node *clause)
 
bool contain_mutable_functions (Node *clause)
 
bool contain_volatile_functions (Node *clause)
 
bool contain_volatile_functions_not_nextval (Node *clause)
 
char max_parallel_hazard (Query *parse)
 
bool is_parallel_safe (PlannerInfo *root, Node *node)
 
bool contain_nonstrict_functions (Node *clause)
 
bool contain_leaked_vars (Node *clause)
 
Relids find_nonnullable_rels (Node *clause)
 
Listfind_nonnullable_vars (Node *clause)
 
Listfind_forced_null_vars (Node *clause)
 
Varfind_forced_null_var (Node *clause)
 
bool is_pseudo_constant_clause (Node *clause)
 
bool is_pseudo_constant_clause_relids (Node *clause, Relids relids)
 
int NumRelids (Node *clause)
 
void CommuteOpExpr (OpExpr *clause)
 
void CommuteRowCompareExpr (RowCompareExpr *clause)
 
Nodeeval_const_expressions (PlannerInfo *root, Node *node)
 
Nodeestimate_expression_value (PlannerInfo *root, Node *node)
 
Queryinline_set_returning_function (PlannerInfo *root, RangeTblEntry *rte)
 

Macro Definition Documentation

◆ is_funcclause

#define is_funcclause (   clause)    ((clause) != NULL && IsA(clause, FuncExpr))

◆ is_opclause

Function Documentation

◆ and_clause()

bool and_clause ( Node clause)

◆ CommuteOpExpr()

void CommuteOpExpr ( OpExpr clause)

Definition at line 2287 of file clauses.c.

References OpExpr::args, elog, ERROR, get_commutator(), InvalidOid, is_opclause, linitial, list_length(), lsecond, OidIsValid, OpExpr::opfuncid, and OpExpr::opno.

Referenced by fix_indexqual_references(), and get_switched_clauses().

2288 {
2289  Oid opoid;
2290  Node *temp;
2291 
2292  /* Sanity checks: caller is at fault if these fail */
2293  if (!is_opclause(clause) ||
2294  list_length(clause->args) != 2)
2295  elog(ERROR, "cannot commute non-binary-operator clause");
2296 
2297  opoid = get_commutator(clause->opno);
2298 
2299  if (!OidIsValid(opoid))
2300  elog(ERROR, "could not find commutator for operator %u",
2301  clause->opno);
2302 
2303  /*
2304  * modify the clause in-place!
2305  */
2306  clause->opno = opoid;
2307  clause->opfuncid = InvalidOid;
2308  /* opresulttype, opretset, opcollid, inputcollid need not change */
2309 
2310  temp = linitial(clause->args);
2311  linitial(clause->args) = lsecond(clause->args);
2312  lsecond(clause->args) = temp;
2313 }
Oid get_commutator(Oid opno)
Definition: lsyscache.c:1313
Definition: nodes.h:512
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:586
#define lsecond(l)
Definition: pg_list.h:116
#define linitial(l)
Definition: pg_list.h:111
#define ERROR
Definition: elog.h:43
#define is_opclause(clause)
Definition: clauses.h:20
Oid opfuncid
Definition: primnodes.h:497
#define InvalidOid
Definition: postgres_ext.h:36
static int list_length(const List *l)
Definition: pg_list.h:89
Oid opno
Definition: primnodes.h:496
#define elog
Definition: elog.h:219
List * args
Definition: primnodes.h:502

◆ CommuteRowCompareExpr()

void CommuteRowCompareExpr ( RowCompareExpr clause)

Definition at line 2321 of file clauses.c.

References elog, ERROR, get_commutator(), IsA, lappend_oid(), RowCompareExpr::largs, lfirst_oid, NIL, OidIsValid, RowCompareExpr::opnos, RowCompareExpr::rargs, RowCompareExpr::rctype, ROWCOMPARE_GE, ROWCOMPARE_GT, ROWCOMPARE_LE, and ROWCOMPARE_LT.

Referenced by fix_indexqual_references().

2322 {
2323  List *newops;
2324  List *temp;
2325  ListCell *l;
2326 
2327  /* Sanity checks: caller is at fault if these fail */
2328  if (!IsA(clause, RowCompareExpr))
2329  elog(ERROR, "expected a RowCompareExpr");
2330 
2331  /* Build list of commuted operators */
2332  newops = NIL;
2333  foreach(l, clause->opnos)
2334  {
2335  Oid opoid = lfirst_oid(l);
2336 
2337  opoid = get_commutator(opoid);
2338  if (!OidIsValid(opoid))
2339  elog(ERROR, "could not find commutator for operator %u",
2340  lfirst_oid(l));
2341  newops = lappend_oid(newops, opoid);
2342  }
2343 
2344  /*
2345  * modify the clause in-place!
2346  */
2347  switch (clause->rctype)
2348  {
2349  case ROWCOMPARE_LT:
2350  clause->rctype = ROWCOMPARE_GT;
2351  break;
2352  case ROWCOMPARE_LE:
2353  clause->rctype = ROWCOMPARE_GE;
2354  break;
2355  case ROWCOMPARE_GE:
2356  clause->rctype = ROWCOMPARE_LE;
2357  break;
2358  case ROWCOMPARE_GT:
2359  clause->rctype = ROWCOMPARE_LT;
2360  break;
2361  default:
2362  elog(ERROR, "unexpected RowCompare type: %d",
2363  (int) clause->rctype);
2364  break;
2365  }
2366 
2367  clause->opnos = newops;
2368 
2369  /*
2370  * Note: we need not change the opfamilies list; we assume any btree
2371  * opfamily containing an operator will also contain its commutator.
2372  * Collations don't change either.
2373  */
2374 
2375  temp = clause->largs;
2376  clause->largs = clause->rargs;
2377  clause->rargs = temp;
2378 }
#define NIL
Definition: pg_list.h:69
#define IsA(nodeptr, _type_)
Definition: nodes.h:563
Oid get_commutator(Oid opno)
Definition: lsyscache.c:1313
RowCompareType rctype
Definition: primnodes.h:1038
unsigned int Oid
Definition: postgres_ext.h:31
List * lappend_oid(List *list, Oid datum)
Definition: list.c:164
#define OidIsValid(objectId)
Definition: c.h:586
#define ERROR
Definition: elog.h:43
#define elog
Definition: elog.h:219
Definition: pg_list.h:45
#define lfirst_oid(lc)
Definition: pg_list.h:108

◆ contain_agg_clause()

bool contain_agg_clause ( Node clause)

Definition at line 417 of file clauses.c.

References contain_agg_clause_walker().

Referenced by get_eclass_for_sort_expr(), and subquery_planner().

418 {
419  return contain_agg_clause_walker(clause, NULL);
420 }
static bool contain_agg_clause_walker(Node *node, void *context)
Definition: clauses.c:423

◆ contain_leaked_vars()

bool contain_leaked_vars ( Node clause)

Definition at line 1515 of file clauses.c.

References contain_leaked_vars_walker().

Referenced by make_restrictinfo_internal(), and qual_is_pushdown_safe().

1516 {
1517  return contain_leaked_vars_walker(clause, NULL);
1518 }
static bool contain_leaked_vars_walker(Node *node, void *context)
Definition: clauses.c:1527

◆ contain_mutable_functions()

bool contain_mutable_functions ( Node clause)

◆ contain_nonstrict_functions()

bool contain_nonstrict_functions ( Node clause)

Definition at line 1314 of file clauses.c.

References contain_nonstrict_functions_walker().

Referenced by inline_function(), process_equivalence(), and pullup_replace_vars_callback().

1315 {
1316  return contain_nonstrict_functions_walker(clause, NULL);
1317 }
static bool contain_nonstrict_functions_walker(Node *node, void *context)
Definition: clauses.c:1326

◆ contain_subplans()

bool contain_subplans ( Node clause)

Definition at line 843 of file clauses.c.

References contain_subplans_walker().

Referenced by convert_EXISTS_to_ANY(), inline_function(), inline_set_returning_function(), qual_is_pushdown_safe(), and subquery_planner().

844 {
845  return contain_subplans_walker(clause, NULL);
846 }
static bool contain_subplans_walker(Node *node, void *context)
Definition: clauses.c:849

◆ contain_volatile_functions()

◆ contain_volatile_functions_not_nextval()

bool contain_volatile_functions_not_nextval ( Node clause)

Definition at line 1007 of file clauses.c.

References contain_volatile_functions_not_nextval_walker().

Referenced by BeginCopyFrom().

1008 {
1009  return contain_volatile_functions_not_nextval_walker(clause, NULL);
1010 }
static bool contain_volatile_functions_not_nextval_walker(Node *node, void *context)
Definition: clauses.c:1020

◆ contain_window_function()

bool contain_window_function ( Node clause)

Definition at line 727 of file clauses.c.

References contain_windowfuncs().

Referenced by get_eclass_for_sort_expr(), and qual_is_pushdown_safe().

728 {
729  return contain_windowfuncs(clause);
730 }
bool contain_windowfuncs(Node *node)
Definition: rewriteManip.c:197

◆ estimate_expression_value()

Node* estimate_expression_value ( PlannerInfo root,
Node node 
)

Definition at line 2492 of file clauses.c.

References eval_const_expressions_context::active_fns, eval_const_expressions_context::boundParams, PlannerGlobal::boundParams, eval_const_expressions_context::case_val, eval_const_expressions_context::estimate, eval_const_expressions_mutator(), PlannerInfo::glob, NIL, and eval_const_expressions_context::root.

Referenced by bernoulli_samplescangetsamplesize(), clause_selectivity(), get_restriction_variable(), gincost_opexpr(), gincost_scalararrayopexpr(), preprocess_limit(), scalararraysel(), system_rows_samplescangetsamplesize(), system_samplescangetsamplesize(), and system_time_samplescangetsamplesize().

2493 {
2495 
2496  context.boundParams = root->glob->boundParams; /* bound Params */
2497  /* we do not need to mark the plan as depending on inlined functions */
2498  context.root = NULL;
2499  context.active_fns = NIL; /* nothing being recursively simplified */
2500  context.case_val = NULL; /* no CASE being examined */
2501  context.estimate = true; /* unsafe transformations OK */
2502  return eval_const_expressions_mutator(node, &context);
2503 }
#define NIL
Definition: pg_list.h:69
static Node * eval_const_expressions_mutator(Node *node, eval_const_expressions_context *context)
Definition: clauses.c:2506
ParamListInfo boundParams
Definition: clauses.c:65
PlannerGlobal * glob
Definition: relation.h:157
ParamListInfo boundParams
Definition: relation.h:96

◆ eval_const_expressions()

Node* eval_const_expressions ( PlannerInfo root,
Node node 
)

Definition at line 2459 of file clauses.c.

References eval_const_expressions_context::active_fns, eval_const_expressions_context::boundParams, PlannerGlobal::boundParams, eval_const_expressions_context::case_val, eval_const_expressions_context::estimate, eval_const_expressions_mutator(), PlannerInfo::glob, NIL, and eval_const_expressions_context::root.

Referenced by ATExecAttachPartition(), convert_EXISTS_to_ANY(), expression_planner(), get_proposed_default_constraint(), get_relation_constraints(), inline_set_returning_function(), PartConstraintImpliedByRelConstraint(), preprocess_expression(), process_implied_equality(), RelationBuildPartitionKey(), RelationGetIndexExpressions(), RelationGetIndexPredicate(), set_append_rel_size(), and simplify_EXISTS_query().

2460 {
2462 
2463  if (root)
2464  context.boundParams = root->glob->boundParams; /* bound Params */
2465  else
2466  context.boundParams = NULL;
2467  context.root = root; /* for inlined-function dependencies */
2468  context.active_fns = NIL; /* nothing being recursively simplified */
2469  context.case_val = NULL; /* no CASE being examined */
2470  context.estimate = false; /* safe transformations only */
2471  return eval_const_expressions_mutator(node, &context);
2472 }
#define NIL
Definition: pg_list.h:69
static Node * eval_const_expressions_mutator(Node *node, eval_const_expressions_context *context)
Definition: clauses.c:2506
ParamListInfo boundParams
Definition: clauses.c:65
PlannerGlobal * glob
Definition: relation.h:157
ParamListInfo boundParams
Definition: relation.h:96

◆ expression_returns_set_rows()

double expression_returns_set_rows ( Node clause)

Definition at line 802 of file clauses.c.

References clamp_row_est(), FuncExpr::funcid, FuncExpr::funcretset, get_func_rows(), IsA, OpExpr::opfuncid, OpExpr::opretset, and set_opfuncid().

Referenced by create_set_projection_path(), estimate_num_groups(), and set_function_size_estimates().

803 {
804  if (clause == NULL)
805  return 1.0;
806  if (IsA(clause, FuncExpr))
807  {
808  FuncExpr *expr = (FuncExpr *) clause;
809 
810  if (expr->funcretset)
811  return clamp_row_est(get_func_rows(expr->funcid));
812  }
813  if (IsA(clause, OpExpr))
814  {
815  OpExpr *expr = (OpExpr *) clause;
816 
817  if (expr->opretset)
818  {
819  set_opfuncid(expr);
820  return clamp_row_est(get_func_rows(expr->opfuncid));
821  }
822  }
823  return 1.0;
824 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:563
float4 get_func_rows(Oid funcid)
Definition: lsyscache.c:1679
bool funcretset
Definition: primnodes.h:451
Oid funcid
Definition: primnodes.h:449
Oid opfuncid
Definition: primnodes.h:497
void set_opfuncid(OpExpr *opexpr)
Definition: nodeFuncs.c:1613
double clamp_row_est(double nrows)
Definition: costsize.c:177
bool opretset
Definition: primnodes.h:499

◆ find_forced_null_var()

Var* find_forced_null_var ( Node clause)

Definition at line 2120 of file clauses.c.

References NullTest::arg, BooleanTest::arg, NullTest::argisrow, BooleanTest::booltesttype, IS_NULL, IS_UNKNOWN, IsA, NullTest::nulltesttype, and Var::varlevelsup.

Referenced by check_redundant_nullability_qual(), and find_forced_null_vars().

2121 {
2122  if (node == NULL)
2123  return NULL;
2124  if (IsA(node, NullTest))
2125  {
2126  /* check for var IS NULL */
2127  NullTest *expr = (NullTest *) node;
2128 
2129  if (expr->nulltesttype == IS_NULL && !expr->argisrow)
2130  {
2131  Var *var = (Var *) expr->arg;
2132 
2133  if (var && IsA(var, Var) &&
2134  var->varlevelsup == 0)
2135  return var;
2136  }
2137  }
2138  else if (IsA(node, BooleanTest))
2139  {
2140  /* var IS UNKNOWN is equivalent to var IS NULL */
2141  BooleanTest *expr = (BooleanTest *) node;
2142 
2143  if (expr->booltesttype == IS_UNKNOWN)
2144  {
2145  Var *var = (Var *) expr->arg;
2146 
2147  if (var && IsA(var, Var) &&
2148  var->varlevelsup == 0)
2149  return var;
2150  }
2151  }
2152  return NULL;
2153 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:563
Index varlevelsup
Definition: primnodes.h:173
Definition: primnodes.h:163
Expr * arg
Definition: primnodes.h:1187
Expr * arg
Definition: primnodes.h:1210
BoolTestType booltesttype
Definition: primnodes.h:1211
NullTestType nulltesttype
Definition: primnodes.h:1188
bool argisrow
Definition: primnodes.h:1189

◆ find_forced_null_vars()

List* find_forced_null_vars ( Node clause)

Definition at line 2061 of file clauses.c.

References AND_EXPR, BoolExpr::args, BoolExpr::boolop, find_forced_null_var(), find_forced_null_vars(), IsA, lfirst, list_concat(), list_make1, and NIL.

Referenced by find_forced_null_vars(), and reduce_outer_joins_pass2().

2062 {
2063  List *result = NIL;
2064  Var *var;
2065  ListCell *l;
2066 
2067  if (node == NULL)
2068  return NIL;
2069  /* Check single-clause cases using subroutine */
2070  var = find_forced_null_var(node);
2071  if (var)
2072  {
2073  result = list_make1(var);
2074  }
2075  /* Otherwise, handle AND-conditions */
2076  else if (IsA(node, List))
2077  {
2078  /*
2079  * At top level, we are examining an implicit-AND list: if any of the
2080  * arms produces FALSE-or-NULL then the result is FALSE-or-NULL.
2081  */
2082  foreach(l, (List *) node)
2083  {
2084  result = list_concat(result,
2086  }
2087  }
2088  else if (IsA(node, BoolExpr))
2089  {
2090  BoolExpr *expr = (BoolExpr *) node;
2091 
2092  /*
2093  * We don't bother considering the OR case, because it's fairly
2094  * unlikely anyone would write "v1 IS NULL OR v1 IS NULL". Likewise,
2095  * the NOT case isn't worth expending code on.
2096  */
2097  if (expr->boolop == AND_EXPR)
2098  {
2099  /* At top level we can just recurse (to the List case) */
2100  result = find_forced_null_vars((Node *) expr->args);
2101  }
2102  }
2103  return result;
2104 }
#define NIL
Definition: pg_list.h:69
#define IsA(nodeptr, _type_)
Definition: nodes.h:563
Definition: nodes.h:512
List * list_concat(List *list1, List *list2)
Definition: list.c:321
Definition: primnodes.h:163
List * find_forced_null_vars(Node *node)
Definition: clauses.c:2061
#define list_make1(x1)
Definition: pg_list.h:139
BoolExprType boolop
Definition: primnodes.h:562
#define lfirst(lc)
Definition: pg_list.h:106
List * args
Definition: primnodes.h:563
Definition: pg_list.h:45
Var * find_forced_null_var(Node *node)
Definition: clauses.c:2120

◆ find_nonnullable_rels()

Relids find_nonnullable_rels ( Node clause)

Definition at line 1660 of file clauses.c.

References find_nonnullable_rels_walker().

Referenced by make_outerjoininfo(), and reduce_outer_joins_pass2().

1661 {
1662  return find_nonnullable_rels_walker(clause, true);
1663 }
static Relids find_nonnullable_rels_walker(Node *node, bool top_level)
Definition: clauses.c:1666

◆ find_nonnullable_vars()

List* find_nonnullable_vars ( Node clause)

Definition at line 1868 of file clauses.c.

References find_nonnullable_vars_walker().

Referenced by reduce_outer_joins_pass2().

1869 {
1870  return find_nonnullable_vars_walker(clause, true);
1871 }
static List * find_nonnullable_vars_walker(Node *node, bool top_level)
Definition: clauses.c:1874

◆ find_window_functions()

WindowFuncLists* find_window_functions ( Node clause,
Index  maxWinRef 
)

Definition at line 740 of file clauses.c.

References find_window_functions_walker(), WindowFuncLists::maxWinRef, WindowFuncLists::numWindowFuncs, palloc(), palloc0(), and WindowFuncLists::windowFuncs.

Referenced by grouping_planner().

741 {
742  WindowFuncLists *lists = palloc(sizeof(WindowFuncLists));
743 
744  lists->numWindowFuncs = 0;
745  lists->maxWinRef = maxWinRef;
746  lists->windowFuncs = (List **) palloc0((maxWinRef + 1) * sizeof(List *));
747  (void) find_window_functions_walker(clause, lists);
748  return lists;
749 }
Index maxWinRef
Definition: clauses.h:26
int numWindowFuncs
Definition: clauses.h:25
void * palloc0(Size size)
Definition: mcxt.c:864
void * palloc(Size size)
Definition: mcxt.c:835
static bool find_window_functions_walker(Node *node, WindowFuncLists *lists)
Definition: clauses.c:752
Definition: pg_list.h:45
List ** windowFuncs
Definition: clauses.h:27

◆ get_agg_clause_costs()

void get_agg_clause_costs ( PlannerInfo root,
Node clause,
AggSplit  aggsplit,
AggClauseCosts costs 
)

Definition at line 467 of file clauses.c.

References get_agg_clause_costs_context::aggsplit, get_agg_clause_costs_context::costs, get_agg_clause_costs_walker(), and get_agg_clause_costs_context::root.

Referenced by create_grouping_paths(), estimate_path_cost_size(), and grouping_planner().

469 {
471 
472  context.root = root;
473  context.aggsplit = aggsplit;
474  context.costs = costs;
475  (void) get_agg_clause_costs_walker(clause, &context);
476 }
AggClauseCosts * costs
Definition: clauses.c:60
static bool get_agg_clause_costs_walker(Node *node, get_agg_clause_costs_context *context)
Definition: clauses.c:479

◆ get_leftop()

◆ get_notclausearg()

Expr* get_notclausearg ( Expr notclause)

◆ get_rightop()

◆ inline_set_returning_function()

Query* inline_set_returning_function ( PlannerInfo root,
RangeTblEntry rte 
)

Definition at line 4837 of file clauses.c.

References ACL_EXECUTE, ACLCHECK_OK, ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Anum_pg_proc_proconfig, Anum_pg_proc_prosrc, ErrorContextCallback::arg, FuncExpr::args, Assert, ErrorContextCallback::callback, check_sql_fn_retval(), check_stack_depth(), CMD_SELECT, Query::commandType, contain_subplans(), contain_volatile_functions(), copyObject, CurrentMemoryContext, elog, ERROR, error_context_stack, eval_const_expressions(), FmgrHookIsNeeded, RangeTblFunction::funccoltypes, RangeTblFunction::funcexpr, FuncExpr::funcid, RangeTblEntry::funcordinality, FuncExpr::funcretset, RangeTblEntry::functions, get_func_result_type(), get_typtype(), GETSTRUCT, GetUserId(), PlannerInfo::glob, heap_attisnull(), HeapTupleIsValid, PlannerGlobal::invalItems, IsA, linitial, list_concat(), list_length(), MemoryContextDelete(), MemoryContextSwitchTo(), NameStr, NIL, ObjectIdGetDatum, pg_analyze_and_rewrite_params(), pg_parse_query(), pg_proc_aclcheck(), prepare_sql_fn_parse_info(), ErrorContextCallback::previous, PROCOID, inline_error_callback_arg::proname, inline_error_callback_arg::prosrc, PROVOLATILE_VOLATILE, querytree(), record_plan_function_dependency(), RECORDOID, ReleaseSysCache(), RTE_FUNCTION, RangeTblEntry::rtekind, SearchSysCache1(), sql_fn_parser_setup(), sql_inline_error_callback(), SQLlanguageId, substitute_actual_srf_parameters(), SysCacheGetAttr(), Query::targetList, TextDatumGetCString, tlist_matches_coltypelist(), TYPEFUNC_RECORD, and TYPTYPE_COMPOSITE.

Referenced by inline_set_returning_functions().

4838 {
4839  RangeTblFunction *rtfunc;
4840  FuncExpr *fexpr;
4841  Oid func_oid;
4842  HeapTuple func_tuple;
4843  Form_pg_proc funcform;
4844  char *src;
4845  Datum tmp;
4846  bool isNull;
4847  bool modifyTargetList;
4848  MemoryContext oldcxt;
4849  MemoryContext mycxt;
4850  List *saveInvalItems;
4851  inline_error_callback_arg callback_arg;
4852  ErrorContextCallback sqlerrcontext;
4854  List *raw_parsetree_list;
4855  List *querytree_list;
4856  Query *querytree;
4857 
4858  Assert(rte->rtekind == RTE_FUNCTION);
4859 
4860  /*
4861  * It doesn't make a lot of sense for a SQL SRF to refer to itself in its
4862  * own FROM clause, since that must cause infinite recursion at runtime.
4863  * It will cause this code to recurse too, so check for stack overflow.
4864  * (There's no need to do more.)
4865  */
4867 
4868  /* Fail if the RTE has ORDINALITY - we don't implement that here. */
4869  if (rte->funcordinality)
4870  return NULL;
4871 
4872  /* Fail if RTE isn't a single, simple FuncExpr */
4873  if (list_length(rte->functions) != 1)
4874  return NULL;
4875  rtfunc = (RangeTblFunction *) linitial(rte->functions);
4876 
4877  if (!IsA(rtfunc->funcexpr, FuncExpr))
4878  return NULL;
4879  fexpr = (FuncExpr *) rtfunc->funcexpr;
4880 
4881  func_oid = fexpr->funcid;
4882 
4883  /*
4884  * The function must be declared to return a set, else inlining would
4885  * change the results if the contained SELECT didn't return exactly one
4886  * row.
4887  */
4888  if (!fexpr->funcretset)
4889  return NULL;
4890 
4891  /*
4892  * Refuse to inline if the arguments contain any volatile functions or
4893  * sub-selects. Volatile functions are rejected because inlining may
4894  * result in the arguments being evaluated multiple times, risking a
4895  * change in behavior. Sub-selects are rejected partly for implementation
4896  * reasons (pushing them down another level might change their behavior)
4897  * and partly because they're likely to be expensive and so multiple
4898  * evaluation would be bad.
4899  */
4900  if (contain_volatile_functions((Node *) fexpr->args) ||
4901  contain_subplans((Node *) fexpr->args))
4902  return NULL;
4903 
4904  /* Check permission to call function (fail later, if not) */
4905  if (pg_proc_aclcheck(func_oid, GetUserId(), ACL_EXECUTE) != ACLCHECK_OK)
4906  return NULL;
4907 
4908  /* Check whether a plugin wants to hook function entry/exit */
4909  if (FmgrHookIsNeeded(func_oid))
4910  return NULL;
4911 
4912  /*
4913  * OK, let's take a look at the function's pg_proc entry.
4914  */
4915  func_tuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(func_oid));
4916  if (!HeapTupleIsValid(func_tuple))
4917  elog(ERROR, "cache lookup failed for function %u", func_oid);
4918  funcform = (Form_pg_proc) GETSTRUCT(func_tuple);
4919 
4920  /*
4921  * Forget it if the function is not SQL-language or has other showstopper
4922  * properties. In particular it mustn't be declared STRICT, since we
4923  * couldn't enforce that. It also mustn't be VOLATILE, because that is
4924  * supposed to cause it to be executed with its own snapshot, rather than
4925  * sharing the snapshot of the calling query. (Rechecking proretset is
4926  * just paranoia.)
4927  */
4928  if (funcform->prolang != SQLlanguageId ||
4929  funcform->proisstrict ||
4930  funcform->provolatile == PROVOLATILE_VOLATILE ||
4931  funcform->prosecdef ||
4932  !funcform->proretset ||
4933  !heap_attisnull(func_tuple, Anum_pg_proc_proconfig))
4934  {
4935  ReleaseSysCache(func_tuple);
4936  return NULL;
4937  }
4938 
4939  /*
4940  * Make a temporary memory context, so that we don't leak all the stuff
4941  * that parsing might create.
4942  */
4944  "inline_set_returning_function",
4946  oldcxt = MemoryContextSwitchTo(mycxt);
4947 
4948  /*
4949  * When we call eval_const_expressions below, it might try to add items to
4950  * root->glob->invalItems. Since it is running in the temp context, those
4951  * items will be in that context, and will need to be copied out if we're
4952  * successful. Temporarily reset the list so that we can keep those items
4953  * separate from the pre-existing list contents.
4954  */
4955  saveInvalItems = root->glob->invalItems;
4956  root->glob->invalItems = NIL;
4957 
4958  /* Fetch the function body */
4959  tmp = SysCacheGetAttr(PROCOID,
4960  func_tuple,
4962  &isNull);
4963  if (isNull)
4964  elog(ERROR, "null prosrc for function %u", func_oid);
4965  src = TextDatumGetCString(tmp);
4966 
4967  /*
4968  * Setup error traceback support for ereport(). This is so that we can
4969  * finger the function that bad information came from.
4970  */
4971  callback_arg.proname = NameStr(funcform->proname);
4972  callback_arg.prosrc = src;
4973 
4974  sqlerrcontext.callback = sql_inline_error_callback;
4975  sqlerrcontext.arg = (void *) &callback_arg;
4976  sqlerrcontext.previous = error_context_stack;
4977  error_context_stack = &sqlerrcontext;
4978 
4979  /*
4980  * Run eval_const_expressions on the function call. This is necessary to
4981  * ensure that named-argument notation is converted to positional notation
4982  * and any default arguments are inserted. It's a bit of overkill for the
4983  * arguments, since they'll get processed again later, but no harm will be
4984  * done.
4985  */
4986  fexpr = (FuncExpr *) eval_const_expressions(root, (Node *) fexpr);
4987 
4988  /* It should still be a call of the same function, but let's check */
4989  if (!IsA(fexpr, FuncExpr) ||
4990  fexpr->funcid != func_oid)
4991  goto fail;
4992 
4993  /* Arg list length should now match the function */
4994  if (list_length(fexpr->args) != funcform->pronargs)
4995  goto fail;
4996 
4997  /*
4998  * Set up to handle parameters while parsing the function body. We can
4999  * use the FuncExpr just created as the input for
5000  * prepare_sql_fn_parse_info.
5001  */
5002  pinfo = prepare_sql_fn_parse_info(func_tuple,
5003  (Node *) fexpr,
5004  fexpr->inputcollid);
5005 
5006  /*
5007  * Parse, analyze, and rewrite (unlike inline_function(), we can't skip
5008  * rewriting here). We can fail as soon as we find more than one query,
5009  * though.
5010  */
5011  raw_parsetree_list = pg_parse_query(src);
5012  if (list_length(raw_parsetree_list) != 1)
5013  goto fail;
5014 
5015  querytree_list = pg_analyze_and_rewrite_params(linitial(raw_parsetree_list),
5016  src,
5018  pinfo, NULL);
5019  if (list_length(querytree_list) != 1)
5020  goto fail;
5021  querytree = linitial(querytree_list);
5022 
5023  /*
5024  * The single command must be a plain SELECT.
5025  */
5026  if (!IsA(querytree, Query) ||
5027  querytree->commandType != CMD_SELECT)
5028  goto fail;
5029 
5030  /*
5031  * Make sure the function (still) returns what it's declared to. This
5032  * will raise an error if wrong, but that's okay since the function would
5033  * fail at runtime anyway. Note that check_sql_fn_retval will also insert
5034  * RelabelType(s) and/or NULL columns if needed to make the tlist
5035  * expression(s) match the declared type of the function.
5036  *
5037  * If the function returns a composite type, don't inline unless the check
5038  * shows it's returning a whole tuple result; otherwise what it's
5039  * returning is a single composite column which is not what we need. (Like
5040  * check_sql_fn_retval, we deliberately exclude domains over composite
5041  * here.)
5042  */
5043  if (!check_sql_fn_retval(func_oid, fexpr->funcresulttype,
5044  querytree_list,
5045  &modifyTargetList, NULL) &&
5047  fexpr->funcresulttype == RECORDOID))
5048  goto fail; /* reject not-whole-tuple-result cases */
5049 
5050  /*
5051  * If we had to modify the tlist to make it match, and the statement is
5052  * one in which changing the tlist contents could change semantics, we
5053  * have to punt and not inline.
5054  */
5055  if (modifyTargetList)
5056  goto fail;
5057 
5058  /*
5059  * If it returns RECORD, we have to check against the column type list
5060  * provided in the RTE; check_sql_fn_retval can't do that. (If no match,
5061  * we just fail to inline, rather than complaining; see notes for
5062  * tlist_matches_coltypelist.) We don't have to do this for functions
5063  * with declared OUT parameters, even though their funcresulttype is
5064  * RECORDOID, so check get_func_result_type too.
5065  */
5066  if (fexpr->funcresulttype == RECORDOID &&
5067  get_func_result_type(func_oid, NULL, NULL) == TYPEFUNC_RECORD &&
5069  rtfunc->funccoltypes))
5070  goto fail;
5071 
5072  /*
5073  * Looks good --- substitute parameters into the query.
5074  */
5075  querytree = substitute_actual_srf_parameters(querytree,
5076  funcform->pronargs,
5077  fexpr->args);
5078 
5079  /*
5080  * Copy the modified query out of the temporary memory context, and clean
5081  * up.
5082  */
5083  MemoryContextSwitchTo(oldcxt);
5084 
5085  querytree = copyObject(querytree);
5086 
5087  /* copy up any new invalItems, too */
5088  root->glob->invalItems = list_concat(saveInvalItems,
5089  copyObject(root->glob->invalItems));
5090 
5091  MemoryContextDelete(mycxt);
5092  error_context_stack = sqlerrcontext.previous;
5093  ReleaseSysCache(func_tuple);
5094 
5095  /*
5096  * We don't have to fix collations here because the upper query is already
5097  * parsed, ie, the collations in the RTE are what count.
5098  */
5099 
5100  /*
5101  * Since there is now no trace of the function in the plan tree, we must
5102  * explicitly record the plan's dependency on the function.
5103  */
5104  record_plan_function_dependency(root, func_oid);
5105 
5106  return querytree;
5107 
5108  /* Here if func is not inlinable: release temp memory and return NULL */
5109 fail:
5110  MemoryContextSwitchTo(oldcxt);
5111  root->glob->invalItems = saveInvalItems;
5112  MemoryContextDelete(mycxt);
5113  error_context_stack = sqlerrcontext.previous;
5114  ReleaseSysCache(func_tuple);
5115 
5116  return NULL;
5117 }
Oid funcresulttype
Definition: primnodes.h:450
#define NIL
Definition: pg_list.h:69
#define IsA(nodeptr, _type_)
Definition: nodes.h:563
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:198
#define GETSTRUCT(TUP)
Definition: htup_details.h:661
List * args
Definition: primnodes.h:457
Oid GetUserId(void)
Definition: miscinit.c:284
#define TYPTYPE_COMPOSITE
Definition: pg_type.h:721
void sql_fn_parser_setup(struct ParseState *pstate, SQLFunctionParseInfoPtr pinfo)
Definition: functions.c:273
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define Anum_pg_proc_prosrc
Definition: pg_proc.h:115
Definition: nodes.h:512
bool check_sql_fn_retval(Oid func_id, Oid rettype, List *queryTreeList, bool *modifyTargetList, JunkFilter **junkFilter)
Definition: functions.c:1534
char get_typtype(Oid typid)
Definition: lsyscache.c:2398
Node * eval_const_expressions(PlannerInfo *root, Node *node)
Definition: clauses.c:2459
List * list_concat(List *list1, List *list2)
Definition: list.c:321
bool funcretset
Definition: primnodes.h:451
bool contain_volatile_functions(Node *clause)
Definition: clauses.c:957
bool funcordinality
Definition: parsenodes.h:1006
unsigned int Oid
Definition: postgres_ext.h:31
void(* callback)(void *arg)
Definition: elog.h:239
struct ErrorContextCallback * previous
Definition: elog.h:238
#define FmgrHookIsNeeded(fn_oid)
Definition: fmgr.h:730
#define Anum_pg_proc_proconfig
Definition: pg_proc.h:117
List * targetList
Definition: parsenodes.h:138
ErrorContextCallback * error_context_stack
Definition: elog.c:88
bool contain_subplans(Node *clause)
Definition: clauses.c:843
#define linitial(l)
Definition: pg_list.h:111
Oid funcid
Definition: primnodes.h:449
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define SQLlanguageId
Definition: pg_language.h:80
List * pg_parse_query(const char *query_string)
Definition: postgres.c:607
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:197
void(* ParserSetupHook)(struct ParseState *pstate, void *arg)
Definition: params.h:66
void check_stack_depth(void)
Definition: postgres.c:3150
PlannerGlobal * glob
Definition: relation.h:157
bool heap_attisnull(HeapTuple tup, int attnum)
Definition: heaptuple.c:296
#define RECORDOID
Definition: pg_type.h:680
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
#define PROVOLATILE_VOLATILE
Definition: pg_proc.h:5539
TypeFuncClass get_func_result_type(Oid functionId, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:272
#define AllocSetContextCreate(parent, name, allocparams)
Definition: memutils.h:165
static void sql_inline_error_callback(void *arg)
Definition: clauses.c:4725
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
List * invalItems
Definition: relation.h:115
#define TextDatumGetCString(d)
Definition: builtins.h:92
uintptr_t Datum
Definition: postgres.h:372
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1368
void record_plan_function_dependency(PlannerInfo *root, Oid funcid)
Definition: setrefs.c:2558
static Query * substitute_actual_srf_parameters(Query *expr, int nargs, List *args)
Definition: clauses.c:5126
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:83
CmdType commandType
Definition: parsenodes.h:110
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define Assert(condition)
Definition: c.h:680
List * functions
Definition: parsenodes.h:1005
static int list_length(const List *l)
Definition: pg_list.h:89
List * pg_analyze_and_rewrite_params(RawStmt *parsetree, const char *query_string, ParserSetupHook parserSetup, void *parserSetupArg, QueryEnvironment *queryEnv)
Definition: postgres.c:686
Datum querytree(PG_FUNCTION_ARGS)
Definition: _int_bool.c:665
RTEKind rtekind
Definition: parsenodes.h:951
static bool tlist_matches_coltypelist(List *tlist, List *coltypelist)
Definition: clauses.c:5194
#define ACL_EXECUTE
Definition: parsenodes.h:79
AclResult pg_proc_aclcheck(Oid proc_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4504
#define NameStr(name)
Definition: c.h:557
#define elog
Definition: elog.h:219
SQLFunctionParseInfoPtr prepare_sql_fn_parse_info(HeapTuple procedureTuple, Node *call_expr, Oid inputCollation)
Definition: functions.c:184
#define copyObject(obj)
Definition: nodes.h:625
Definition: pg_list.h:45

◆ is_parallel_safe()

bool is_parallel_safe ( PlannerInfo root,
Node node 
)

Definition at line 1087 of file clauses.c.

References PlannerInfo::glob, PlannerInfo::init_plans, lcons_int(), lfirst, lfirst_int, max_parallel_hazard_context::max_hazard, max_parallel_hazard_context::max_interesting, max_parallel_hazard_walker(), PlannerGlobal::maxParallelHazard, NIL, PlannerGlobal::paramExecTypes, PlannerInfo::parent_root, PROPARALLEL_RESTRICTED, PROPARALLEL_SAFE, max_parallel_hazard_context::safe_param_ids, and SubPlan::setParam.

Referenced by apply_projection_to_path(), build_join_rel(), create_grouping_paths(), create_ordered_paths(), create_projection_path(), create_set_projection_path(), create_window_paths(), grouping_planner(), query_planner(), and set_rel_consider_parallel().

1088 {
1090  PlannerInfo *proot;
1091  ListCell *l;
1092 
1093  /*
1094  * Even if the original querytree contained nothing unsafe, we need to
1095  * search the expression if we have generated any PARAM_EXEC Params while
1096  * planning, because those are parallel-restricted and there might be one
1097  * in this expression. But otherwise we don't need to look.
1098  */
1099  if (root->glob->maxParallelHazard == PROPARALLEL_SAFE &&
1100  root->glob->paramExecTypes == NIL)
1101  return true;
1102  /* Else use max_parallel_hazard's search logic, but stop on RESTRICTED */
1103  context.max_hazard = PROPARALLEL_SAFE;
1105  context.safe_param_ids = NIL;
1106 
1107  /*
1108  * The params that refer to the same or parent query level are considered
1109  * parallel-safe. The idea is that we compute such params at Gather or
1110  * Gather Merge node and pass their value to workers.
1111  */
1112  for (proot = root; proot != NULL; proot = proot->parent_root)
1113  {
1114  foreach(l, proot->init_plans)
1115  {
1116  SubPlan *initsubplan = (SubPlan *) lfirst(l);
1117  ListCell *l2;
1118 
1119  foreach(l2, initsubplan->setParam)
1120  context.safe_param_ids = lcons_int(lfirst_int(l2),
1121  context.safe_param_ids);
1122  }
1123  }
1124 
1125  return !max_parallel_hazard_walker(node, &context);
1126 }
char maxParallelHazard
Definition: relation.h:133
#define NIL
Definition: pg_list.h:69
List * lcons_int(int datum, List *list)
Definition: list.c:277
#define PROPARALLEL_RESTRICTED
Definition: pg_proc.h:5547
List * paramExecTypes
Definition: relation.h:117
#define lfirst_int(lc)
Definition: pg_list.h:107
static bool max_parallel_hazard_walker(Node *node, max_parallel_hazard_context *context)
Definition: clauses.c:1165
PlannerGlobal * glob
Definition: relation.h:157
#define PROPARALLEL_SAFE
Definition: pg_proc.h:5546
struct PlannerInfo * parent_root
Definition: relation.h:161
List * init_plans
Definition: relation.h:228
#define lfirst(lc)
Definition: pg_list.h:106
List * setParam
Definition: primnodes.h:707

◆ is_pseudo_constant_clause()

bool is_pseudo_constant_clause ( Node clause)

Definition at line 2230 of file clauses.c.

References contain_var_clause(), and contain_volatile_functions().

Referenced by clauselist_selectivity(), dependency_is_compatible_clause(), IsTidEqualAnyClause(), and IsTidEqualClause().

2231 {
2232  /*
2233  * We could implement this check in one recursive scan. But since the
2234  * check for volatile functions is both moderately expensive and unlikely
2235  * to fail, it seems better to look for Vars first and only check for
2236  * volatile functions if we find no Vars.
2237  */
2238  if (!contain_var_clause(clause) &&
2239  !contain_volatile_functions(clause))
2240  return true;
2241  return false;
2242 }
bool contain_var_clause(Node *node)
Definition: var.c:331
bool contain_volatile_functions(Node *clause)
Definition: clauses.c:957

◆ is_pseudo_constant_clause_relids()

bool is_pseudo_constant_clause_relids ( Node clause,
Relids  relids 
)

Definition at line 2250 of file clauses.c.

References bms_is_empty(), and contain_volatile_functions().

Referenced by clauselist_selectivity().

2251 {
2252  if (bms_is_empty(relids) &&
2253  !contain_volatile_functions(clause))
2254  return true;
2255  return false;
2256 }
bool contain_volatile_functions(Node *clause)
Definition: clauses.c:957
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:663

◆ make_and_qual()

Node* make_and_qual ( Node qual1,
Node qual2 
)

Definition at line 348 of file clauses.c.

References list_make2, and make_andclause().

Referenced by AddQual(), and subquery_push_qual().

349 {
350  if (qual1 == NULL)
351  return qual2;
352  if (qual2 == NULL)
353  return qual1;
354  return (Node *) make_andclause(list_make2(qual1, qual2));
355 }
#define list_make2(x1, x2)
Definition: pg_list.h:140
Definition: nodes.h:512
Expr * make_andclause(List *andclauses)
Definition: clauses.c:327

◆ make_andclause()

Expr* make_andclause ( List andclauses)

Definition at line 327 of file clauses.c.

References AND_EXPR, BoolExpr::args, BoolExpr::boolop, BoolExpr::location, and makeNode.

Referenced by eval_const_expressions_mutator(), find_duplicate_ors(), make_and_qual(), make_ands_explicit(), make_sub_restrictinfos(), negate_clause(), process_duplicate_ors(), process_sublinks_mutator(), and pull_up_sublinks_qual_recurse().

328 {
329  BoolExpr *expr = makeNode(BoolExpr);
330 
331  expr->boolop = AND_EXPR;
332  expr->args = andclauses;
333  expr->location = -1;
334  return (Expr *) expr;
335 }
int location
Definition: primnodes.h:564
BoolExprType boolop
Definition: primnodes.h:562
#define makeNode(_type_)
Definition: nodes.h:560
List * args
Definition: primnodes.h:563

◆ make_ands_explicit()

Expr* make_ands_explicit ( List andclauses)

Definition at line 367 of file clauses.c.

References linitial, list_length(), make_andclause(), makeBoolConst(), and NIL.

Referenced by ATExecAttachPartition(), convert_EXISTS_to_ANY(), create_bitmap_subplan(), ExecInitCheck(), extract_or_clause(), get_proposed_default_constraint(), get_qual_for_list(), PartConstraintImpliedByRelConstraint(), show_qual(), and UpdateIndexRelation().

368 {
369  if (andclauses == NIL)
370  return (Expr *) makeBoolConst(true, false);
371  else if (list_length(andclauses) == 1)
372  return (Expr *) linitial(andclauses);
373  else
374  return make_andclause(andclauses);
375 }
#define NIL
Definition: pg_list.h:69
#define linitial(l)
Definition: pg_list.h:111
Node * makeBoolConst(bool value, bool isnull)
Definition: makefuncs.c:356
static int list_length(const List *l)
Definition: pg_list.h:89
Expr * make_andclause(List *andclauses)
Definition: clauses.c:327

◆ make_ands_implicit()

List* make_ands_implicit ( Expr clause)

Definition at line 378 of file clauses.c.

References and_clause(), DatumGetBool, IsA, list_make1, and NIL.

Referenced by convert_EXISTS_to_ANY(), cost_subplan(), DefineIndex(), get_relation_constraints(), PartConstraintImpliedByRelConstraint(), preprocess_expression(), RelationGetIndexPredicate(), set_append_rel_size(), and TriggerEnabled().

379 {
380  /*
381  * NB: because the parser sets the qual field to NULL in a query that has
382  * no WHERE clause, we must consider a NULL input clause as TRUE, even
383  * though one might more reasonably think it FALSE. Grumble. If this
384  * causes trouble, consider changing the parser's behavior.
385  */
386  if (clause == NULL)
387  return NIL; /* NULL -> NIL list == TRUE */
388  else if (and_clause((Node *) clause))
389  return ((BoolExpr *) clause)->args;
390  else if (IsA(clause, Const) &&
391  !((Const *) clause)->constisnull &&
392  DatumGetBool(((Const *) clause)->constvalue))
393  return NIL; /* constant TRUE input -> NIL list */
394  else
395  return list_make1(clause);
396 }
#define NIL
Definition: pg_list.h:69
#define IsA(nodeptr, _type_)
Definition: nodes.h:563
Definition: nodes.h:512
#define list_make1(x1)
Definition: pg_list.h:139
bool and_clause(Node *clause)
Definition: clauses.c:314
#define DatumGetBool(X)
Definition: postgres.h:399

◆ make_notclause()

Expr* make_notclause ( Expr notclause)

Definition at line 249 of file clauses.c.

References BoolExpr::args, BoolExpr::boolop, list_make1, BoolExpr::location, makeNode, and NOT_EXPR.

Referenced by negate_clause().

250 {
251  BoolExpr *expr = makeNode(BoolExpr);
252 
253  expr->boolop = NOT_EXPR;
254  expr->args = list_make1(notclause);
255  expr->location = -1;
256  return (Expr *) expr;
257 }
int location
Definition: primnodes.h:564
#define list_make1(x1)
Definition: pg_list.h:139
BoolExprType boolop
Definition: primnodes.h:562
#define makeNode(_type_)
Definition: nodes.h:560
List * args
Definition: primnodes.h:563

◆ make_opclause()

Expr* make_opclause ( Oid  opno,
Oid  opresulttype,
bool  opretset,
Expr leftop,
Expr rightop,
Oid  opcollid,
Oid  inputcollid 
)

Definition at line 172 of file clauses.c.

References OpExpr::args, OpExpr::inputcollid, InvalidOid, list_make1, list_make2, OpExpr::location, makeNode, OpExpr::opcollid, OpExpr::opfuncid, OpExpr::opno, OpExpr::opresulttype, and OpExpr::opretset.

Referenced by adjust_rowcompare_for_index(), build_implied_join_equality(), convert_EXISTS_to_ANY(), expand_boolean_index_clause(), make_partition_op_expr(), network_prefix_quals(), operator_predicate_proof(), prefix_quals(), and process_implied_equality().

175 {
176  OpExpr *expr = makeNode(OpExpr);
177 
178  expr->opno = opno;
179  expr->opfuncid = InvalidOid;
180  expr->opresulttype = opresulttype;
181  expr->opretset = opretset;
182  expr->opcollid = opcollid;
183  expr->inputcollid = inputcollid;
184  if (rightop)
185  expr->args = list_make2(leftop, rightop);
186  else
187  expr->args = list_make1(leftop);
188  expr->location = -1;
189  return (Expr *) expr;
190 }
#define list_make2(x1, x2)
Definition: pg_list.h:140
#define list_make1(x1)
Definition: pg_list.h:139
Oid opresulttype
Definition: primnodes.h:498
int location
Definition: primnodes.h:503
Oid opcollid
Definition: primnodes.h:500
Oid opfuncid
Definition: primnodes.h:497
#define InvalidOid
Definition: postgres_ext.h:36
#define makeNode(_type_)
Definition: nodes.h:560
Oid inputcollid
Definition: primnodes.h:501
Oid opno
Definition: primnodes.h:496
List * args
Definition: primnodes.h:502
bool opretset
Definition: primnodes.h:499

◆ make_orclause()

Expr* make_orclause ( List orclauses)

Definition at line 293 of file clauses.c.

References BoolExpr::args, BoolExpr::boolop, BoolExpr::location, makeNode, and OR_EXPR.

Referenced by create_bitmap_subplan(), create_tidscan_plan(), eval_const_expressions_mutator(), ExplainNode(), extract_or_clause(), make_sub_restrictinfos(), negate_clause(), process_duplicate_ors(), and process_sublinks_mutator().

294 {
295  BoolExpr *expr = makeNode(BoolExpr);
296 
297  expr->boolop = OR_EXPR;
298  expr->args = orclauses;
299  expr->location = -1;
300  return (Expr *) expr;
301 }
int location
Definition: primnodes.h:564
BoolExprType boolop
Definition: primnodes.h:562
#define makeNode(_type_)
Definition: nodes.h:560
List * args
Definition: primnodes.h:563

◆ max_parallel_hazard()

char max_parallel_hazard ( Query parse)

Definition at line 1068 of file clauses.c.

References max_parallel_hazard_context::max_hazard, max_parallel_hazard_context::max_interesting, max_parallel_hazard_walker(), NIL, parse(), PROPARALLEL_SAFE, PROPARALLEL_UNSAFE, and max_parallel_hazard_context::safe_param_ids.

Referenced by standard_planner().

1069 {
1071 
1072  context.max_hazard = PROPARALLEL_SAFE;
1074  context.safe_param_ids = NIL;
1075  (void) max_parallel_hazard_walker((Node *) parse, &context);
1076  return context.max_hazard;
1077 }
#define NIL
Definition: pg_list.h:69
Definition: nodes.h:512
static bool max_parallel_hazard_walker(Node *node, max_parallel_hazard_context *context)
Definition: clauses.c:1165
#define PROPARALLEL_SAFE
Definition: pg_proc.h:5546
#define PROPARALLEL_UNSAFE
Definition: pg_proc.h:5548
static struct subre * parse(struct vars *, int, int, struct state *, struct state *)
Definition: regcomp.c:649

◆ not_clause()

bool not_clause ( Node clause)

Definition at line 236 of file clauses.c.

References boolop(), IsA, and NOT_EXPR.

Referenced by clause_selectivity(), dependency_is_compatible_clause(), expand_boolean_index_clause(), match_boolean_index_clause(), and pull_up_sublinks_qual_recurse().

237 {
238  return (clause != NULL &&
239  IsA(clause, BoolExpr) &&
240  ((BoolExpr *) clause)->boolop == NOT_EXPR);
241 }
Datum boolop(PG_FUNCTION_ARGS)
Definition: _int_bool.c:420
#define IsA(nodeptr, _type_)
Definition: nodes.h:563

◆ NumRelids()

int NumRelids ( Node clause)

Definition at line 2272 of file clauses.c.

References bms_free(), bms_num_members(), and pull_varnos().

Referenced by clauselist_selectivity(), rowcomparesel(), and treat_as_join_clause().

2273 {
2274  Relids varnos = pull_varnos(clause);
2275  int result = bms_num_members(varnos);
2276 
2277  bms_free(varnos);
2278  return result;
2279 }
int bms_num_members(const Bitmapset *a)
Definition: bitmapset.c:605
Relids pull_varnos(Node *node)
Definition: var.c:95
void bms_free(Bitmapset *a)
Definition: bitmapset.c:201

◆ or_clause()

bool or_clause ( Node clause)

Definition at line 280 of file clauses.c.

References boolop(), IsA, and OR_EXPR.

Referenced by clause_selectivity(), extract_or_clause(), find_duplicate_ors(), make_restrictinfo(), make_sub_restrictinfos(), predicate_classify(), process_sublinks_mutator(), pull_ors(), simplify_or_arguments(), and TidQualFromExpr().

281 {
282  return (clause != NULL &&
283  IsA(clause, BoolExpr) &&
284  ((BoolExpr *) clause)->boolop == OR_EXPR);
285 }
Datum boolop(PG_FUNCTION_ARGS)
Definition: _int_bool.c:420
#define IsA(nodeptr, _type_)
Definition: nodes.h:563