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

Go to the source code of this file.

Data Structures

struct  WindowFuncLists
 

Functions

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

Function Documentation

◆ CommuteOpExpr()

void CommuteOpExpr ( OpExpr clause)
extern

Definition at line 2390 of file clauses.c.

2391{
2392 Oid opoid;
2393 Node *temp;
2394
2395 /* Sanity checks: caller is at fault if these fail */
2396 if (!is_opclause(clause) ||
2397 list_length(clause->args) != 2)
2398 elog(ERROR, "cannot commute non-binary-operator clause");
2399
2400 opoid = get_commutator(clause->opno);
2401
2402 if (!OidIsValid(opoid))
2403 elog(ERROR, "could not find commutator for operator %u",
2404 clause->opno);
2405
2406 /*
2407 * modify the clause in-place!
2408 */
2409 clause->opno = opoid;
2410 clause->opfuncid = InvalidOid;
2411 /* opresulttype, opretset, opcollid, inputcollid need not change */
2412
2413 temp = linitial(clause->args);
2414 linitial(clause->args) = lsecond(clause->args);
2415 lsecond(clause->args) = temp;
2416}
#define OidIsValid(objectId)
Definition c.h:830
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
Oid get_commutator(Oid opno)
Definition lsyscache.c:1727
static bool is_opclause(const void *clause)
Definition nodeFuncs.h:76
static int list_length(const List *l)
Definition pg_list.h:152
#define linitial(l)
Definition pg_list.h:178
#define lsecond(l)
Definition pg_list.h:183
#define InvalidOid
unsigned int Oid
static int fb(int x)
Definition nodes.h:135
Oid opno
Definition primnodes.h:851
List * args
Definition primnodes.h:869

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

Referenced by get_switched_clauses().

◆ contain_agg_clause()

bool contain_agg_clause ( Node clause)
extern

Definition at line 192 of file clauses.c.

193{
194 return contain_agg_clause_walker(clause, NULL);
195}
static bool contain_agg_clause_walker(Node *node, void *context)
Definition clauses.c:198

References contain_agg_clause_walker(), and fb().

Referenced by get_eclass_for_sort_expr(), mark_nullable_by_grouping(), and subquery_planner().

◆ contain_exec_param()

bool contain_exec_param ( Node clause,
List param_ids 
)
extern

Definition at line 1150 of file clauses.c.

1151{
1152 return contain_exec_param_walker(clause, param_ids);
1153}
static bool contain_exec_param_walker(Node *node, List *param_ids)
Definition clauses.c:1156

References contain_exec_param_walker(), and fb().

Referenced by test_opexpr_is_hashable().

◆ contain_leaked_vars()

bool contain_leaked_vars ( Node clause)
extern

Definition at line 1276 of file clauses.c.

1277{
1278 return contain_leaked_vars_walker(clause, NULL);
1279}
static bool contain_leaked_vars_walker(Node *node, void *context)
Definition clauses.c:1288

References contain_leaked_vars_walker(), and fb().

Referenced by make_plain_restrictinfo(), and qual_is_pushdown_safe().

◆ contain_nonstrict_functions()

bool contain_nonstrict_functions ( Node clause)
extern

Definition at line 1004 of file clauses.c.

1005{
1007}
static bool contain_nonstrict_functions_walker(Node *node, void *context)
Definition clauses.c:1016

References contain_nonstrict_functions_walker(), and fb().

Referenced by inline_function(), and pullup_replace_vars_callback().

◆ contain_subplans()

bool contain_subplans ( Node clause)
extern

◆ contain_window_function()

bool contain_window_function ( Node clause)
extern

Definition at line 229 of file clauses.c.

230{
231 return contain_windowfuncs(clause);
232}
bool contain_windowfuncs(Node *node)

References contain_windowfuncs().

Referenced by get_eclass_for_sort_expr(), and mark_nullable_by_grouping().

◆ expression_returns_set_rows()

double expression_returns_set_rows ( PlannerInfo root,
Node clause 
)
extern

Definition at line 300 of file clauses.c.

