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

2233 {
2234  Oid opoid;
2235  Node *temp;
2236 
2237  /* Sanity checks: caller is at fault if these fail */
2238  if (!is_opclause(clause) ||
2239  list_length(clause->args) != 2)
2240  elog(ERROR, "cannot commute non-binary-operator clause");
2241 
2242  opoid = get_commutator(clause->opno);
2243 
2244  if (!OidIsValid(opoid))
2245  elog(ERROR, "could not find commutator for operator %u",
2246  clause->opno);
2247 
2248  /*
2249  * modify the clause in-place!
2250  */
2251  clause->opno = opoid;
2252  clause->opfuncid = InvalidOid;
2253  /* opresulttype, opretset, opcollid, inputcollid need not change */
2254 
2255  temp = linitial(clause->args);
2256  linitial(clause->args) = lsecond(clause->args);
2257  lsecond(clause->args) = temp;
2258 }
Oid get_commutator(Oid opno)
Definition: lsyscache.c:1313
Definition: nodes.h:509
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:538
#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
void CommuteRowCompareExpr ( RowCompareExpr clause)

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

2267 {
2268  List *newops;
2269  List *temp;
2270  ListCell *l;
2271 
2272  /* Sanity checks: caller is at fault if these fail */
2273  if (!IsA(clause, RowCompareExpr))
2274  elog(ERROR, "expected a RowCompareExpr");
2275 
2276  /* Build list of commuted operators */
2277  newops = NIL;
2278  foreach(l, clause->opnos)
2279  {
2280  Oid opoid = lfirst_oid(l);
2281 
2282  opoid = get_commutator(opoid);
2283  if (!OidIsValid(opoid))
2284  elog(ERROR, "could not find commutator for operator %u",
2285  lfirst_oid(l));
2286  newops = lappend_oid(newops, opoid);
2287  }
2288 
2289  /*
2290  * modify the clause in-place!
2291  */
2292  switch (clause->rctype)
2293  {
2294  case ROWCOMPARE_LT:
2295  clause->rctype = ROWCOMPARE_GT;
2296  break;
2297  case ROWCOMPARE_LE:
2298  clause->rctype = ROWCOMPARE_GE;
2299  break;
2300  case ROWCOMPARE_GE:
2301  clause->rctype = ROWCOMPARE_LE;
2302  break;
2303  case ROWCOMPARE_GT:
2304  clause->rctype = ROWCOMPARE_LT;
2305  break;
2306  default:
2307  elog(ERROR, "unexpected RowCompare type: %d",
2308  (int) clause->rctype);
2309  break;
2310  }
2311 
2312  clause->opnos = newops;
2313 
2314  /*
2315  * Note: we need not change the opfamilies list; we assume any btree
2316  * opfamily containing an operator will also contain its commutator.
2317  * Collations don't change either.
2318  */
2319 
2320  temp = clause->largs;
2321  clause->largs = clause->rargs;
2322  clause->rargs = temp;
2323 }
#define NIL
Definition: pg_list.h:69
#define IsA(nodeptr, _type_)
Definition: nodes.h:560
Oid get_commutator(Oid opno)
Definition: lsyscache.c:1313
RowCompareType rctype
Definition: primnodes.h:1031
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:538
#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 417 of file clauses.c.

References contain_agg_clause_walker(), and NULL.

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
#define NULL
Definition: c.h:229
bool contain_leaked_vars ( Node clause)

Definition at line 1461 of file clauses.c.

References contain_leaked_vars_walker(), and NULL.

Referenced by make_restrictinfo_internal(), and qual_is_pushdown_safe().

1462 {
1463  return contain_leaked_vars_walker(clause, NULL);
1464 }
#define NULL
Definition: c.h:229
static bool contain_leaked_vars_walker(Node *node, void *context)
Definition: clauses.c:1473
bool contain_mutable_functions ( Node clause)

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

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

Definition at line 1268 of file clauses.c.

References contain_nonstrict_functions_walker(), and NULL.

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

