PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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

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

Function Documentation

bool and_clause ( Node clause)
void CommuteOpExpr ( OpExpr clause)

Definition at line 2198 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().

2199 {
2200  Oid opoid;
2201  Node *temp;
2202 
2203  /* Sanity checks: caller is at fault if these fail */
2204  if (!is_opclause(clause) ||
2205  list_length(clause->args) != 2)
2206  elog(ERROR, "cannot commute non-binary-operator clause");
2207 
2208  opoid = get_commutator(clause->opno);
2209 
2210  if (!OidIsValid(opoid))
2211  elog(ERROR, "could not find commutator for operator %u",
2212  clause->opno);
2213 
2214  /*
2215  * modify the clause in-place!
2216  */
2217  clause->opno = opoid;
2218  clause->opfuncid = InvalidOid;
2219  /* opresulttype, opretset, opcollid, inputcollid need not change */
2220 
2221  temp = linitial(clause->args);
2222  linitial(clause->args) = lsecond(clause->args);
2223  lsecond(clause->args) = temp;
2224 }
Oid get_commutator(Oid opno)
Definition: lsyscache.c:1281
Definition: nodes.h:508
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:534
#define lsecond(l)
Definition: pg_list.h:114
#define linitial(l)
Definition: pg_list.h:110
#define ERROR
Definition: elog.h:43
#define is_opclause(clause)
Definition: clauses.h:20
Oid opfuncid
Definition: primnodes.h:474
#define InvalidOid
Definition: postgres_ext.h:36
static int list_length(const List *l)
Definition: pg_list.h:89
Oid opno
Definition: primnodes.h:473
#define elog
Definition: elog.h:219
List * args
Definition: primnodes.h:479
void CommuteRowCompareExpr ( RowCompareExpr clause)

Definition at line 2232 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().

2233 {
2234  List *newops;
2235  List *temp;
2236  ListCell *l;
2237 
2238  /* Sanity checks: caller is at fault if these fail */
2239  if (!IsA(clause, RowCompareExpr))
2240  elog(ERROR, "expected a RowCompareExpr");
2241 
2242  /* Build list of commuted operators */
2243  newops = NIL;
2244  foreach(l, clause->opnos)
2245  {
2246  Oid opoid = lfirst_oid(l);
2247 
2248  opoid = get_commutator(opoid);
2249  if (!OidIsValid(opoid))
2250  elog(ERROR, "could not find commutator for operator %u",
2251  lfirst_oid(l));
2252  newops = lappend_oid(newops, opoid);
2253  }
2254 
2255  /*
2256  * modify the clause in-place!
2257  */
2258  switch (clause->rctype)
2259  {
2260  case ROWCOMPARE_LT:
2261  clause->rctype = ROWCOMPARE_GT;
2262  break;
2263  case ROWCOMPARE_LE:
2264  clause->rctype = ROWCOMPARE_GE;
2265  break;
2266  case ROWCOMPARE_GE:
2267  clause->rctype = ROWCOMPARE_LE;
2268  break;
2269  case ROWCOMPARE_GT:
2270  clause->rctype = ROWCOMPARE_LT;
2271  break;
2272  default:
2273  elog(ERROR, "unexpected RowCompare type: %d",
2274  (int) clause->rctype);
2275  break;
2276  }
2277 
2278  clause->opnos = newops;
2279 
2280  /*
2281  * Note: we need not change the opfamilies list; we assume any btree
2282  * opfamily containing an operator will also contain its commutator.
2283  * Collations don't change either.
2284  */
2285 
2286  temp = clause->largs;
2287  clause->largs = clause->rargs;
2288  clause->rargs = temp;
2289 }
#define NIL
Definition: pg_list.h:69
#define IsA(nodeptr, _type_)
Definition: nodes.h:559
Oid get_commutator(Oid opno)
Definition: lsyscache.c:1281
RowCompareType rctype
Definition: primnodes.h:1007
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:534
#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
bool contain_agg_clause ( Node clause)

Definition at line 416 of file clauses.c.

References contain_agg_clause_walker(), and NULL.

Referenced by get_eclass_for_sort_expr(), and subquery_planner().

417 {
418  return contain_agg_clause_walker(clause, NULL);
419 }
static bool contain_agg_clause_walker(Node *node, void *context)
Definition: clauses.c:422
#define NULL
Definition: c.h:226
bool contain_leaked_vars ( Node clause)

Definition at line 1427 of file clauses.c.

References contain_leaked_vars_walker(), and NULL.

Referenced by make_restrictinfo_internal(), and qual_is_pushdown_safe().

1428 {
1429  return contain_leaked_vars_walker(clause, NULL);
1430 }
#define NULL
Definition: c.h:226
static bool contain_leaked_vars_walker(Node *node, void *context)
Definition: clauses.c:1439
bool contain_mutable_functions ( Node clause)

Definition at line 877 of file clauses.c.

References contain_mutable_functions_walker(), and NULL.