301{
302 if (clause == NULL)
303 return 1.0;
304 if (IsA(clause, FuncExpr))
305 {
306 FuncExpr *expr = (FuncExpr *) clause;
307
308 if (expr->funcretset)
309 return clamp_row_est(get_function_rows(root, expr->funcid, clause));
310 }
311 if (IsA(clause, OpExpr))
312 {
313 OpExpr *expr = (OpExpr *) clause;
314
315 if (expr->opretset)
316 {
317 set_opfuncid(expr);
318 return clamp_row_est(get_function_rows(root, expr->opfuncid, clause));
319 }
320 }
321 return 1.0;
322}
double clamp_row_est(double nrows)
Definition costsize.c:213
void set_opfuncid(OpExpr *opexpr)
Definition nodeFuncs.c:1871
#define IsA(nodeptr, _type_)
Definition nodes.h:164
double get_function_rows(PlannerInfo *root, Oid funcid, Node *node)
Definition plancat.c:2416
tree ctl root
Definition radixtree.h:1857
Oid funcid
Definition primnodes.h:783

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

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

◆ find_forced_null_var()

Var * find_forced_null_var ( Node node)
extern

Definition at line 1995 of file clauses.c.

1996{
1997 if (node == NULL)
1998 return NULL;
1999 if (IsA(node, NullTest))
2000 {
2001 /* check for var IS NULL */
2002 NullTest *expr = (NullTest *) node;
2003
2004 if (expr->nulltesttype == IS_NULL && !expr->argisrow)
2005 {
2006 Var *var = (Var *) expr->arg;
2007
2008 if (var && IsA(var, Var) &&
2009 var->varlevelsup == 0)
2010 return var;
2011 }
2012 }
2013 else if (IsA(node, BooleanTest))
2014 {
2015 /* var IS UNKNOWN is equivalent to var IS NULL */
2016 BooleanTest *expr = (BooleanTest *) node;
2017
2018 if (expr->booltesttype == IS_UNKNOWN)
2019 {
2020 Var *var = (Var *) expr->arg;
2021
2022 if (var && IsA(var, Var) &&
2023 var->varlevelsup == 0)
2024 return var;
2025 }
2026 }
2027 return NULL;
2028}
@ IS_UNKNOWN
Definition primnodes.h:2002
@ IS_NULL
Definition primnodes.h:1978
BoolTestType booltesttype
Definition primnodes.h:2009
NullTestType nulltesttype
Definition primnodes.h:1985
Expr * arg
Definition primnodes.h:1984

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

Referenced by check_redundant_nullability_qual(), and find_forced_null_vars().

◆ find_forced_null_vars()

List * find_forced_null_vars ( Node node)
extern

Definition at line 1934 of file clauses.c.