1269 {
1270  return contain_nonstrict_functions_walker(clause, NULL);
1271 }
static bool contain_nonstrict_functions_walker(Node *node, void *context)
Definition: clauses.c:1280
#define NULL
Definition: c.h:229
bool contain_subplans ( Node clause)

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

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

Definition at line 995 of file clauses.c.

References contain_volatile_functions_not_nextval_walker(), and NULL.

Referenced by BeginCopyFrom().

996 {
998 }
static bool contain_volatile_functions_not_nextval_walker(Node *node, void *context)
Definition: clauses.c:1008
#define NULL
Definition: c.h:229
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
Node* estimate_expression_value ( PlannerInfo root,
Node node 
)

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

2434 {
2436 
2437  context.boundParams = root->glob->boundParams; /* bound Params */
2438  /* we do not need to mark the plan as depending on inlined functions */
2439  context.root = NULL;
2440  context.active_fns = NIL; /* nothing being recursively simplified */
2441  context.case_val = NULL; /* no CASE being examined */
2442  context.estimate = true; /* unsafe transformations OK */
2443  return eval_const_expressions_mutator(node, &context);
2444 }
#define NIL
Definition: pg_list.h:69
static Node * eval_const_expressions_mutator(Node *node, eval_const_expressions_context *context)
Definition: clauses.c:2447
ParamListInfo boundParams
Definition: clauses.c:65
PlannerGlobal * glob
Definition: relation.h:157
#define NULL
Definition: c.h:229
ParamListInfo boundParams
Definition: relation.h:96
Node* eval_const_expressions ( PlannerInfo root,
Node node 
)

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

2401 {
2403 
2404  if (root)
2405  context.boundParams = root->glob->boundParams; /* bound Params */
2406  else
2407  context.boundParams = NULL;
2408  context.root = root; /* for inlined-function dependencies */
2409  context.active_fns = NIL; /* nothing being recursively simplified */
2410  context.case_val = NULL; /* no CASE being examined */
2411  context.estimate = false; /* safe transformations only */
2412  return eval_const_expressions_mutator(node, &context);
2413 }
#define NIL
Definition: pg_list.h:69
static Node * eval_const_expressions_mutator(Node *node, eval_const_expressions_context *context)
Definition: clauses.c:2447
ParamListInfo boundParams
Definition: clauses.c:65
PlannerGlobal * glob
Definition: relation.h:157
#define NULL
Definition: c.h:229
ParamListInfo boundParams
Definition: relation.h:96
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, NULL, OpExpr::opfuncid, OpExpr::opretset, and set_opfuncid().

Referenced by create_set_projection_path(), 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:560
float4 get_func_rows(Oid funcid)
Definition: lsyscache.c:1660
bool funcretset
Definition: primnodes.h:451
Oid funcid
Definition: primnodes.h:449
Oid opfuncid
Definition: primnodes.h:497
#define NULL
Definition: c.h:229
void set_opfuncid(OpExpr *opexpr)
Definition: nodeFuncs.c:1613
double clamp_row_est(double nrows)
Definition: costsize.c:173
bool opretset
Definition: primnodes.h:499
Var* find_forced_null_var ( Node clause)

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

