PostgreSQL Source Code  git master
clauses.h File Reference
#include "nodes/pathnodes.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
 

Functions

bool contain_agg_clause (Node *clause)
 
bool contain_window_function (Node *clause)
 
WindowFuncListsfind_window_functions (Node *clause, Index maxWinRef)
 
double expression_returns_set_rows (PlannerInfo *root, Node *clause)
 
bool contain_subplans (Node *clause)
 
char max_parallel_hazard (Query *parse)
 
bool is_parallel_safe (PlannerInfo *root, Node *node)
 
bool contain_nonstrict_functions (Node *clause)
 
bool contain_exec_param (Node *clause, List *param_ids)
 
bool contain_leaked_vars (Node *clause)
 
Relids find_nonnullable_rels (Node *clause)
 
Listfind_nonnullable_vars (Node *clause)
 
Listfind_forced_null_vars (Node *node)
 
Varfind_forced_null_var (Node *node)
 
bool is_pseudo_constant_clause (Node *clause)
 
bool is_pseudo_constant_clause_relids (Node *clause, Relids relids)
 
int NumRelids (PlannerInfo *root, Node *clause)
 
void CommuteOpExpr (OpExpr *clause)
 
Queryinline_set_returning_function (PlannerInfo *root, RangeTblEntry *rte)
 
Bitmapsetpull_paramids (Expr *expr)
 

Function Documentation

◆ CommuteOpExpr()

void CommuteOpExpr ( OpExpr clause)

Definition at line 2027 of file clauses.c.

2028 {
2029  Oid opoid;
2030  Node *temp;
2031 
2032  /* Sanity checks: caller is at fault if these fail */
2033  if (!is_opclause(clause) ||
2034  list_length(clause->args) != 2)
2035  elog(ERROR, "cannot commute non-binary-operator clause");
2036 
2037  opoid = get_commutator(clause->opno);
2038 
2039  if (!OidIsValid(opoid))
2040  elog(ERROR, "could not find commutator for operator %u",
2041  clause->opno);
2042 
2043  /*
2044  * modify the clause in-place!
2045  */
2046  clause->opno = opoid;
2047  clause->opfuncid = InvalidOid;
2048  /* opresulttype, opretset, opcollid, inputcollid need not change */
2049 
2050  temp = linitial(clause->args);
2051  linitial(clause->args) = lsecond(clause->args);
2052  lsecond(clause->args) = temp;
2053 }
#define OidIsValid(objectId)
Definition: c.h:759
#define ERROR
Definition: elog.h:39
Oid get_commutator(Oid opno)
Definition: lsyscache.c:1491
static bool is_opclause(const void *clause)
Definition: nodeFuncs.h:74
static int list_length(const List *l)
Definition: pg_list.h:152
#define linitial(l)
Definition: pg_list.h:178
#define lsecond(l)
Definition: pg_list.h:183
#define InvalidOid
Definition: postgres_ext.h:36
unsigned int Oid
Definition: postgres_ext.h:31
Definition: nodes.h:129
Oid opno
Definition: primnodes.h:742
List * args
Definition: primnodes.h:760

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

Referenced by get_switched_clauses().

◆ contain_agg_clause()

bool contain_agg_clause ( Node clause)

Definition at line 177 of file clauses.c.

178 {
179  return contain_agg_clause_walker(clause, NULL);
180 }
static bool contain_agg_clause_walker(Node *node, void *context)
Definition: clauses.c:183

References contain_agg_clause_walker().

Referenced by get_eclass_for_sort_expr(), and subquery_planner().

◆ contain_exec_param()

bool contain_exec_param ( Node clause,
List param_ids 
)

Definition at line 1018 of file clauses.c.

1019 {
1020  return contain_exec_param_walker(clause, param_ids);
1021 }
static bool contain_exec_param_walker(Node *node, List *param_ids)
Definition: clauses.c:1024

References contain_exec_param_walker().

Referenced by test_opexpr_is_hashable().

◆ contain_leaked_vars()

bool contain_leaked_vars ( Node clause)

Definition at line 1144 of file clauses.c.

1145 {
1146  return contain_leaked_vars_walker(clause, NULL);
1147 }
static bool contain_leaked_vars_walker(Node *node, void *context)
Definition: clauses.c:1156

References contain_leaked_vars_walker().

Referenced by make_restrictinfo_internal(), and qual_is_pushdown_safe().

◆ contain_nonstrict_functions()