1935{
1936 List *result = NIL;
1937 Var *var;
1938 ListCell *l;
1939
1940 if (node == NULL)
1941 return NIL;
1942 /* Check single-clause cases using subroutine */
1943 var = find_forced_null_var(node);
1944 if (var)
1945 {
1946 result = mbms_add_member(result,
1947 var->varno,
1949 }
1950 /* Otherwise, handle AND-conditions */
1951 else if (IsA(node, List))
1952 {
1953 /*
1954 * At top level, we are examining an implicit-AND list: if any of the
1955 * arms produces FALSE-or-NULL then the result is FALSE-or-NULL.
1956 */
1957 foreach(l, (List *) node)
1958 {
1959 result = mbms_add_members(result,
1961 }
1962 }
1963 else if (IsA(node, BoolExpr))
1964 {
1965 BoolExpr *expr = (BoolExpr *) node;
1966
1967 /*
1968 * We don't bother considering the OR case, because it's fairly
1969 * unlikely anyone would write "v1 IS NULL OR v1 IS NULL". Likewise,
1970 * the NOT case isn't worth expending code on.
1971 */
1972 if (expr->boolop == AND_EXPR)
1973 {
1974 /* At top level we can just recurse (to the List case) */
1975 result = find_forced_null_vars((Node *) expr->args);
1976 }
1977 }
1978 return result;
1979}
List * find_forced_null_vars(Node *node)
Definition clauses.c:1934
Var * find_forced_null_var(Node *node)
Definition clauses.c:1995
List * mbms_add_members(List *a, const List *b)
List * mbms_add_member(List *a, int listidx, int bitidx)
#define lfirst(lc)
Definition pg_list.h:172
#define NIL
Definition pg_list.h:68
@ AND_EXPR
Definition primnodes.h:964
BoolExprType boolop
Definition primnodes.h:972
List * args
Definition primnodes.h:973
Definition pg_list.h:54
AttrNumber varattno
Definition primnodes.h:275
int varno
Definition primnodes.h:270
#define FirstLowInvalidHeapAttributeNumber
Definition sysattr.h:27

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

Referenced by find_forced_null_vars(), and reduce_outer_joins_pass2().

◆ find_nonnullable_rels()

Relids find_nonnullable_rels ( Node clause)
extern

Definition at line 1474 of file clauses.c.

1475{
1476 return find_nonnullable_rels_walker(clause, true);
1477}
static Relids find_nonnullable_rels_walker(Node *node, bool top_level)
Definition clauses.c:1480

References find_nonnullable_rels_walker().

Referenced by make_outerjoininfo(), and reduce_outer_joins_pass2().

◆ find_nonnullable_vars()

List * find_nonnullable_vars ( Node clause)
extern

Definition at line 1725 of file clauses.c.

1726{
1727 return find_nonnullable_vars_walker(clause, true);
1728}
static List * find_nonnullable_vars_walker(Node *node, bool top_level)
Definition clauses.c:1731

References find_nonnullable_vars_walker().

Referenced by query_outputs_are_not_nullable(), and reduce_outer_joins_pass2().

◆ find_window_functions()

WindowFuncLists * find_window_functions ( Node clause,
Index  maxWinRef 
)
extern

Definition at line 242 of file clauses.c.

243{
245
246 lists->numWindowFuncs = 0;
247 lists->maxWinRef = maxWinRef;
248 lists->windowFuncs = (List **) palloc0((maxWinRef + 1) * sizeof(List *));
250 return lists;
251}
static bool find_window_functions_walker(Node *node, WindowFuncLists *lists)
Definition clauses.c:254
#define palloc_object(type)
Definition fe_memutils.h:74
void * palloc0(Size size)
Definition mcxt.c:1417

References fb(), find_window_functions_walker(), palloc0(), and palloc_object.

Referenced by grouping_planner().

◆ inline_function_in_from()

Query * inline_function_in_from ( PlannerInfo root,
RangeTblEntry rte 
)
extern

Definition at line 5780 of file clauses.c.

5781{
5782 RangeTblFunction *rtfunc;
5783 FuncExpr *fexpr;
5784 Oid func_oid;
5789 Datum tmp;
5790 char *src;
5791 inline_error_callback_arg callback_arg;
5793 Query *querytree = NULL;
5794
5795 Assert(rte->rtekind == RTE_FUNCTION);
5796
5797 /*
5798 * Guard against infinite recursion during expansion by checking for stack
5799 * overflow. (There's no need to do more.)
5800 */
5802
5803 /* Fail if the RTE has ORDINALITY - we don't implement that here. */
5804 if (rte->funcordinality)
5805 return NULL;
5806
5807 /* Fail if RTE isn't a single, simple FuncExpr */
5808 if (list_length(rte->functions) != 1)
5809 return NULL;
5810 rtfunc = (RangeTblFunction *) linitial(rte->functions);
5811
5812 if (!IsA(rtfunc->funcexpr, FuncExpr))
5813 return NULL;
5814 fexpr = (FuncExpr *) rtfunc->funcexpr;
5815
5816 func_oid = fexpr->funcid;
5817
5818 /*
5819 * Refuse to inline if the arguments contain any volatile functions or
5820 * sub-selects. Volatile functions are rejected because inlining may
5821 * result in the arguments being evaluated multiple times, risking a
5822 * change in behavior. Sub-selects are rejected partly for implementation
5823 * reasons (pushing them down another level might change their behavior)
5824 * and partly because they're likely to be expensive and so multiple
5825 * evaluation would be bad.
5826 */
5827 if (contain_volatile_functions((Node *) fexpr->args) ||
5828 contain_subplans((Node *) fexpr->args))
5829 return NULL;
5830
5831 /* Check permission to call function (fail later, if not) */
5833 return NULL;
5834
5835 /* Check whether a plugin wants to hook function entry/exit */
5837 return NULL;
5838
5839 /*
5840 * OK, let's take a look at the function's pg_proc entry.
5841 */
5844 elog(ERROR, "cache lookup failed for function %u", func_oid);
5846
5847 /*
5848 * If the function SETs any configuration parameters, inlining would cause
5849 * us to miss making those changes.
5850 */
5852 {
5854 return NULL;
5855 }
5856
5857 /*
5858 * Make a temporary memory context, so that we don't leak all the stuff
5859 * that parsing and rewriting might create. If we succeed, we'll copy
5860 * just the finished query tree back up to the caller's context.
5861 */
5863 "inline_function_in_from",
5866
5867 /* Fetch the function body */
5869 src = TextDatumGetCString(tmp);
5870
5871 /*
5872 * If the function has an attached support function that can handle
5873 * SupportRequestInlineInFrom, then attempt to inline with that.
5874 */
5875 if (funcform->prosupport)
5876 {
5878
5880 req.root = root;
5881 req.rtfunc = rtfunc;
5882 req.proc = func_tuple;
5883
5884 querytree = (Query *)
5886 PointerGetDatum(&req)));
5887 }
5888
5889 /*
5890 * Setup error traceback support for ereport(). This is so that we can
5891 * finger the function that bad information came from. We don't install
5892 * this while running the support function, since it'd be likely to do the
5893 * wrong thing: any parse errors reported during that are very likely not
5894 * against the raw function source text.
5895 */
5896 callback_arg.proname = NameStr(funcform->proname);
5897 callback_arg.prosrc = src;
5898
5900 sqlerrcontext.arg = &callback_arg;
5903
5904 /*
5905 * If SupportRequestInlineInFrom didn't work, try our built-in inlining
5906 * mechanism.
5907 */
5908 if (!querytree)
5910 func_tuple, funcform, src);
5911
5912 if (!querytree)
5913 goto fail; /* no luck there either, fail */
5914
5915 /*
5916 * The result had better be a SELECT Query.
5917 */
5919 Assert(querytree->commandType == CMD_SELECT);
5920
5921 /*
5922 * Looks good --- substitute parameters into the query.
5923 */
5925 funcform->pronargs,
5926 fexpr->args);
5927
5928 /*
5929 * Copy the modified query out of the temporary memory context, and clean
5930 * up.
5931 */
5933
5935
5939
5940 /*
5941 * We don't have to fix collations here because the upper query is already
5942 * parsed, ie, the collations in the RTE are what count.
5943 */
5944
5945 /*
5946 * Since there is now no trace of the function in the plan tree, we must
5947 * explicitly record the plan's dependency on the function.
5948 */
5950
5951 /*
5952 * We must also notice if the inserted query adds a dependency on the
5953 * calling role due to RLS quals.
5954 */
5955 if (querytree->hasRowSecurity)
5956 root->glob->dependsOnRole = true;
5957
5958 return querytree;
5959
5960 /* Here if func is not inlinable: release temp memory and return NULL */
5961fail:
5966
5967 return NULL;
5968}
Datum querytree(PG_FUNCTION_ARGS)
Definition _int_bool.c:665
@ ACLCHECK_OK
Definition acl.h:183
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
Definition aclchk.c:3854
#define TextDatumGetCString(d)
Definition builtins.h:99
#define NameStr(name)
Definition c.h:807
#define Assert(condition)
Definition c.h:915
static Query * substitute_actual_parameters_in_from(Query *expr, int nargs, List *args)
Definition clauses.c:6144
static void sql_inline_error_callback(void *arg)
Definition clauses.c:5664
static Query * inline_sql_function_in_from(PlannerInfo *root, RangeTblFunction *rtfunc, FuncExpr *fexpr, HeapTuple func_tuple, Form_pg_proc funcform, const char *src)
Definition clauses.c:5984
bool contain_subplans(Node *clause)
Definition clauses.c:341
bool contain_volatile_functions(Node *clause)
Definition clauses.c:549
ErrorContextCallback * error_context_stack
Definition elog.c:99
#define OidFunctionCall1(functionId, arg1)
Definition fmgr.h:722
#define FmgrHookIsNeeded(fn_oid)
Definition fmgr.h:850
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
Definition heaptuple.c:456
#define HeapTupleIsValid(tuple)
Definition htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
MemoryContext CurrentMemoryContext
Definition mcxt.c:160
void MemoryContextDelete(MemoryContext context)
Definition mcxt.c:472
#define AllocSetContextCreate
Definition memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition memutils.h:160
Oid GetUserId(void)
Definition miscinit.c:470
#define copyObject(obj)
Definition nodes.h:232
@ CMD_SELECT
Definition nodes.h:275
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:124
@ RTE_FUNCTION
#define ACL_EXECUTE
Definition parsenodes.h:83
END_CATALOG_STRUCT typedef FormData_pg_proc * Form_pg_proc
Definition pg_proc.h:140
static Datum PointerGetDatum(const void *X)
Definition postgres.h:342
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
uint64_t Datum
Definition postgres.h:70
static Pointer DatumGetPointer(Datum X)
Definition postgres.h:332
void record_plan_function_dependency(PlannerInfo *root, Oid funcid)
Definition setrefs.c:3626
void check_stack_depth(void)
Definition stack_depth.c:95
struct ErrorContextCallback * previous
Definition elog.h:297
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:264
Datum SysCacheGetAttrNotNull(SysCacheIdentifier cacheId, HeapTuple tup, AttrNumber attributeNumber)
Definition syscache.c:625
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:220