2066 {
2067  if (node == NULL)
2068  return NULL;
2069  if (IsA(node, NullTest))
2070  {
2071  /* check for var IS NULL */
2072  NullTest *expr = (NullTest *) node;
2073 
2074  if (expr->nulltesttype == IS_NULL && !expr->argisrow)
2075  {
2076  Var *var = (Var *) expr->arg;
2077 
2078  if (var && IsA(var, Var) &&
2079  var->varlevelsup == 0)
2080  return var;
2081  }
2082  }
2083  else if (IsA(node, BooleanTest))
2084  {
2085  /* var IS UNKNOWN is equivalent to var IS NULL */
2086  BooleanTest *expr = (BooleanTest *) node;
2087 
2088  if (expr->booltesttype == IS_UNKNOWN)
2089  {
2090  Var *var = (Var *) expr->arg;
2091 
2092  if (var && IsA(var, Var) &&
2093  var->varlevelsup == 0)
2094  return var;
2095  }
2096  }
2097  return NULL;
2098 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:560
Index varlevelsup
Definition: primnodes.h:173
Definition: primnodes.h:163
Expr * arg
Definition: primnodes.h:1180
Expr * arg
Definition: primnodes.h:1203
BoolTestType booltesttype
Definition: primnodes.h:1204
NullTestType nulltesttype
Definition: primnodes.h:1181
#define NULL
Definition: c.h:229
bool argisrow
Definition: primnodes.h:1182
List* find_forced_null_vars ( Node clause)

Definition at line 2006 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, NULL, and result.

Referenced by find_forced_null_vars(), and reduce_outer_joins_pass2().

2007 {
2008  List *result = NIL;
2009  Var *var;
2010  ListCell *l;
2011 
2012  if (node == NULL)
2013  return NIL;
2014  /* Check single-clause cases using subroutine */
2015  var = find_forced_null_var(node);
2016  if (var)
2017  {
2018  result = list_make1(var);
2019  }
2020  /* Otherwise, handle AND-conditions */
2021  else if (IsA(node, List))
2022  {
2023  /*
2024  * At top level, we are examining an implicit-AND list: if any of the
2025  * arms produces FALSE-or-NULL then the result is FALSE-or-NULL.
2026  */
2027  foreach(l, (List *) node)
2028  {
2029  result = list_concat(result,
2031  }
2032  }
2033  else if (IsA(node, BoolExpr))
2034  {
2035  BoolExpr *expr = (BoolExpr *) node;
2036 
2037  /*
2038  * We don't bother considering the OR case, because it's fairly
2039  * unlikely anyone would write "v1 IS NULL OR v1 IS NULL". Likewise,
2040  * the NOT case isn't worth expending code on.
2041  */
2042  if (expr->boolop == AND_EXPR)
2043  {
2044  /* At top level we can just recurse (to the List case) */
2045  result = find_forced_null_vars((Node *) expr->args);
2046  }
2047  }
2048  return result;
2049 }
#define NIL
Definition: pg_list.h:69
#define IsA(nodeptr, _type_)
Definition: nodes.h:560
Definition: nodes.h:509
List * list_concat(List *list1, List *list2)
Definition: list.c:321
return result
Definition: formatting.c:1633
Definition: primnodes.h:163
List * find_forced_null_vars(Node *node)
Definition: clauses.c:2006
#define list_make1(x1)
Definition: pg_list.h:139
BoolExprType boolop
Definition: primnodes.h:562
#define NULL
Definition: c.h:229
#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:2065
Relids find_nonnullable_rels ( Node clause)

Definition at line 1605 of file clauses.c.

References find_nonnullable_rels_walker().

Referenced by make_outerjoininfo(), and reduce_outer_joins_pass2().

1606 {
1607  return find_nonnullable_rels_walker(clause, true);
1608 }
static Relids find_nonnullable_rels_walker(Node *node, bool top_level)
Definition: clauses.c:1611
List* find_nonnullable_vars ( Node clause)

Definition at line 1813 of file clauses.c.

References find_nonnullable_vars_walker().

Referenced by reduce_outer_joins_pass2().

1814 {
1815  return find_nonnullable_vars_walker(clause, true);
1816 }
static List * find_nonnullable_vars_walker(Node *node, bool top_level)
Definition: clauses.c:1819
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:878
void * palloc(Size size)
Definition: mcxt.c:849
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
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
Expr* get_notclausearg ( Expr notclause)

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

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

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

4767 {
4768  RangeTblFunction *rtfunc;
4769  FuncExpr *fexpr;
4770  Oid func_oid;
4771  HeapTuple func_tuple;
4772  Form_pg_proc funcform;
4773  char *src;
4774  Datum tmp;
4775  bool isNull;
4776  bool modifyTargetList;
4777  MemoryContext oldcxt;
4778  MemoryContext mycxt;
4779  List *saveInvalItems;
4780  inline_error_callback_arg callback_arg;
4781  ErrorContextCallback sqlerrcontext;
4783  List *raw_parsetree_list;
4784  List *querytree_list;
4785  Query *querytree;
4786 
4787  Assert(rte->rtekind == RTE_FUNCTION);
4788 
4789  /*
4790  * It doesn't make a lot of sense for a SQL SRF to refer to itself in its
4791  * own FROM clause, since that must cause infinite recursion at runtime.
4792  * It will cause this code to recurse too, so check for stack overflow.
4793  * (There's no need to do more.)
4794  */
4796 
4797  /* Fail if the RTE has ORDINALITY - we don't implement that here. */
4798  if (rte->funcordinality)
4799  return NULL;
4800 
4801  /* Fail if RTE isn't a single, simple FuncExpr */
4802  if (list_length(rte->functions) != 1)
4803  return NULL;
4804  rtfunc = (RangeTblFunction *) linitial(rte->functions);
4805 
4806  if (!IsA(rtfunc->funcexpr, FuncExpr))
4807  return NULL;
4808  fexpr = (FuncExpr *) rtfunc->funcexpr;
4809 
4810  func_oid = fexpr->funcid;
4811 
4812  /*
4813  * The function must be declared to return a set, else inlining would
4814  * change the results if the contained SELECT didn't return exactly one
4815  * row.
4816  */
4817  if (!fexpr->funcretset)
4818  return NULL;
4819 
4820  /*
4821  * Refuse to inline if the arguments contain any volatile functions or
4822  * sub-selects. Volatile functions are rejected because inlining may
4823  * result in the arguments being evaluated multiple times, risking a
4824  * change in behavior. Sub-selects are rejected partly for implementation
4825  * reasons (pushing them down another level might change their behavior)
4826  * and partly because they're likely to be expensive and so multiple
4827  * evaluation would be bad.
4828  */
4829  if (contain_volatile_functions((Node *) fexpr->args) ||
4830  contain_subplans((Node *) fexpr->args))
4831  return NULL;
4832 
4833  /* Check permission to call function (fail later, if not) */
4834  if (pg_proc_aclcheck(func_oid, GetUserId(), ACL_EXECUTE) != ACLCHECK_OK)
4835  return NULL;
4836 
4837  /* Check whether a plugin wants to hook function entry/exit */
4838  if (FmgrHookIsNeeded(func_oid))
4839  return NULL;
4840 
4841  /*
4842  * OK, let's take a look at the function's pg_proc entry.
4843  */
4844  func_tuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(func_oid));
4845  if (!HeapTupleIsValid(func_tuple))
4846  elog(ERROR, "cache lookup failed for function %u", func_oid);
4847  funcform = (Form_pg_proc) GETSTRUCT(func_tuple);
4848 
4849  /*
4850  * Forget it if the function is not SQL-language or has other showstopper
4851  * properties. In particular it mustn't be declared STRICT, since we
4852  * couldn't enforce that. It also mustn't be VOLATILE, because that is
4853  * supposed to cause it to be executed with its own snapshot, rather than
4854  * sharing the snapshot of the calling query. (Rechecking proretset is
4855  * just paranoia.)
4856  */
4857  if (funcform->prolang != SQLlanguageId ||
4858  funcform->proisstrict ||
4859  funcform->provolatile == PROVOLATILE_VOLATILE ||
4860  funcform->prosecdef ||
4861  !funcform->proretset ||
4862  !heap_attisnull(func_tuple, Anum_pg_proc_proconfig))
4863  {
4864  ReleaseSysCache(func_tuple);
4865  return NULL;
4866  }
4867 
4868  /*
4869  * Make a temporary memory context, so that we don't leak all the stuff
4870  * that parsing might create.
4871  */
4873  "inline_set_returning_function",
4875  oldcxt = MemoryContextSwitchTo(mycxt);
4876 
4877  /*
4878  * When we call eval_const_expressions below, it might try to add items to
4879  * root->glob->invalItems. Since it is running in the temp context, those
4880  * items will be in that context, and will need to be copied out if we're
4881  * successful. Temporarily reset the list so that we can keep those items
4882  * separate from the pre-existing list contents.
4883  */
4884  saveInvalItems = root->glob->invalItems;
4885  root->glob->invalItems = NIL;
4886 
4887  /* Fetch the function body */
4888  tmp = SysCacheGetAttr(PROCOID,
4889  func_tuple,
4891  &isNull);
4892  if (isNull)
4893  elog(ERROR, "null prosrc for function %u", func_oid);
4894  src = TextDatumGetCString(tmp);
4895 
4896  /*
4897  * Setup error traceback support for ereport(). This is so that we can
4898  * finger the function that bad information came from.
4899  */
4900  callback_arg.proname = NameStr(funcform->proname);
4901  callback_arg.prosrc = src;
4902 
4903  sqlerrcontext.callback = sql_inline_error_callback;
4904  sqlerrcontext.arg = (void *) &callback_arg;
4905  sqlerrcontext.previous = error_context_stack;
4906  error_context_stack = &sqlerrcontext;
4907 
4908  /*
4909  * Run eval_const_expressions on the function call. This is necessary to
4910  * ensure that named-argument notation is converted to positional notation
4911  * and any default arguments are inserted. It's a bit of overkill for the
4912  * arguments, since they'll get processed again later, but no harm will be
4913  * done.
4914  */
4915  fexpr = (FuncExpr *) eval_const_expressions(root, (Node *) fexpr);
4916 
4917  /* It should still be a call of the same function, but let's check */
4918  if (!IsA(fexpr, FuncExpr) ||
4919  fexpr->funcid != func_oid)
4920  goto fail;
4921 
4922  /* Arg list length should now match the function */
4923  if (list_length(fexpr->args) != funcform->pronargs)
4924  goto fail;
4925 
4926  /*
4927  * Set up to handle parameters while parsing the function body. We can
4928  * use the FuncExpr just created as the input for
4929  * prepare_sql_fn_parse_info.
4930  */
4931  pinfo = prepare_sql_fn_parse_info(func_tuple,
4932  (Node *) fexpr,
4933  fexpr->inputcollid);
4934 
4935  /*
4936  * Parse, analyze, and rewrite (unlike inline_function(), we can't skip
4937  * rewriting here). We can fail as soon as we find more than one query,
4938  * though.
4939  */
4940  raw_parsetree_list = pg_parse_query(src);
4941  if (list_length(raw_parsetree_list) != 1)
4942  goto fail;
4943 
4944  querytree_list = pg_analyze_and_rewrite_params(linitial(raw_parsetree_list),
4945  src,
4947  pinfo, NULL);
4948  if (list_length(querytree_list) != 1)
4949  goto fail;
4950  querytree = linitial(querytree_list);
4951 
4952  /*
4953  * The single command must be a plain SELECT.
4954  */
4955  if (!IsA(querytree, Query) ||
4956  querytree->commandType != CMD_SELECT)
4957  goto fail;
4958 
4959  /*
4960  * Make sure the function (still) returns what it's declared to. This
4961  * will raise an error if wrong, but that's okay since the function would
4962  * fail at runtime anyway. Note that check_sql_fn_retval will also insert
4963  * RelabelType(s) and/or NULL columns if needed to make the tlist
4964  * expression(s) match the declared type of the function.
4965  *
4966  * If the function returns a composite type, don't inline unless the check
4967  * shows it's returning a whole tuple result; otherwise what it's
4968  * returning is a single composite column which is not what we need.
4969  */
4970  if (!check_sql_fn_retval(func_oid, fexpr->funcresulttype,
4971  querytree_list,
4972  &modifyTargetList, NULL) &&
4974  fexpr->funcresulttype == RECORDOID))
4975  goto fail; /* reject not-whole-tuple-result cases */
4976 
4977  /*
4978  * If we had to modify the tlist to make it match, and the statement is
4979  * one in which changing the tlist contents could change semantics, we
4980  * have to punt and not inline.
4981  */
4982  if (modifyTargetList)
4983  goto fail;
4984 
4985  /*
4986  * If it returns RECORD, we have to check against the column type list
4987  * provided in the RTE; check_sql_fn_retval can't do that. (If no match,
4988  * we just fail to inline, rather than complaining; see notes for
4989  * tlist_matches_coltypelist.) We don't have to do this for functions
4990  * with declared OUT parameters, even though their funcresulttype is
4991  * RECORDOID, so check get_func_result_type too.
4992  */
4993  if (fexpr->funcresulttype == RECORDOID &&
4994  get_func_result_type(func_oid, NULL, NULL) == TYPEFUNC_RECORD &&
4996  rtfunc->funccoltypes))
4997  goto fail;
4998 
4999  /*
5000  * Looks good --- substitute parameters into the query.
5001  */
5002  querytree = substitute_actual_srf_parameters(querytree,
5003  funcform->pronargs,
5004  fexpr->args);
5005 
5006  /*
5007  * Copy the modified query out of the temporary memory context, and clean
5008  * up.
5009  */
5010  MemoryContextSwitchTo(oldcxt);
5011 
5012  querytree = copyObject(querytree);
5013 
5014  /* copy up any new invalItems, too */
5015  root->glob->invalItems = list_concat(saveInvalItems,
5016  copyObject(root->glob->invalItems));
5017 
5018  MemoryContextDelete(mycxt);
5019  error_context_stack = sqlerrcontext.previous;
5020  ReleaseSysCache(func_tuple);
5021 
5022  /*
5023  * We don't have to fix collations here because the upper query is already
5024  * parsed, ie, the collations in the RTE are what count.
5025  */
5026 
5027  /*
5028  * Since there is now no trace of the function in the plan tree, we must
5029  * explicitly record the plan's dependency on the function.
5030  */
5031  record_plan_function_dependency(root, func_oid);
5032 
5033  return querytree;
5034 
5035  /* Here if func is not inlinable: release temp memory and return NULL */
5036 fail:
5037  MemoryContextSwitchTo(oldcxt);
5038  root->glob->invalItems = saveInvalItems;
5039  MemoryContextDelete(mycxt);
5040  error_context_stack = sqlerrcontext.previous;
5041  ReleaseSysCache(func_tuple);
5042 
5043  return NULL;
5044 }
Oid funcresulttype
Definition: primnodes.h:450
#define NIL
Definition: pg_list.h:69
#define IsA(nodeptr, _type_)
Definition: nodes.h:560
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:200
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
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:509
bool check_sql_fn_retval(Oid func_id, Oid rettype, List *queryTreeList, bool *modifyTargetList, JunkFilter **junkFilter)
Definition: functions.c:1532
char get_typtype(Oid typid)
Definition: lsyscache.c:2379
Node * eval_const_expressions(PlannerInfo *root, Node *node)
Definition: clauses.c:2400
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:951
bool funcordinality
Definition: parsenodes.h:991
unsigned int Oid
Definition: postgres_ext.h:31
struct ErrorContextCallback * previous
Definition: elog.h:238
#define FmgrHookIsNeeded(fn_oid)
Definition: fmgr.h:728
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:156
#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:596
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:165
void check_stack_depth(void)
Definition: postgres.c:3117
PlannerGlobal * glob
Definition: relation.h:157
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:680
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
#define PROVOLATILE_VOLATILE
Definition: pg_proc.h:5488
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:4654
List * invalItems
Definition: relation.h:115
#define TextDatumGetCString(d)
Definition: builtins.h:92
MemoryContext AllocSetContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: aset.c:322
uintptr_t Datum
Definition: postgres.h:372
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1117
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1279
void record_plan_function_dependency(PlannerInfo *root, Oid funcid)
Definition: setrefs.c:2496
static Query * substitute_actual_srf_parameters(Query *expr, int nargs, List *args)
Definition: clauses.c:5053
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:83
CmdType commandType
Definition: parsenodes.h:110
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
Oid inputcollid
Definition: primnodes.h:456
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
List * functions
Definition: parsenodes.h:990
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:675
Datum querytree(PG_FUNCTION_ARGS)
Definition: _int_bool.c:665
RTEKind rtekind
Definition: parsenodes.h:936
static bool tlist_matches_coltypelist(List *tlist, List *coltypelist)
Definition: clauses.c:5121
void(* callback)(void *arg)
Definition: elog.h:239
#define ACL_EXECUTE
Definition: parsenodes.h:79
AclResult pg_proc_aclcheck(Oid proc_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4446
#define NameStr(name)
Definition: c.h:499
#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:622
Definition: pg_list.h:45
bool is_parallel_safe ( PlannerInfo root,
Node node 
)

Definition at line 1073 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, NIL, PlannerGlobal::nParamExec, PROPARALLEL_RESTRICTED, PROPARALLEL_SAFE, and max_parallel_hazard_context::safe_param_ids.

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

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

Definition at line 2175 of file clauses.c.

References contain_var_clause(), and contain_volatile_functions().

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

2176 {
2177  /*
2178  * We could implement this check in one recursive scan. But since the
2179  * check for volatile functions is both moderately expensive and unlikely
2180  * to fail, it seems better to look for Vars first and only check for
2181  * volatile functions if we find no Vars.
2182  */
2183  if (!contain_var_clause(clause) &&
2184  !contain_volatile_functions(clause))
2185  return true;
2186  return false;
2187 }
bool contain_var_clause(Node *node)
Definition: var.c:331
bool contain_volatile_functions(Node *clause)
Definition: clauses.c:951
bool is_pseudo_constant_clause_relids ( Node clause,
Relids  relids 
)

Definition at line 2195 of file clauses.c.

References bms_is_empty(), and contain_volatile_functions().

Referenced by clauselist_selectivity().

2196 {
2197  if (bms_is_empty(relids) &&
2198  !contain_volatile_functions(clause))
2199  return true;
2200  return false;
2201 }
bool contain_volatile_functions(Node *clause)
Definition: clauses.c:951
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:663
Node* make_and_qual ( Node qual1,
Node qual2 
)

Definition at line 348 of file clauses.c.

References list_make2, make_andclause(), and NULL.

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:509
#define NULL
Definition: c.h:229
Expr * make_andclause(List *andclauses)
Definition: clauses.c:327
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:557
List * args
Definition: primnodes.h:563
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(), 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:354
static int list_length(const List *l)
Definition: pg_list.h:89
Expr * make_andclause(List *andclauses)
Definition: clauses.c:327
List* make_ands_implicit ( Expr clause)

Definition at line 378 of file clauses.c.

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

Referenced by ATExecAttachPartition(), convert_EXISTS_to_ANY(), cost_subplan(), DefineIndex(), get_relation_constraints(), 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:560
Definition: nodes.h:509
#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
#define NULL
Definition: c.h:229
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:557
List * args
Definition: primnodes.h:563
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:557
Oid inputcollid
Definition: primnodes.h:501
Oid opno
Definition: primnodes.h:496
List * args
Definition: primnodes.h:502
bool opretset
Definition: primnodes.h:499
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:557
List * args
Definition: primnodes.h:563
char max_parallel_hazard ( Query parse)

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

1055 {
1057 
1058  context.max_hazard = PROPARALLEL_SAFE;
1060  context.safe_param_ids = NIL;
1061  (void) max_parallel_hazard_walker((Node *) parse, &context);
1062  return context.max_hazard;
1063 }
#define NIL
Definition: pg_list.h:69
Definition: nodes.h:509
static bool max_parallel_hazard_walker(Node *node, max_parallel_hazard_context *context)
Definition: clauses.c:1130
#define PROPARALLEL_SAFE
Definition: pg_proc.h:5495
#define PROPARALLEL_UNSAFE
Definition: pg_proc.h:5497
static struct subre * parse(struct vars *, int, int, struct state *, struct state *)
Definition: regcomp.c:649
bool not_clause ( Node clause)

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

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:560
#define NULL
Definition: c.h:229
int NumRelids ( Node clause)

Definition at line 2217 of file clauses.c.

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

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

2218 {
2219  Relids varnos = pull_varnos(clause);
2220  int result = bms_num_members(varnos);
2221 
2222  bms_free(varnos);
2223  return result;
2224 }
return result
Definition: formatting.c:1633
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
bool or_clause ( Node clause)

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

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:560
#define NULL
Definition: c.h:229