Referenced by check_index_predicates(), CheckMutability(), ComputePartitionAttrs(), create_bitmap_scan_plan(), create_indexscan_plan(), find_minmax_aggs_walker(), inline_function(), is_foreign_expr(), and relation_excluded_by_constraints().

878 {
879  return contain_mutable_functions_walker(clause, NULL);
880 }
static bool contain_mutable_functions_walker(Node *node, void *context)
Definition: clauses.c:889
#define NULL
Definition: c.h:226
bool contain_nonstrict_functions ( Node clause)

Definition at line 1234 of file clauses.c.

References contain_nonstrict_functions_walker(), and NULL.

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

1235 {
1236  return contain_nonstrict_functions_walker(clause, NULL);
1237 }
static bool contain_nonstrict_functions_walker(Node *node, void *context)
Definition: clauses.c:1246
#define NULL
Definition: c.h:226
bool contain_subplans ( Node clause)

Definition at line 842 of file clauses.c.

References contain_subplans_walker(), and NULL.

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

843 {
844  return contain_subplans_walker(clause, NULL);
845 }
#define NULL
Definition: c.h:226
static bool contain_subplans_walker(Node *node, void *context)
Definition: clauses.c:848
bool contain_volatile_functions_not_nextval ( Node clause)

Definition at line 994 of file clauses.c.

References contain_volatile_functions_not_nextval_walker(), and NULL.

Referenced by BeginCopyFrom().

995 {
997 }
static bool contain_volatile_functions_not_nextval_walker(Node *node, void *context)
Definition: clauses.c:1007
#define NULL
Definition: c.h:226
bool contain_window_function ( Node clause)

Definition at line 726 of file clauses.c.

References contain_windowfuncs().

Referenced by get_eclass_for_sort_expr(), and qual_is_pushdown_safe().

727 {
728  return contain_windowfuncs(clause);
729 }
bool contain_windowfuncs(Node *node)
Definition: rewriteManip.c:197
Node* estimate_expression_value ( PlannerInfo root,
Node node 
)

Definition at line 2399 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, NULL, 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().

2400 {
2402 
2403  context.boundParams = root->glob->boundParams; /* bound Params */
2404  /* we do not need to mark the plan as depending on inlined functions */
2405  context.root = NULL;
2406  context.active_fns = NIL; /* nothing being recursively simplified */
2407  context.case_val = NULL; /* no CASE being examined */
2408  context.estimate = true; /* unsafe transformations OK */
2409  return eval_const_expressions_mutator(node, &context);
2410 }
#define NIL
Definition: pg_list.h:69
static Node * eval_const_expressions_mutator(Node *node, eval_const_expressions_context *context)
Definition: clauses.c:2413
ParamListInfo boundParams
Definition: clauses.c:65
PlannerGlobal * glob
Definition: relation.h:154
#define NULL
Definition: c.h:226
ParamListInfo boundParams
Definition: relation.h:96
Node* eval_const_expressions ( PlannerInfo root,
Node node 
)

Definition at line 2366 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, NULL, and eval_const_expressions_context::root.

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

2367 {
2369 
2370  if (root)
2371  context.boundParams = root->glob->boundParams; /* bound Params */
2372  else
2373  context.boundParams = NULL;
2374  context.root = root; /* for inlined-function dependencies */
2375  context.active_fns = NIL; /* nothing being recursively simplified */
2376  context.case_val = NULL; /* no CASE being examined */
2377  context.estimate = false; /* safe transformations only */
2378  return eval_const_expressions_mutator(node, &context);
2379 }
#define NIL
Definition: pg_list.h:69
static Node * eval_const_expressions_mutator(Node *node, eval_const_expressions_context *context)
Definition: clauses.c:2413
ParamListInfo boundParams
Definition: clauses.c:65
PlannerGlobal * glob
Definition: relation.h:154
#define NULL
Definition: c.h:226
ParamListInfo boundParams
Definition: relation.h:96
double expression_returns_set_rows ( Node clause)

Definition at line 801 of file clauses.c.

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

Referenced by create_set_projection_path(), and set_function_size_estimates().