References ACL_EXECUTE, ACLCHECK_OK, ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert, check_stack_depth(), CMD_SELECT, contain_subplans(), contain_volatile_functions(), copyObject, CurrentMemoryContext, DatumGetPointer(), elog, ERROR, error_context_stack, fb(), FmgrHookIsNeeded, Form_pg_proc, RangeTblFunction::funcexpr, GETSTRUCT(), GetUserId(), heap_attisnull(), HeapTupleIsValid, inline_sql_function_in_from(), IsA, linitial, list_length(), MemoryContextDelete(), MemoryContextSwitchTo(), NameStr, object_aclcheck(), ObjectIdGetDatum(), OidFunctionCall1, PointerGetDatum(), ErrorContextCallback::previous, inline_error_callback_arg::proname, inline_error_callback_arg::prosrc, querytree(), record_plan_function_dependency(), ReleaseSysCache(), root, RTE_FUNCTION, SearchSysCache1(), sql_inline_error_callback(), substitute_actual_parameters_in_from(), SysCacheGetAttrNotNull(), TextDatumGetCString, and SupportRequestInlineInFrom::type.

Referenced by preprocess_function_rtes().

◆ is_parallel_safe()

bool is_parallel_safe ( PlannerInfo root,
Node node 
)
extern

Definition at line 764 of file clauses.c.