bool contain_nonstrict_functions ( Node clause)

Definition at line 874 of file clauses.c.

875 {
876  return contain_nonstrict_functions_walker(clause, NULL);
877 }
static bool contain_nonstrict_functions_walker(Node *node, void *context)
Definition: clauses.c:886

References contain_nonstrict_functions_walker().

Referenced by inline_function().

◆ contain_subplans()

bool contain_subplans ( Node clause)

Definition at line 330 of file clauses.c.

331 {
332  return contain_subplans_walker(clause, NULL);
333 }
static bool contain_subplans_walker(Node *node, void *context)
Definition: clauses.c:336

References contain_subplans_walker().

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

◆ contain_window_function()

bool contain_window_function ( Node clause)

Definition at line 214 of file clauses.c.

215 {
216  return contain_windowfuncs(clause);
217 }
bool contain_windowfuncs(Node *node)
Definition: rewriteManip.c:215

References contain_windowfuncs().

Referenced by get_eclass_for_sort_expr(), and qual_is_pushdown_safe().

◆ expression_returns_set_rows()

double expression_returns_set_rows ( PlannerInfo root,
Node clause 
)

Definition at line 289 of file clauses.c.

290 {
291  if (clause == NULL)
292  return 1.0;
293  if (IsA(clause, FuncExpr))
294  {
295  FuncExpr *expr = (FuncExpr *) clause;
296 
297  if (expr->funcretset)
298  return clamp_row_est(get_function_rows(root, expr->funcid, clause));
299  }
300  if (IsA(clause, OpExpr))
301  {
302  OpExpr *expr = (OpExpr *) clause;
303 
304  if (expr->opretset)
305  {
306  set_opfuncid(expr);
307  return clamp_row_est(get_function_rows(root, expr->opfuncid, clause));
308  }
309  }
310  return 1.0;
311 }
double clamp_row_est(double nrows)
Definition: costsize.c:202
void set_opfuncid(OpExpr *opexpr)
Definition: nodeFuncs.c:1672
#define IsA(nodeptr, _type_)
Definition: nodes.h:179
double get_function_rows(PlannerInfo *root, Oid funcid, Node *node)
Definition: plancat.c:2102
Oid funcid
Definition: primnodes.h:674

References clamp_row_est(), FuncExpr::funcid, get_function_rows(), IsA, and set_opfuncid().

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

◆ find_forced_null_var()

Var* find_forced_null_var ( Node node)

Definition at line 1857 of file clauses.c.

1858 {
1859  if (node == NULL)
1860  return NULL;
1861  if (IsA(node, NullTest))
1862  {
1863  /* check for var IS NULL */
1864  NullTest *expr = (NullTest *) node;
1865 
1866  if (expr->nulltesttype == IS_NULL && !expr->argisrow)
1867  {
1868  Var *var = (Var *) expr->arg;
1869 
1870  if (var && IsA(var, Var) &&
1871  var->varlevelsup == 0)
1872  return var;
1873  }
1874  }
1875  else if (IsA(node, BooleanTest))
1876  {
1877  /* var IS UNKNOWN is equivalent to var IS NULL */
1878  BooleanTest *expr = (BooleanTest *) node;
1879 
1880  if (expr->booltesttype == IS_UNKNOWN)
1881  {
1882  Var *var = (Var *) expr->arg;
1883 
1884  if (var && IsA(var, Var) &&
1885  var->varlevelsup == 0)
1886  return var;
1887  }
1888  }
1889  return NULL;
1890 }
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77
@ IS_UNKNOWN
Definition: primnodes.h:1537
@ IS_NULL
Definition: primnodes.h:1513
BoolTestType booltesttype
Definition: primnodes.h:1544
Expr * arg
Definition: primnodes.h:1543
NullTestType nulltesttype
Definition: primnodes.h:1520
Expr * arg
Definition: primnodes.h:1519
Definition: primnodes.h:223
Index varlevelsup
Definition: primnodes.h:255

References NullTest::arg, BooleanTest::arg, BooleanTest::booltesttype, if(), IS_NULL, IS_UNKNOWN, IsA, NullTest::nulltesttype, and Var::varlevelsup.

Referenced by check_redundant_nullability_qual(), and find_forced_null_vars().

◆ find_forced_null_vars()

List* find_forced_null_vars ( Node node)

Definition at line 1796 of file clauses.c.