802 {
803  if (clause == NULL)
804  return 1.0;
805  if (IsA(clause, FuncExpr))
806  {
807  FuncExpr *expr = (FuncExpr *) clause;
808 
809  if (expr->funcretset)
810  return clamp_row_est(get_func_rows(expr->funcid));
811  }
812  if (IsA(clause, OpExpr))
813  {
814  OpExpr *expr = (OpExpr *) clause;
815 
816  if (expr->opretset)
817  {
818  set_opfuncid(expr);
819  return clamp_row_est(get_func_rows(expr->opfuncid));
820  }
821  }
822  return 1.0;
823 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:559
float4 get_func_rows(Oid funcid)
Definition: lsyscache.c:1628
bool funcretset
Definition: primnodes.h:428
Oid funcid
Definition: primnodes.h:426
Oid opfuncid
Definition: primnodes.h:474
#define NULL
Definition: c.h:226
void set_opfuncid(OpExpr *opexpr)
Definition: nodeFuncs.c:1622
double clamp_row_est(double nrows)
Definition: costsize.c:172
bool opretset
Definition: primnodes.h:476
Var* find_forced_null_var ( Node clause)

Definition at line 2031 of file clauses.c.

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

Referenced by check_redundant_nullability_qual(), and find_forced_null_vars().

2032 {
2033  if (node == NULL)
2034  return NULL;
2035  if (IsA(node, NullTest))
2036  {
2037  /* check for var IS NULL */
2038  NullTest *expr = (NullTest *) node;
2039 
2040  if (expr->nulltesttype == IS_NULL && !expr->argisrow)
2041  {
2042  Var *var = (Var *) expr->arg;
2043 
2044  if (var && IsA(var, Var) &&
2045  var->varlevelsup == 0)
2046  return var;
2047  }
2048  }
2049  else if (IsA(node, BooleanTest))
2050  {
2051  /* var IS UNKNOWN is equivalent to var IS NULL */
2052  BooleanTest *expr = (BooleanTest *) node;
2053 
2054  if (expr->booltesttype == IS_UNKNOWN)
2055  {
2056  Var *var = (Var *) expr->arg;
2057 
2058  if (var && IsA(var, Var) &&
2059  var->varlevelsup == 0)
2060  return var;
2061  }
2062  }
2063  return NULL;
2064 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:559
Index varlevelsup
Definition: primnodes.h:151
Definition: primnodes.h:141
Expr * arg
Definition: primnodes.h:1156
Expr * arg
Definition: primnodes.h:1179
BoolTestType booltesttype
Definition: primnodes.h:1180
NullTestType nulltesttype
Definition: primnodes.h:1157
#define NULL
Definition: c.h:226
bool argisrow
Definition: primnodes.h:1158
List* find_forced_null_vars ( Node clause)

Definition at line 1972 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, NIL, and NULL.

Referenced by find_forced_null_vars(), and reduce_outer_joins_pass2().

1973 {
1974  List *result = NIL;
1975  Var *var;
1976  ListCell *l;
1977 
1978  if (node == NULL)
1979  return NIL;
1980  /* Check single-clause cases using subroutine */
1981  var = find_forced_null_var(node);
1982  if (var)
1983  {
1984  result = list_make1(var);
1985  }
1986  /* Otherwise, handle AND-conditions */
1987  else if (IsA(node, List))
1988  {
1989  /*
1990  * At top level, we are examining an implicit-AND list: if any of the
1991  * arms produces FALSE-or-NULL then the result is FALSE-or-NULL.
1992  */
1993  foreach(l, (List *) node)
1994  {
1995  result = list_concat(result,
1997  }
1998  }
1999  else if (IsA(node, BoolExpr))
2000  {
2001  BoolExpr *expr = (BoolExpr *) node;
2002 
2003  /*
2004  * We don't bother considering the OR case, because it's fairly
2005  * unlikely anyone would write "v1 IS NULL OR v1 IS NULL". Likewise,
2006  * the NOT case isn't worth expending code on.
2007  */
2008  if (expr->boolop == AND_EXPR)
2009  {
2010  /* At top level we can just recurse (to the List case) */
2011  result = find_forced_null_vars((Node *) expr->args);
2012  }
2013  }
2014  return result;
2015 }
#define NIL
Definition: pg_list.h:69
#define IsA(nodeptr, _type_)
Definition: nodes.h:559
Definition: nodes.h:508
List * list_concat(List *list1, List *list2)
Definition: list.c:321
Definition: primnodes.h:141
List * find_forced_null_vars(Node *node)
Definition: clauses.c:1972
#define list_make1(x1)
Definition: pg_list.h:133
BoolExprType boolop
Definition: primnodes.h:539
#define NULL
Definition: c.h:226
#define lfirst(lc)
Definition: pg_list.h:106
List * args
Definition: primnodes.h:540
Definition: pg_list.h:45
Var * find_forced_null_var(Node *node)
Definition: clauses.c:2031
Relids find_nonnullable_rels ( Node clause)

Definition at line 1571 of file clauses.c.

References find_nonnullable_rels_walker().

Referenced by make_outerjoininfo(), and reduce_outer_joins_pass2().

1572 {
1573  return find_nonnullable_rels_walker(clause, true);
1574 }
static Relids find_nonnullable_rels_walker(Node *node, bool top_level)
Definition: clauses.c:1577
List* find_nonnullable_vars ( Node clause)

Definition at line 1779 of file clauses.c.

References find_nonnullable_vars_walker().

Referenced by reduce_outer_joins_pass2().

1780 {
1781  return find_nonnullable_vars_walker(clause, true);
1782 }
static List * find_nonnullable_vars_walker(Node *node, bool top_level)
Definition: clauses.c:1785
WindowFuncLists* find_window_functions ( Node clause,
Index  maxWinRef 
)

Definition at line 739 of file clauses.c.

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

Referenced by grouping_planner().

740 {
741  WindowFuncLists *lists = palloc(sizeof(WindowFuncLists));
742 
743  lists->numWindowFuncs = 0;
744  lists->maxWinRef = maxWinRef;
745  lists->windowFuncs = (List **) palloc0((maxWinRef + 1) * sizeof(List *));
746  (void) find_window_functions_walker(clause, lists);
747  return lists;
748 }
Index maxWinRef
Definition: clauses.h:26
int numWindowFuncs
Definition: clauses.h:25
void * palloc0(Size size)
Definition: mcxt.c:920
void * palloc(Size size)
Definition: mcxt.c:891
static bool find_window_functions_walker(Node *node, WindowFuncLists *lists)
Definition: clauses.c:751
Definition: pg_list.h:45
List ** windowFuncs
Definition: clauses.h:27
void get_agg_clause_costs ( PlannerInfo root,
Node clause,
AggSplit  aggsplit,
AggClauseCosts costs 
)

Definition at line 466 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().

468 {
470 
471  context.root = root;
472  context.aggsplit = aggsplit;
473  context.costs = costs;
474  (void) get_agg_clause_costs_walker(clause, &context);
475 }
AggClauseCosts * costs
Definition: clauses.c:60
static bool get_agg_clause_costs_walker(Node *node, get_agg_clause_costs_context *context)
Definition: clauses.c:478
Expr* get_notclausearg ( Expr notclause)

Definition at line 264 of file clauses.c.

References generate_unaccent_rules::args, and linitial.

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

265 {
266  return linitial(((BoolExpr *) notclause)->args);
267 }
#define linitial(l)
Definition: pg_list.h:110
Query* inline_set_returning_function ( PlannerInfo root,
RangeTblEntry rte 
)

Definition at line 4732 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::funcresulttype, FuncExpr::funcretset, RangeTblEntry::functions, get_func_result_type(), get_typtype(), GETSTRUCT, GetUserId(), PlannerInfo::glob, heap_attisnull(), HeapTupleIsValid, FuncExpr::inputcollid, PlannerGlobal::invalItems, IsA, linitial, list_concat(), list_length(), MemoryContextDelete(), MemoryContextSwitchTo(), NameStr, NIL, NULL, 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().

4733 {
4734  RangeTblFunction *rtfunc;
4735  FuncExpr *fexpr;
4736  Oid func_oid;
4737  HeapTuple func_tuple;
4738  Form_pg_proc funcform;
4739  char *src;
4740  Datum tmp;
4741  bool isNull;
4742  bool modifyTargetList;
4743  MemoryContext oldcxt;
4744  MemoryContext mycxt;
4745  List *saveInvalItems;
4746  inline_error_callback_arg callback_arg;
4747  ErrorContextCallback sqlerrcontext;
4749  List *raw_parsetree_list;
4750  List *querytree_list;
4751  Query *querytree;
4752 
4753  Assert(rte->rtekind == RTE_FUNCTION);
4754 
4755  /*
4756  * It doesn't make a lot of sense for a SQL SRF to refer to itself in its
4757  * own FROM clause, since that must cause infinite recursion at runtime.
4758  * It will cause this code to recurse too, so check for stack overflow.
4759  * (There's no need to do more.)
4760  */
4762 
4763  /* Fail if the RTE has ORDINALITY - we don't implement that here. */
4764  if (rte->funcordinality)
4765  return NULL;
4766 
4767  /* Fail if RTE isn't a single, simple FuncExpr */
4768  if (list_length(rte->functions) != 1)
4769  return NULL;
4770  rtfunc = (RangeTblFunction *) linitial(rte->functions);
4771 
4772  if (!IsA(rtfunc->funcexpr, FuncExpr))
4773  return NULL;
4774  fexpr = (FuncExpr *) rtfunc->funcexpr;
4775 
4776  func_oid = fexpr->funcid;
4777 
4778  /*
4779  * The function must be declared to return a set, else inlining would
4780  * change the results if the contained SELECT didn't return exactly one
4781  * row.
4782  */
4783  if (!fexpr->funcretset)
4784  return NULL;
4785 
4786  /*
4787  * Refuse to inline if the arguments contain any volatile functions or
4788  * sub-selects. Volatile functions are rejected because inlining may
4789  * result in the arguments being evaluated multiple times, risking a
4790  * change in behavior. Sub-selects are rejected partly for implementation
4791  * reasons (pushing them down another level might change their behavior)
4792  * and partly because they're likely to be expensive and so multiple
4793  * evaluation would be bad.
4794  */
4795  if (contain_volatile_functions((Node *) fexpr->args) ||
4796  contain_subplans((Node *) fexpr->args))
4797  return NULL;
4798 
4799  /* Check permission to call function (fail later, if not) */
4800  if (pg_proc_aclcheck(func_oid, GetUserId(), ACL_EXECUTE) != ACLCHECK_OK)
4801  return NULL;
4802 
4803  /* Check whether a plugin wants to hook function entry/exit */
4804  if (FmgrHookIsNeeded(func_oid))
4805  return NULL;
4806 
4807  /*
4808  * OK, let's take a look at the function's pg_proc entry.
4809  */
4810  func_tuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(func_oid));
4811  if (!HeapTupleIsValid(func_tuple))
4812  elog(ERROR, "cache lookup failed for function %u", func_oid);
4813  funcform = (Form_pg_proc) GETSTRUCT(func_tuple);
4814 
4815  /*
4816  * Forget it if the function is not SQL-language or has other showstopper
4817  * properties. In particular it mustn't be declared STRICT, since we
4818  * couldn't enforce that. It also mustn't be VOLATILE, because that is
4819  * supposed to cause it to be executed with its own snapshot, rather than
4820  * sharing the snapshot of the calling query. (Rechecking proretset is
4821  * just paranoia.)
4822  */
4823  if (funcform->prolang != SQLlanguageId ||
4824  funcform->proisstrict ||
4825  funcform->provolatile == PROVOLATILE_VOLATILE ||
4826  funcform->prosecdef ||
4827  !funcform->proretset ||
4828  !heap_attisnull(func_tuple, Anum_pg_proc_proconfig))
4829  {
4830  ReleaseSysCache(func_tuple);
4831  return NULL;
4832  }
4833 
4834  /*
4835  * Make a temporary memory context, so that we don't leak all the stuff
4836  * that parsing might create.
4837  */
4839  "inline_set_returning_function",
4841  oldcxt = MemoryContextSwitchTo(mycxt);
4842 
4843  /*
4844  * When we call eval_const_expressions below, it might try to add items to
4845  * root->glob->invalItems. Since it is running in the temp context, those
4846  * items will be in that context, and will need to be copied out if we're
4847  * successful. Temporarily reset the list so that we can keep those items
4848  * separate from the pre-existing list contents.
4849  */
4850  saveInvalItems = root->glob->invalItems;
4851  root->glob->invalItems = NIL;
4852 
4853  /* Fetch the function body */
4854  tmp = SysCacheGetAttr(PROCOID,
4855  func_tuple,
4857  &isNull);
4858  if (isNull)
4859  elog(ERROR, "null prosrc for function %u", func_oid);
4860  src = TextDatumGetCString(tmp);
4861 
4862  /*
4863  * Setup error traceback support for ereport(). This is so that we can
4864  * finger the function that bad information came from.
4865  */
4866  callback_arg.proname = NameStr(funcform->proname);
4867  callback_arg.prosrc = src;
4868 
4869  sqlerrcontext.callback = sql_inline_error_callback;
4870  sqlerrcontext.arg = (void *) &callback_arg;
4871  sqlerrcontext.previous = error_context_stack;
4872  error_context_stack = &sqlerrcontext;
4873 
4874  /*
4875  * Run eval_const_expressions on the function call. This is necessary to
4876  * ensure that named-argument notation is converted to positional notation
4877  * and any default arguments are inserted. It's a bit of overkill for the
4878  * arguments, since they'll get processed again later, but no harm will be
4879  * done.
4880  */
4881  fexpr = (FuncExpr *) eval_const_expressions(root, (Node *) fexpr);
4882 
4883  /* It should still be a call of the same function, but let's check */
4884  if (!IsA(fexpr, FuncExpr) ||
4885  fexpr->funcid != func_oid)
4886  goto fail;
4887 
4888  /* Arg list length should now match the function */
4889  if (list_length(fexpr->args) != funcform->pronargs)
4890  goto fail;
4891 
4892  /*
4893  * Set up to handle parameters while parsing the function body. We can
4894  * use the FuncExpr just created as the input for
4895  * prepare_sql_fn_parse_info.
4896  */
4897  pinfo = prepare_sql_fn_parse_info(func_tuple,
4898  (Node *) fexpr,
4899  fexpr->inputcollid);
4900 
4901  /*
4902  * Parse, analyze, and rewrite (unlike inline_function(), we can't skip
4903  * rewriting here). We can fail as soon as we find more than one query,
4904  * though.
4905  */
4906  raw_parsetree_list = pg_parse_query(src);
4907  if (list_length(raw_parsetree_list) != 1)
4908  goto fail;
4909 
4910  querytree_list = pg_analyze_and_rewrite_params(linitial(raw_parsetree_list),
4911  src,
4913  pinfo);
4914  if (list_length(querytree_list) != 1)
4915  goto fail;
4916  querytree = linitial(querytree_list);
4917 
4918  /*
4919  * The single command must be a plain SELECT.
4920  */
4921  if (!IsA(querytree, Query) ||
4922  querytree->commandType != CMD_SELECT)
4923  goto fail;
4924 
4925  /*
4926  * Make sure the function (still) returns what it's declared to. This
4927  * will raise an error if wrong, but that's okay since the function would
4928  * fail at runtime anyway. Note that check_sql_fn_retval will also insert
4929  * RelabelType(s) and/or NULL columns if needed to make the tlist
4930  * expression(s) match the declared type of the function.
4931  *
4932  * If the function returns a composite type, don't inline unless the check
4933  * shows it's returning a whole tuple result; otherwise what it's
4934  * returning is a single composite column which is not what we need.
4935  */
4936  if (!check_sql_fn_retval(func_oid, fexpr->funcresulttype,
4937  querytree_list,
4938  &modifyTargetList, NULL) &&
4940  fexpr->funcresulttype == RECORDOID))
4941  goto fail; /* reject not-whole-tuple-result cases */
4942 
4943  /*
4944  * If we had to modify the tlist to make it match, and the statement is
4945  * one in which changing the tlist contents could change semantics, we
4946  * have to punt and not inline.
4947  */
4948  if (modifyTargetList)
4949  goto fail;
4950 
4951  /*
4952  * If it returns RECORD, we have to check against the column type list
4953  * provided in the RTE; check_sql_fn_retval can't do that. (If no match,
4954  * we just fail to inline, rather than complaining; see notes for
4955  * tlist_matches_coltypelist.) We don't have to do this for functions
4956  * with declared OUT parameters, even though their funcresulttype is
4957  * RECORDOID, so check get_func_result_type too.
4958  */
4959  if (fexpr->funcresulttype == RECORDOID &&
4960  get_func_result_type(func_oid, NULL, NULL) == TYPEFUNC_RECORD &&
4962  rtfunc->funccoltypes))
4963  goto fail;
4964 
4965  /*
4966  * Looks good --- substitute parameters into the query.
4967  */
4968  querytree = substitute_actual_srf_parameters(querytree,
4969  funcform->pronargs,
4970  fexpr->args);
4971 
4972  /*
4973  * Copy the modified query out of the temporary memory context, and clean
4974  * up.
4975  */
4976  MemoryContextSwitchTo(oldcxt);
4977 
4978  querytree = copyObject(querytree);
4979 
4980  /* copy up any new invalItems, too */
4981  root->glob->invalItems = list_concat(saveInvalItems,
4982  copyObject(root->glob->invalItems));
4983 
4984  MemoryContextDelete(mycxt);
4985  error_context_stack = sqlerrcontext.previous;
4986  ReleaseSysCache(func_tuple);
4987 
4988  /*
4989  * We don't have to fix collations here because the upper query is already
4990  * parsed, ie, the collations in the RTE are what count.
4991  */
4992 
4993  /*
4994  * Since there is now no trace of the function in the plan tree, we must
4995  * explicitly record the plan's dependency on the function.
4996  */
4997  record_plan_function_dependency(root, func_oid);
4998 
4999  return querytree;
5000 
5001  /* Here if func is not inlinable: release temp memory and return NULL */
5002 fail:
5003  MemoryContextSwitchTo(oldcxt);
5004  root->glob->invalItems = saveInvalItems;
5005  MemoryContextDelete(mycxt);
5006  error_context_stack = sqlerrcontext.previous;
5007  ReleaseSysCache(func_tuple);
5008 
5009  return NULL;
5010 }
Oid funcresulttype
Definition: primnodes.h:427
#define NIL
Definition: pg_list.h:69
#define IsA(nodeptr, _type_)
Definition: nodes.h:559
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:200
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
List * args
Definition: primnodes.h:434
Oid GetUserId(void)
Definition: miscinit.c:283
#define TYPTYPE_COMPOSITE
Definition: pg_type.h:709
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:508
bool check_sql_fn_retval(Oid func_id, Oid rettype, List *queryTreeList, bool *modifyTargetList, JunkFilter **junkFilter)
Definition: functions.c:1527
char get_typtype(Oid typid)
Definition: lsyscache.c:2347
Node * eval_const_expressions(PlannerInfo *root, Node *node)
Definition: clauses.c:2366
List * list_concat(List *list1, List *list2)
Definition: list.c:321
bool funcretset
Definition: primnodes.h:428
bool contain_volatile_functions(Node *clause)
Definition: clauses.c:950
bool funcordinality
Definition: parsenodes.h:932
unsigned int Oid
Definition: postgres_ext.h:31
struct ErrorContextCallback * previous
Definition: elog.h:238
#define FmgrHookIsNeeded(fn_oid)
Definition: fmgr.h:699
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:149
#define Anum_pg_proc_proconfig
Definition: pg_proc.h:117
List * targetList
Definition: parsenodes.h:131
void * copyObject(const void *from)
Definition: copyfuncs.c:4475
ErrorContextCallback * error_context_stack
Definition: elog.c:88
bool contain_subplans(Node *clause)
Definition: clauses.c:842
#define linitial(l)
Definition: pg_list.h:110
Oid funcid
Definition: primnodes.h:426
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define ERROR
Definition: elog.h:43
#define SQLlanguageId
Definition: pg_language.h:80
List * pg_parse_query(const char *query_string)
Definition: postgres.c:602
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:145
void check_stack_depth(void)
Definition: postgres.c:3096
PlannerGlobal * glob
Definition: relation.h:154
bool heap_attisnull(HeapTuple tup, int attnum)
Definition: heaptuple.c:297
void(* ParserSetupHook)(struct ParseState *pstate, void *arg)
Definition: params.h:66
#define RECORDOID
Definition: pg_type.h:668
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
List * pg_analyze_and_rewrite_params(RawStmt *parsetree, const char *query_string, ParserSetupHook parserSetup, void *parserSetupArg)
Definition: postgres.c:679
#define PROVOLATILE_VOLATILE
Definition: pg_proc.h:5374
TypeFuncClass get_func_result_type(Oid functionId, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:269
static void sql_inline_error_callback(void *arg)
Definition: clauses.c:4620
List * invalItems
Definition: relation.h:112
#define TextDatumGetCString(d)
Definition: builtins.h:91
MemoryContext AllocSetContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: aset.c:440
uintptr_t Datum
Definition: postgres.h:374
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1083
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1245
void record_plan_function_dependency(PlannerInfo *root, Oid funcid)
Definition: setrefs.c:2437
static Query * substitute_actual_srf_parameters(Query *expr, int nargs, List *args)
Definition: clauses.c:5019
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:83
CmdType commandType
Definition: parsenodes.h:103
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
Oid inputcollid
Definition: primnodes.h:433
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
List * functions
Definition: parsenodes.h:931
static int list_length(const List *l)
Definition: pg_list.h:89
Datum querytree(PG_FUNCTION_ARGS)
Definition: _int_bool.c:665
RTEKind rtekind
Definition: parsenodes.h:882
static bool tlist_matches_coltypelist(List *tlist, List *coltypelist)
Definition: clauses.c:5087
void(* callback)(void *arg)
Definition: elog.h:239
#define ACL_EXECUTE
Definition: parsenodes.h:72
AclResult pg_proc_aclcheck(Oid proc_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4421
List * funccoltypes
Definition: parsenodes.h:997
#define NameStr(name)
Definition: c.h:495
#define elog
Definition: elog.h:219
SQLFunctionParseInfoPtr prepare_sql_fn_parse_info(HeapTuple procedureTuple, Node *call_expr, Oid inputCollation)
Definition: functions.c:184
Definition: pg_list.h:45
bool is_parallel_safe ( PlannerInfo root,
Node node 
)

Definition at line 1071 of file clauses.c.

References PlannerInfo::glob, max_parallel_hazard_context::max_hazard, max_parallel_hazard_context::max_interesting, max_parallel_hazard_walker(), PlannerGlobal::maxParallelHazard, PlannerGlobal::nParamExec, PROPARALLEL_RESTRICTED, and PROPARALLEL_SAFE.

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().

1072 {
1074 
1075  /*
1076  * Even if the original querytree contained nothing unsafe, we need to
1077  * search the expression if we have generated any PARAM_EXEC Params while
1078  * planning, because those are parallel-restricted and there might be one
1079  * in this expression. But otherwise we don't need to look.
1080  */
1081  if (root->glob->maxParallelHazard == PROPARALLEL_SAFE &&
1082  root->glob->nParamExec == 0)
1083  return true;
1084  /* Else use max_parallel_hazard's search logic, but stop on RESTRICTED */
1085  context.max_hazard = PROPARALLEL_SAFE;
1087  return !max_parallel_hazard_walker(node, &context);
1088 }
char maxParallelHazard
Definition: relation.h:130
#define PROPARALLEL_RESTRICTED
Definition: pg_proc.h:5382
static bool max_parallel_hazard_walker(Node *node, max_parallel_hazard_context *context)
Definition: clauses.c:1127
PlannerGlobal * glob
Definition: relation.h:154
#define PROPARALLEL_SAFE
Definition: pg_proc.h:5381
int nParamExec
Definition: relation.h:114
bool is_pseudo_constant_clause ( Node clause)

Definition at line 2141 of file clauses.c.

References contain_var_clause(), and contain_volatile_functions().

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

2142 {
2143  /*
2144  * We could implement this check in one recursive scan. But since the
2145  * check for volatile functions is both moderately expensive and unlikely
2146  * to fail, it seems better to look for Vars first and only check for
2147  * volatile functions if we find no Vars.
2148  */
2149  if (!contain_var_clause(clause) &&
2150  !contain_volatile_functions(clause))
2151  return true;
2152  return false;
2153 }
bool contain_var_clause(Node *node)
Definition: var.c:331
bool contain_volatile_functions(Node *clause)
Definition: clauses.c:950
bool is_pseudo_constant_clause_relids ( Node clause,
Relids  relids 
)

Definition at line 2161 of file clauses.c.

References bms_is_empty(), and contain_volatile_functions().

Referenced by clauselist_selectivity().

2162 {
2163  if (bms_is_empty(relids) &&
2164  !contain_volatile_functions(clause))
2165  return true;
2166  return false;
2167 }
bool contain_volatile_functions(Node *clause)
Definition: clauses.c:950
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:633
Node* make_and_qual ( Node qual1,
Node qual2 
)

Definition at line 347 of file clauses.c.

References list_make2, make_andclause(), and NULL.

Referenced by AddQual(), and subquery_push_qual().

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

Definition at line 326 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().

327 {
328  BoolExpr *expr = makeNode(BoolExpr);
329 
330  expr->boolop = AND_EXPR;
331  expr->args = andclauses;
332  expr->location = -1;
333  return (Expr *) expr;
334 }
int location
Definition: primnodes.h:541
BoolExprType boolop
Definition: primnodes.h:539
#define makeNode(_type_)
Definition: nodes.h:556
List * args
Definition: primnodes.h:540
Expr* make_ands_explicit ( List andclauses)

Definition at line 366 of file clauses.c.

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

Referenced by ATExecAttachPartition(), convert_EXISTS_to_ANY(), create_bitmap_subplan(), extract_or_clause(), show_qual(), and UpdateIndexRelation().

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

Definition at line 377 of file clauses.c.

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

Referenced by ATAddCheckConstraint(), ATExecAttachPartition(), convert_EXISTS_to_ANY(), cost_subplan(), DefineIndex(), ExecRelCheck(), get_relation_constraints(), preprocess_expression(), RelationGetIndexPredicate(), set_append_rel_size(), TriggerEnabled(), and validateCheckConstraint().

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

Definition at line 248 of file clauses.c.

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

Referenced by negate_clause().

249 {
250  BoolExpr *expr = makeNode(BoolExpr);
251 
252  expr->boolop = NOT_EXPR;
253  expr->args = list_make1(notclause);
254  expr->location = -1;
255  return (Expr *) expr;
256 }
int location
Definition: primnodes.h:541
#define list_make1(x1)
Definition: pg_list.h:133
BoolExprType boolop
Definition: primnodes.h:539
#define makeNode(_type_)
Definition: nodes.h:556
List * args
Definition: primnodes.h:540
Expr* make_opclause ( Oid  opno,
Oid  opresulttype,
bool  opretset,
Expr leftop,
Expr rightop,
Oid  opcollid,
Oid  inputcollid 
)

Definition at line 171 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(), get_qual_for_range(), network_prefix_quals(), operator_predicate_proof(), prefix_quals(), and process_implied_equality().

174 {
175  OpExpr *expr = makeNode(OpExpr);
176 
177  expr->opno = opno;
178  expr->opfuncid = InvalidOid;
179  expr->opresulttype = opresulttype;
180  expr->opretset = opretset;
181  expr->opcollid = opcollid;
182  expr->inputcollid = inputcollid;
183  if (rightop)
184  expr->args = list_make2(leftop, rightop);
185  else
186  expr->args = list_make1(leftop);
187  expr->location = -1;
188  return (Expr *) expr;
189 }
#define list_make2(x1, x2)
Definition: pg_list.h:134
#define list_make1(x1)
Definition: pg_list.h:133
Oid opresulttype
Definition: primnodes.h:475
int location
Definition: primnodes.h:480
Oid opcollid
Definition: primnodes.h:477
Oid opfuncid
Definition: primnodes.h:474
#define InvalidOid
Definition: postgres_ext.h:36
#define makeNode(_type_)
Definition: nodes.h:556
Oid inputcollid
Definition: primnodes.h:478
Oid opno
Definition: primnodes.h:473
List * args
Definition: primnodes.h:479
bool opretset
Definition: primnodes.h:476
Expr* make_orclause ( List orclauses)

Definition at line 292 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().

293 {
294  BoolExpr *expr = makeNode(BoolExpr);
295 
296  expr->boolop = OR_EXPR;
297  expr->args = orclauses;
298  expr->location = -1;
299  return (Expr *) expr;
300 }
int location
Definition: primnodes.h:541
BoolExprType boolop
Definition: primnodes.h:539
#define makeNode(_type_)
Definition: nodes.h:556
List * args
Definition: primnodes.h:540
char max_parallel_hazard ( Query parse)

Definition at line 1053 of file clauses.c.

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

Referenced by standard_planner().

1054 {
1056 
1057  context.max_hazard = PROPARALLEL_SAFE;
1059  (void) max_parallel_hazard_walker((Node *) parse, &context);
1060  return context.max_hazard;
1061 }
Definition: nodes.h:508
static bool max_parallel_hazard_walker(Node *node, max_parallel_hazard_context *context)
Definition: clauses.c:1127
#define PROPARALLEL_SAFE
Definition: pg_proc.h:5381
#define PROPARALLEL_UNSAFE
Definition: pg_proc.h:5383
static struct subre * parse(struct vars *, int, int, struct state *, struct state *)
Definition: regcomp.c:651
bool not_clause ( Node clause)

Definition at line 235 of file clauses.c.

References boolop(), IsA, NOT_EXPR, and NULL.

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

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

Definition at line 2183 of file clauses.c.

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

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

2184 {
2185  Relids varnos = pull_varnos(clause);
2186  int result = bms_num_members(varnos);
2187 
2188  bms_free(varnos);
2189  return result;
2190 }
int bms_num_members(const Bitmapset *a)
Definition: bitmapset.c:575
Relids pull_varnos(Node *node)
Definition: var.c:95
void bms_free(Bitmapset *a)
Definition: bitmapset.c:200
bool or_clause ( Node clause)

Definition at line 279 of file clauses.c.

References boolop(), IsA, NULL, 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().

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