765{
768 ListCell *l;
769
770 /*
771 * Even if the original querytree contained nothing unsafe, we need to
772 * search the expression if we have generated any PARAM_EXEC Params while
773 * planning, because those are parallel-restricted and there might be one
774 * in this expression. But otherwise we don't need to look.
775 */
776 if (root->glob->maxParallelHazard == PROPARALLEL_SAFE &&
777 root->glob->paramExecTypes == NIL)
778 return true;
779 /* Else use max_parallel_hazard's search logic, but stop on RESTRICTED */
782 context.safe_param_ids = NIL;
783
784 /*
785 * The params that refer to the same or parent query level are considered
786 * parallel-safe. The idea is that we compute such params at Gather or
787 * Gather Merge node and pass their value to workers.
788 */
789 for (proot = root; proot != NULL; proot = proot->parent_root)
790 {
791 foreach(l, proot->init_plans)
792 {
794
795 context.safe_param_ids = list_concat(context.safe_param_ids,
796 initsubplan->setParam);
797 }
798 }
799
800 return !max_parallel_hazard_walker(node, &context);
801}
static bool max_parallel_hazard_walker(Node *node, max_parallel_hazard_context *context)
Definition clauses.c:840
List * list_concat(List *list1, const List *list2)
Definition list.c:561

References fb(), lfirst, list_concat(), max_parallel_hazard_context::max_hazard, max_parallel_hazard_context::max_interesting, max_parallel_hazard_walker(), NIL, root, and max_parallel_hazard_context::safe_param_ids.

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