1797 {
1798  List *result = NIL;
1799  Var *var;
1800  ListCell *l;
1801 
1802  if (node == NULL)
1803  return NIL;
1804  /* Check single-clause cases using subroutine */
1805  var = find_forced_null_var(node);
1806  if (var)
1807  {
1808  result = mbms_add_member(result,
1809  var->varno,
1811  }
1812  /* Otherwise, handle AND-conditions */
1813  else if (IsA(node, List))
1814  {
1815  /*
1816  * At top level, we are examining an implicit-AND list: if any of the
1817  * arms produces FALSE-or-NULL then the result is FALSE-or-NULL.
1818  */
1819  foreach(l, (List *) node)
1820  {
1821  result = mbms_add_members(result,
1823  }
1824  }
1825  else if (IsA(node, BoolExpr))
1826  {
1827  BoolExpr *expr = (BoolExpr *) node;
1828 
1829  /*
1830  * We don't bother considering the OR case, because it's fairly
1831  * unlikely anyone would write "v1 IS NULL OR v1 IS NULL". Likewise,
1832  * the NOT case isn't worth expending code on.
1833  */
1834  if (expr->boolop == AND_EXPR)
1835  {
1836  /* At top level we can just recurse (to the List case) */
1837  result = find_forced_null_vars((Node *) expr->args);
1838  }
1839  }
1840  return result;
1841 }
Var * find_forced_null_var(Node *node)
Definition: clauses.c:1857
List * find_forced_null_vars(Node *node)
Definition: clauses.c:1796
List * mbms_add_member(List *a, int listidx, int bitidx)
List * mbms_add_members(List *a, const List *b)
#define lfirst(lc)
Definition: pg_list.h:172
#define NIL
Definition: pg_list.h:68
@ AND_EXPR
Definition: primnodes.h:855
BoolExprType boolop
Definition: primnodes.h:863
List * args
Definition: primnodes.h:864
Definition: pg_list.h:54
AttrNumber varattno
Definition: primnodes.h:235
int varno
Definition: primnodes.h:230
#define FirstLowInvalidHeapAttributeNumber
Definition: sysattr.h:27

References AND_EXPR, BoolExpr::args, BoolExpr::boolop, find_forced_null_var(), FirstLowInvalidHeapAttributeNumber, IsA, lfirst, mbms_add_member(), mbms_add_members(), NIL, Var::varattno, and Var::varno.

Referenced by reduce_outer_joins_pass2().

◆ find_nonnullable_rels()

Relids find_nonnullable_rels ( Node clause)

Definition at line 1336 of file clauses.c.

1337 {
1338  return find_nonnullable_rels_walker(clause, true);
1339 }
static Relids find_nonnullable_rels_walker(Node *node, bool top_level)
Definition: clauses.c:1342

References find_nonnullable_rels_walker().

Referenced by make_outerjoininfo(), and reduce_outer_joins_pass2().

◆ find_nonnullable_vars()

List* find_nonnullable_vars ( Node clause)

Definition at line 1587 of file clauses.c.

1588 {
1589  return find_nonnullable_vars_walker(clause, true);
1590 }
static List * find_nonnullable_vars_walker(Node *node, bool top_level)
Definition: clauses.c:1593

References find_nonnullable_vars_walker().

Referenced by reduce_outer_joins_pass2().

◆ find_window_functions()

WindowFuncLists* find_window_functions ( Node clause,
Index  maxWinRef 
)

Definition at line 227 of file clauses.c.

228 {
229  WindowFuncLists *lists = palloc(sizeof(WindowFuncLists));
230 
231  lists->numWindowFuncs = 0;
232  lists->maxWinRef = maxWinRef;
233  lists->windowFuncs = (List **) palloc0((maxWinRef + 1) * sizeof(List *));
234  (void) find_window_functions_walker(clause, lists);
235  return lists;
236 }
static bool find_window_functions_walker(Node *node, WindowFuncLists *lists)
Definition: clauses.c:239
void * palloc0(Size size)
Definition: mcxt.c:1241
void * palloc(Size size)
Definition: mcxt.c:1210
List ** windowFuncs
Definition: clauses.h:23
Index maxWinRef
Definition: clauses.h:22
int numWindowFuncs
Definition: clauses.h:21

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

Referenced by grouping_planner().

◆ inline_set_returning_function()

Query* inline_set_returning_function ( PlannerInfo root,
RangeTblEntry rte 
)

Definition at line 4901 of file clauses.c.

4902 {
4903  RangeTblFunction *rtfunc;
4904  FuncExpr *fexpr;
4905  Oid func_oid;
4906  HeapTuple func_tuple;
4907  Form_pg_proc funcform;
4908  char *src;
4909  Datum tmp;
4910  bool isNull;
4911  MemoryContext oldcxt;
4912  MemoryContext mycxt;
4913  inline_error_callback_arg callback_arg;
4914  ErrorContextCallback sqlerrcontext;
4916  TypeFuncClass functypclass;
4917  TupleDesc rettupdesc;
4918  List *raw_parsetree_list;
4919  List *querytree_list;
4920  Query *querytree;
4921 
4922  Assert(rte->rtekind == RTE_FUNCTION);
4923 
4924  /*
4925  * It doesn't make a lot of sense for a SQL SRF to refer to itself in its
4926  * own FROM clause, since that must cause infinite recursion at runtime.
4927  * It will cause this code to recurse too, so check for stack overflow.
4928  * (There's no need to do more.)
4929  */
4931 
4932  /* Fail if the RTE has ORDINALITY - we don't implement that here. */
4933  if (rte->funcordinality)
4934  return NULL;
4935 
4936  /* Fail if RTE isn't a single, simple FuncExpr */
4937  if (list_length(rte->functions) != 1)
4938  return NULL;
4939  rtfunc = (RangeTblFunction *) linitial(rte->functions);
4940 
4941  if (!IsA(rtfunc->funcexpr, FuncExpr))
4942  return NULL;
4943  fexpr = (FuncExpr *) rtfunc->funcexpr;
4944 
4945  func_oid = fexpr->funcid;
4946 
4947  /*
4948  * The function must be declared to return a set, else inlining would
4949  * change the results if the contained SELECT didn't return exactly one
4950  * row.
4951  */
4952  if (!fexpr->funcretset)
4953  return NULL;
4954 
4955  /*
4956  * Refuse to inline if the arguments contain any volatile functions or
4957  * sub-selects. Volatile functions are rejected because inlining may
4958  * result in the arguments being evaluated multiple times, risking a
4959  * change in behavior. Sub-selects are rejected partly for implementation
4960  * reasons (pushing them down another level might change their behavior)
4961  * and partly because they're likely to be expensive and so multiple
4962  * evaluation would be bad.
4963  */
4964  if (contain_volatile_functions((Node *) fexpr->args) ||
4965  contain_subplans((Node *) fexpr->args))
4966  return NULL;
4967 
4968  /* Check permission to call function (fail later, if not) */
4969  if (object_aclcheck(ProcedureRelationId, func_oid, GetUserId(), ACL_EXECUTE) != ACLCHECK_OK)
4970  return NULL;
4971 
4972  /* Check whether a plugin wants to hook function entry/exit */
4973  if (FmgrHookIsNeeded(func_oid))
4974  return NULL;
4975 
4976  /*
4977  * OK, let's take a look at the function's pg_proc entry.
4978  */
4979  func_tuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(func_oid));
4980  if (!HeapTupleIsValid(func_tuple))
4981  elog(ERROR, "cache lookup failed for function %u", func_oid);
4982  funcform = (Form_pg_proc) GETSTRUCT(func_tuple);
4983 
4984  /*
4985  * Forget it if the function is not SQL-language or has other showstopper
4986  * properties. In particular it mustn't be declared STRICT, since we
4987  * couldn't enforce that. It also mustn't be VOLATILE, because that is
4988  * supposed to cause it to be executed with its own snapshot, rather than
4989  * sharing the snapshot of the calling query. We also disallow returning
4990  * SETOF VOID, because inlining would result in exposing the actual result
4991  * of the function's last SELECT, which should not happen in that case.
4992  * (Rechecking prokind, proretset, and pronargs is just paranoia.)
4993  */
4994  if (funcform->prolang != SQLlanguageId ||
4995  funcform->prokind != PROKIND_FUNCTION ||
4996  funcform->proisstrict ||
4997  funcform->provolatile == PROVOLATILE_VOLATILE ||
4998  funcform->prorettype == VOIDOID ||
4999  funcform->prosecdef ||
5000  !funcform->proretset ||
5001  list_length(fexpr->args) != funcform->pronargs ||
5002  !heap_attisnull(func_tuple, Anum_pg_proc_proconfig, NULL))
5003  {
5004  ReleaseSysCache(func_tuple);
5005  return NULL;
5006  }
5007 
5008  /*
5009  * Make a temporary memory context, so that we don't leak all the stuff
5010  * that parsing might create.
5011  */
5013  "inline_set_returning_function",
5015  oldcxt = MemoryContextSwitchTo(mycxt);
5016 
5017  /* Fetch the function body */
5018  tmp = SysCacheGetAttr(PROCOID,
5019  func_tuple,
5020  Anum_pg_proc_prosrc,
5021  &isNull);
5022  if (isNull)
5023  elog(ERROR, "null prosrc for function %u", func_oid);
5024  src = TextDatumGetCString(tmp);
5025 
5026  /*
5027  * Setup error traceback support for ereport(). This is so that we can
5028  * finger the function that bad information came from.
5029  */
5030  callback_arg.proname = NameStr(funcform->proname);
5031  callback_arg.prosrc = src;
5032 
5033  sqlerrcontext.callback = sql_inline_error_callback;
5034  sqlerrcontext.arg = (void *) &callback_arg;
5035  sqlerrcontext.previous = error_context_stack;
5036  error_context_stack = &sqlerrcontext;
5037 
5038  /* If we have prosqlbody, pay attention to that not prosrc */
5039  tmp = SysCacheGetAttr(PROCOID,
5040  func_tuple,
5041  Anum_pg_proc_prosqlbody,
5042  &isNull);
5043  if (!isNull)
5044  {
5045  Node *n;
5046 
5048  if (IsA(n, List))
5049  querytree_list = linitial_node(List, castNode(List, n));
5050  else
5051  querytree_list = list_make1(n);
5052  if (list_length(querytree_list) != 1)
5053  goto fail;
5054  querytree = linitial(querytree_list);
5055 
5056  /* Acquire necessary locks, then apply rewriter. */
5057  AcquireRewriteLocks(querytree, true, false);
5058  querytree_list = pg_rewrite_query(querytree);
5059  if (list_length(querytree_list) != 1)
5060  goto fail;
5061  querytree = linitial(querytree_list);
5062  }
5063  else
5064  {
5065  /*
5066  * Set up to handle parameters while parsing the function body. We
5067  * can use the FuncExpr just created as the input for
5068  * prepare_sql_fn_parse_info.
5069  */
5070  pinfo = prepare_sql_fn_parse_info(func_tuple,
5071  (Node *) fexpr,
5072  fexpr->inputcollid);
5073 
5074  /*
5075  * Parse, analyze, and rewrite (unlike inline_function(), we can't
5076  * skip rewriting here). We can fail as soon as we find more than one
5077  * query, though.
5078  */
5079  raw_parsetree_list = pg_parse_query(src);
5080  if (list_length(raw_parsetree_list) != 1)
5081  goto fail;
5082 
5083  querytree_list = pg_analyze_and_rewrite_withcb(linitial(raw_parsetree_list),
5084  src,
5086  pinfo, NULL);
5087  if (list_length(querytree_list) != 1)
5088  goto fail;
5089  querytree = linitial(querytree_list);
5090  }
5091 
5092  /*
5093  * Also resolve the actual function result tupdesc, if composite. If the
5094  * function is just declared to return RECORD, dig the info out of the AS
5095  * clause.
5096  */
5097  functypclass = get_expr_result_type((Node *) fexpr, NULL, &rettupdesc);
5098  if (functypclass == TYPEFUNC_RECORD)
5099  rettupdesc = BuildDescFromLists(rtfunc->funccolnames,
5100  rtfunc->funccoltypes,
5101  rtfunc->funccoltypmods,
5102  rtfunc->funccolcollations);
5103 
5104  /*
5105  * The single command must be a plain SELECT.
5106  */
5107  if (!IsA(querytree, Query) ||
5108  querytree->commandType != CMD_SELECT)
5109  goto fail;
5110 
5111  /*
5112  * Make sure the function (still) returns what it's declared to. This
5113  * will raise an error if wrong, but that's okay since the function would
5114  * fail at runtime anyway. Note that check_sql_fn_retval will also insert
5115  * coercions if needed to make the tlist expression(s) match the declared
5116  * type of the function. We also ask it to insert dummy NULL columns for
5117  * any dropped columns in rettupdesc, so that the elements of the modified
5118  * tlist match up to the attribute numbers.
5119  *
5120  * If the function returns a composite type, don't inline unless the check
5121  * shows it's returning a whole tuple result; otherwise what it's
5122  * returning is a single composite column which is not what we need.
5123  */
5124  if (!check_sql_fn_retval(list_make1(querytree_list),
5125  fexpr->funcresulttype, rettupdesc,
5126  true, NULL) &&
5127  (functypclass == TYPEFUNC_COMPOSITE ||
5128  functypclass == TYPEFUNC_COMPOSITE_DOMAIN ||
5129  functypclass == TYPEFUNC_RECORD))
5130  goto fail; /* reject not-whole-tuple-result cases */
5131 
5132  /*
5133  * check_sql_fn_retval might've inserted a projection step, but that's
5134  * fine; just make sure we use the upper Query.
5135  */
5136  querytree = linitial_node(Query, querytree_list);
5137 
5138  /*
5139  * Looks good --- substitute parameters into the query.
5140  */
5142  funcform->pronargs,
5143  fexpr->args);
5144 
5145  /*
5146  * Copy the modified query out of the temporary memory context, and clean
5147  * up.
5148  */
5149  MemoryContextSwitchTo(oldcxt);
5150 
5152 
5153  MemoryContextDelete(mycxt);
5154  error_context_stack = sqlerrcontext.previous;
5155  ReleaseSysCache(func_tuple);
5156 
5157  /*
5158  * We don't have to fix collations here because the upper query is already
5159  * parsed, ie, the collations in the RTE are what count.
5160  */
5161 
5162  /*
5163  * Since there is now no trace of the function in the plan tree, we must
5164  * explicitly record the plan's dependency on the function.
5165  */
5166  record_plan_function_dependency(root, func_oid);
5167 
5168  return querytree;
5169 
5170  /* Here if func is not inlinable: release temp memory and return NULL */
5171 fail:
5172  MemoryContextSwitchTo(oldcxt);
5173  MemoryContextDelete(mycxt);
5174  error_context_stack = sqlerrcontext.previous;
5175  ReleaseSysCache(func_tuple);
5176 
5177  return NULL;
5178 }
Datum querytree(PG_FUNCTION_ARGS)
Definition: _int_bool.c:666
@ ACLCHECK_OK
Definition: acl.h:183
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
Definition: aclchk.c:3783
#define TextDatumGetCString(d)
Definition: builtins.h:95
#define NameStr(name)
Definition: c.h:730
static Query * substitute_actual_srf_parameters(Query *expr, int nargs, List *args)
Definition: clauses.c:5187
static void sql_inline_error_callback(void *arg)
Definition: clauses.c:4785
bool contain_subplans(Node *clause)
Definition: clauses.c:330
bool contain_volatile_functions(Node *clause)
Definition: clauses.c:448
ErrorContextCallback * error_context_stack
Definition: elog.c:95
#define FmgrHookIsNeeded(fn_oid)
Definition: fmgr.h:797
TypeFuncClass get_expr_result_type(Node *expr, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:292
TypeFuncClass
Definition: funcapi.h:147
@ TYPEFUNC_COMPOSITE
Definition: funcapi.h:149
@ TYPEFUNC_RECORD
Definition: funcapi.h:151
@ TYPEFUNC_COMPOSITE_DOMAIN
Definition: funcapi.h:150
bool check_sql_fn_retval(List *queryTreeLists, Oid rettype, TupleDesc rettupdesc, bool insertDroppedCols, List **resultTargetList)
Definition: functions.c:1612
void sql_fn_parser_setup(struct ParseState *pstate, SQLFunctionParseInfoPtr pinfo)
Definition: functions.c:265
SQLFunctionParseInfoPtr prepare_sql_fn_parse_info(HeapTuple procedureTuple, Node *call_expr, Oid inputCollation)
Definition: functions.c:176
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
Definition: heaptuple.c:359
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:653
Assert(fmt[strlen(fmt) - 1] !='\n')
MemoryContext CurrentMemoryContext
Definition: mcxt.c:135
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:387
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:153
Oid GetUserId(void)
Definition: miscinit.c:502
#define copyObject(obj)
Definition: nodes.h:244
@ CMD_SELECT
Definition: nodes.h:276
#define castNode(_type_, nodeptr)
Definition: nodes.h:197
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:138
void(* ParserSetupHook)(struct ParseState *pstate, void *arg)
Definition: params.h:108
@ RTE_FUNCTION
Definition: parsenodes.h:1016
#define ACL_EXECUTE
Definition: parsenodes.h:90
#define linitial_node(type, l)
Definition: pg_list.h:181
#define list_make1(x1)
Definition: pg_list.h:212
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:136
List * pg_parse_query(const char *query_string)
Definition: postgres.c:577
List * pg_analyze_and_rewrite_withcb(RawStmt *parsetree, const char *query_string, ParserSetupHook parserSetup, void *parserSetupArg, QueryEnvironment *queryEnv)
Definition: postgres.c:730
List * pg_rewrite_query(Query *query)
Definition: postgres.c:770
void check_stack_depth(void)
Definition: postgres.c:3454
uintptr_t Datum
Definition: postgres.h:64
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
void * stringToNode(const char *str)
Definition: read.c:90
void AcquireRewriteLocks(Query *parsetree, bool forExecute, bool forUpdatePushedDown)
void record_plan_function_dependency(PlannerInfo *root, Oid funcid)
Definition: setrefs.c:3396
struct ErrorContextCallback * previous
Definition: elog.h:295
void(* callback)(void *arg)
Definition: elog.h:296
List * args
Definition: primnodes.h:692
bool funcordinality
Definition: parsenodes.h:1148
List * functions
Definition: parsenodes.h:1147
RTEKind rtekind
Definition: parsenodes.h:1032
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:865
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:817
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1078
@ PROCOID
Definition: syscache.h:79
TupleDesc BuildDescFromLists(List *names, List *types, List *typmods, List *collations)
Definition: tupdesc.c:886

References ACL_EXECUTE, ACLCHECK_OK, AcquireRewriteLocks(), ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, ErrorContextCallback::arg, FuncExpr::args, Assert(), BuildDescFromLists(), ErrorContextCallback::callback, castNode, check_sql_fn_retval(), check_stack_depth(), CMD_SELECT, contain_subplans(), contain_volatile_functions(), copyObject, CurrentMemoryContext, elog(), ERROR, error_context_stack, FmgrHookIsNeeded, RangeTblFunction::funcexpr, FuncExpr::funcid, RangeTblEntry::funcordinality, RangeTblEntry::functions, get_expr_result_type(), GETSTRUCT, GetUserId(), heap_attisnull(), HeapTupleIsValid, if(), IsA, linitial, linitial_node, list_length(), list_make1, MemoryContextDelete(), MemoryContextSwitchTo(), NameStr, object_aclcheck(), ObjectIdGetDatum(), pg_analyze_and_rewrite_withcb(), pg_parse_query(), pg_rewrite_query(), prepare_sql_fn_parse_info(), ErrorContextCallback::previous, PROCOID, inline_error_callback_arg::proname, inline_error_callback_arg::prosrc, querytree(), record_plan_function_dependency(), ReleaseSysCache(), RTE_FUNCTION, RangeTblEntry::rtekind, SearchSysCache1(), sql_fn_parser_setup(), sql_inline_error_callback(), stringToNode(), substitute_actual_srf_parameters(), SysCacheGetAttr(), TextDatumGetCString, TYPEFUNC_COMPOSITE, TYPEFUNC_COMPOSITE_DOMAIN, and TYPEFUNC_RECORD.

Referenced by preprocess_function_rtes().

◆ is_parallel_safe()

bool is_parallel_safe ( PlannerInfo root,
Node node 
)

Definition at line 634 of file clauses.c.

635 {
637  PlannerInfo *proot;
638  ListCell *l;
639 
640  /*
641  * Even if the original querytree contained nothing unsafe, we need to
642  * search the expression if we have generated any PARAM_EXEC Params while
643  * planning, because those are parallel-restricted and there might be one
644  * in this expression. But otherwise we don't need to look.
645  */
646  if (root->glob->maxParallelHazard == PROPARALLEL_SAFE &&
647  root->glob->paramExecTypes == NIL)
648  return true;
649  /* Else use max_parallel_hazard's search logic, but stop on RESTRICTED */
650  context.max_hazard = PROPARALLEL_SAFE;
651  context.max_interesting = PROPARALLEL_RESTRICTED;
652  context.safe_param_ids = NIL;
653 
654  /*
655  * The params that refer to the same or parent query level are considered
656  * parallel-safe. The idea is that we compute such params at Gather or
657  * Gather Merge node and pass their value to workers.
658  */
659  for (proot = root; proot != NULL; proot = proot->parent_root)
660  {
661  foreach(l, proot->init_plans)
662  {
663  SubPlan *initsubplan = (SubPlan *) lfirst(l);
664 
665  context.safe_param_ids = list_concat(context.safe_param_ids,
666  initsubplan->setParam);
667  }
668  }
669 
670  return !max_parallel_hazard_walker(node, &context);
671 }
static bool max_parallel_hazard_walker(Node *node, max_parallel_hazard_context *context)
Definition: clauses.c:710
List * list_concat(List *list1, const List *list2)
Definition: list.c:560
char maxParallelHazard
Definition: pathnodes.h:162
List * paramExecTypes
Definition: pathnodes.h:138
List * init_plans
Definition: pathnodes.h:299
PlannerGlobal * glob
Definition: pathnodes.h:205
List * setParam
Definition: primnodes.h:1010

References PlannerInfo::glob, PlannerInfo::init_plans, lfirst, list_concat(), max_parallel_hazard_context::max_hazard, max_parallel_hazard_context::max_interesting, max_parallel_hazard_walker(), PlannerGlobal::maxParallelHazard, NIL, PlannerGlobal::paramExecTypes, max_parallel_hazard_context::safe_param_ids, and SubPlan::setParam.

Referenced by apply_projection_to_path(), build_join_rel(), create_projection_path(), create_set_projection_path(), create_window_paths(), find_computable_ec_member(), grouping_planner(), make_grouping_rel(), plan_create_index_workers(), query_planner(), relation_can_be_sorted_early(), and set_rel_consider_parallel().

◆ is_pseudo_constant_clause()

bool is_pseudo_constant_clause ( Node clause)

Definition at line 1968 of file clauses.c.

1969 {
1970  /*
1971  * We could implement this check in one recursive scan. But since the
1972  * check for volatile functions is both moderately expensive and unlikely
1973  * to fail, it seems better to look for Vars first and only check for
1974  * volatile functions if we find no Vars.
1975  */
1976  if (!contain_var_clause(clause) &&
1977  !contain_volatile_functions(clause))
1978  return true;
1979  return false;
1980 }
bool contain_var_clause(Node *node)
Definition: var.c:413

References contain_var_clause(), and contain_volatile_functions().

Referenced by clauselist_selectivity_ext(), dependency_is_compatible_clause(), dependency_is_compatible_expression(), and find_window_run_conditions().

◆ is_pseudo_constant_clause_relids()

bool is_pseudo_constant_clause_relids ( Node clause,
Relids  relids 
)

Definition at line 1988 of file clauses.c.

1989 {
1990  if (bms_is_empty(relids) &&
1991  !contain_volatile_functions(clause))
1992  return true;
1993  return false;
1994 }
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:704

References bms_is_empty(), and contain_volatile_functions().

Referenced by clauselist_selectivity_ext().

◆ max_parallel_hazard()

char max_parallel_hazard ( Query parse)

Definition at line 615 of file clauses.c.

616 {
618 
619  context.max_hazard = PROPARALLEL_SAFE;
620  context.max_interesting = PROPARALLEL_UNSAFE;
621  context.safe_param_ids = NIL;
622  (void) max_parallel_hazard_walker((Node *) parse, &context);
623  return context.max_hazard;
624 }
static struct subre * parse(struct vars *v, int stopper, int type, struct state *init, struct state *final)
Definition: regcomp.c:717

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

Referenced by standard_planner().

◆ NumRelids()

int NumRelids ( PlannerInfo root,
Node clause 
)

Definition at line 2010 of file clauses.c.

2011 {
2012  int result;
2013  Relids varnos = pull_varnos(root, clause);
2014 
2015  varnos = bms_del_members(varnos, root->outer_join_rels);
2016  result = bms_num_members(varnos);
2017  bms_free(varnos);
2018  return result;
2019 }
void bms_free(Bitmapset *a)
Definition: bitmapset.c:209
int bms_num_members(const Bitmapset *a)
Definition: bitmapset.c:649
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:932
Relids outer_join_rels
Definition: pathnodes.h:261
Relids pull_varnos(PlannerInfo *root, Node *node)
Definition: var.c:108

References bms_del_members(), bms_free(), bms_num_members(), PlannerInfo::outer_join_rels, and pull_varnos().

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

◆ pull_paramids()

Bitmapset* pull_paramids ( Expr expr)

Definition at line 5247 of file clauses.c.

5248 {
5249  Bitmapset *result = NULL;
5250 
5251  (void) pull_paramids_walker((Node *) expr, &result);
5252 
5253  return result;
5254 }
static bool pull_paramids_walker(Node *node, Bitmapset **context)
Definition: clauses.c:5257

References pull_paramids_walker().

Referenced by create_memoize_plan().