◆ is_pseudo_constant_clause()

bool is_pseudo_constant_clause ( Node clause)
extern

Definition at line 2331 of file clauses.c.

2332{
2333 /*
2334 * We could implement this check in one recursive scan. But since the
2335 * check for volatile functions is both moderately expensive and unlikely
2336 * to fail, it seems better to look for Vars first and only check for
2337 * volatile functions if we find no Vars.
2338 */
2339 if (!contain_var_clause(clause) &&
2341 return true;
2342 return false;
2343}
bool contain_var_clause(Node *node)
Definition var.c:406

References contain_var_clause(), and contain_volatile_functions().

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

◆ is_pseudo_constant_clause_relids()

bool is_pseudo_constant_clause_relids ( Node clause,
Relids  relids 
)
extern

Definition at line 2351 of file clauses.c.

2352{
2353 if (bms_is_empty(relids) &&
2355 return true;
2356 return false;
2357}
#define bms_is_empty(a)
Definition bitmapset.h:118

References bms_is_empty, and contain_volatile_functions().

Referenced by clauselist_selectivity_ext().

◆ max_parallel_hazard()

char max_parallel_hazard ( Query parse)
extern

◆ NumRelids()

int NumRelids ( PlannerInfo root,
Node clause 
)
extern

Definition at line 2373 of file clauses.c.

2374{
2375 int result;
2376 Relids varnos = pull_varnos(root, clause);
2377
2378 varnos = bms_del_members(varnos, root->outer_join_rels);
2379 result = bms_num_members(varnos);
2380 bms_free(varnos);
2381 return result;
2382}
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Definition bitmapset.c:1145
void bms_free(Bitmapset *a)
Definition bitmapset.c:239
int bms_num_members(const Bitmapset *a)
Definition bitmapset.c:744
Relids pull_varnos(PlannerInfo *root, Node *node)
Definition var.c:114

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

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

◆ pull_paramids()

Bitmapset * pull_paramids ( Expr expr)
extern

Definition at line 6204 of file clauses.c.

6205{
6206 Bitmapset *result = NULL;
6207
6208 (void) pull_paramids_walker((Node *) expr, &result);
6209
6210 return result;
6211}
static bool pull_paramids_walker(Node *node, Bitmapset **context)
Definition clauses.c:6214

References fb(), and pull_paramids_walker().

Referenced by create_memoize_plan().

◆ query_outputs_are_not_nullable()

bool query_outputs_are_not_nullable ( Query query)
extern

Definition at line 2049 of file clauses.c.

2050{
2051 PlannerInfo subroot;
2052 List *safe_quals = NIL;
2054 bool computed_nonnullable_vars = false;
2055
2056 /*
2057 * If the query contains set operations, punt. The set ops themselves
2058 * couldn't introduce nulls that weren't in their inputs, but the tlist
2059 * present in the top-level query is just dummy and won't give us useful
2060 * info. We could get an answer by recursing to examine each leaf query,
2061 * but for the moment it doesn't seem worth the extra complication.
2062 */
2063 if (query->setOperations)
2064 return false;
2065
2066 /*
2067 * If the query contains grouping sets, punt. Grouping sets can introduce
2068 * NULL values, and we currently lack the PlannerInfo needed to flatten
2069 * grouping Vars in the query's outputs.
2070 */
2071 if (query->groupingSets)
2072 return false;
2073
2074 /*
2075 * We need a PlannerInfo to pass to expr_is_nonnullable. Fortunately, we
2076 * can cons up an entirely dummy one, because only the "parse" link in the
2077 * struct is used by expr_is_nonnullable.
2078 */
2079 MemSet(&subroot, 0, sizeof(subroot));
2080 subroot.parse = query;
2081
2082 /*
2083 * Examine each targetlist entry to prove that it can't produce NULL.
2084 */
2086 {
2087 Expr *expr = tle->expr;
2088
2089 /* Resjunk columns can be ignored: they don't produce output values */
2090 if (tle->resjunk)
2091 continue;
2092
2093 /*
2094 * Look through binary relabelings, since we know those don't
2095 * introduce nulls.
2096 */
2097 while (expr && IsA(expr, RelabelType))
2098 expr = ((RelabelType *) expr)->arg;
2099
2100 if (expr == NULL) /* paranoia */
2101 return false;
2102
2103 /*
2104 * Since the subquery hasn't yet been through expression
2105 * preprocessing, we must explicitly flatten grouping Vars and join
2106 * alias Vars in the given expression. Note that flatten_group_exprs
2107 * must be applied before flatten_join_alias_vars, as grouping Vars
2108 * can wrap join alias Vars.
2109 *
2110 * We must also apply flatten_join_alias_vars to the quals extracted
2111 * by find_subquery_safe_quals. We do not need to apply
2112 * flatten_group_exprs to these quals, though, because grouping Vars
2113 * cannot appear in jointree quals.
2114 */
2115
2116 /*
2117 * We have verified that the query does not contain grouping sets,
2118 * meaning the grouping Vars will not have varnullingrels that need
2119 * preserving, so it's safe to use NULL as the root here.
2120 */
2121 if (query->hasGroupRTE)
2122 expr = (Expr *) flatten_group_exprs(NULL, query, (Node *) expr);
2123
2124 /*
2125 * We won't be dealing with arbitrary expressions, so it's safe to use
2126 * NULL as the root, so long as adjust_standard_join_alias_expression
2127 * can handle everything the parser would make as a join alias
2128 * expression.
2129 */
2130 expr = (Expr *) flatten_join_alias_vars(NULL, query, (Node *) expr);
2131
2132 /*
2133 * Check to see if the expr cannot be NULL. Since we're on a raw
2134 * parse tree, we need to look up the not-null constraints from the
2135 * system catalogs.
2136 */
2137 if (expr_is_nonnullable(&subroot, expr, NOTNULL_SOURCE_SYSCACHE))
2138 continue;
2139
2140 if (IsA(expr, Var))
2141 {
2142 Var *var = (Var *) expr;
2143
2144 /*
2145 * For a plain Var, even if that didn't work, we can conclude that
2146 * the Var is not nullable if find_nonnullable_vars can find a
2147 * "var IS NOT NULL" or similarly strict condition among the quals
2148 * on non-outerjoined-rels. Compute the list of Vars having such
2149 * quals if we didn't already.
2150 */
2152 {
2154 safe_quals = (List *)
2158 }
2159
2160 if (!mbms_is_member(var->varno,
2163 return false; /* we failed to prove the Var non-null */
2164 }
2165 else
2166 {
2167 /* Punt otherwise */
2168 return false;
2169 }
2170 }
2171
2172 return true;
2173}
#define MemSet(start, val, len)
Definition c.h:1079
static void find_subquery_safe_quals(Node *jtnode, List **safe_quals)
Definition clauses.c:2187
List * find_nonnullable_vars(Node *clause)
Definition clauses.c:1725
bool expr_is_nonnullable(PlannerInfo *root, Expr *expr, NotNullSource source)
Definition clauses.c:4749
bool mbms_is_member(int listidx, int bitidx, const List *a)
@ NOTNULL_SOURCE_SYSCACHE
Definition optimizer.h:138
#define foreach_node(type, var, lst)
Definition pg_list.h:496
Query * parse
Definition pathnodes.h:309
FromExpr * jointree
Definition parsenodes.h:182
Node * setOperations
Definition parsenodes.h:236
List * targetList
Definition parsenodes.h:198
List * groupingSets
Definition parsenodes.h:220
Node * flatten_group_exprs(PlannerInfo *root, Query *query, Node *node)
Definition var.c:999
Node * flatten_join_alias_vars(PlannerInfo *root, Query *query, Node *node)
Definition var.c:781

References expr_is_nonnullable(), fb(), find_nonnullable_vars(), find_subquery_safe_quals(), FirstLowInvalidHeapAttributeNumber, flatten_group_exprs(), flatten_join_alias_vars(), foreach_node, Query::groupingSets, IsA, Query::jointree, mbms_is_member(), MemSet, NIL, NOTNULL_SOURCE_SYSCACHE, PlannerInfo::parse, Query::setOperations, Query::targetList, Var::varattno, and Var::varno.

Referenced by convert_ANY_sublink_to_join().