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 2392 of file clauses.c.

2393{
2394 Oid opoid;
2395 Node *temp;
2396
2397 /* Sanity checks: caller is at fault if these fail */
2398 if (!is_opclause(clause) ||
2399 list_length(clause->args) != 2)
2400 elog(ERROR, "cannot commute non-binary-operator clause");
2401
2402 opoid = get_commutator(clause->opno);
2403
2404 if (!OidIsValid(opoid))
2405 elog(ERROR, "could not find commutator for operator %u",
2406 clause->opno);
2407
2408 /*
2409 * modify the clause in-place!
2410 */
2411 clause->opno = opoid;
2412 clause->opfuncid = InvalidOid;
2413 /* opresulttype, opretset, opcollid, inputcollid need not change */
2414
2415 temp = linitial(clause->args);
2416 linitial(clause->args) = lsecond(clause->args);
2417 lsecond(clause->args) = temp;
2418}
#define OidIsValid(objectId)
Definition c.h:858
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
Oid get_commutator(Oid opno)
Definition lsyscache.c:1702
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 194 of file clauses.c.

195{
196 return contain_agg_clause_walker(clause, NULL);
197}
static bool contain_agg_clause_walker(Node *node, void *context)
Definition clauses.c:200

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 1152 of file clauses.c.

1153{
1154 return contain_exec_param_walker(clause, param_ids);
1155}
static bool contain_exec_param_walker(Node *node, List *param_ids)
Definition clauses.c:1158

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 1278 of file clauses.c.

1279{
1280 return contain_leaked_vars_walker(clause, NULL);
1281}
static bool contain_leaked_vars_walker(Node *node, void *context)
Definition clauses.c:1290

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 1006 of file clauses.c.

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

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 231 of file clauses.c.

232{
233 return contain_windowfuncs(clause);
234}
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 302 of file clauses.c.

303{
304 if (clause == NULL)
305 return 1.0;
306 if (IsA(clause, FuncExpr))
307 {
308 FuncExpr *expr = (FuncExpr *) clause;
309
310 if (expr->funcretset)
311 return clamp_row_est(get_function_rows(root, expr->funcid, clause));
312 }
313 if (IsA(clause, OpExpr))
314 {
315 OpExpr *expr = (OpExpr *) clause;
316
317 if (expr->opretset)
318 {
319 set_opfuncid(expr);
320 return clamp_row_est(get_function_rows(root, expr->opfuncid, clause));
321 }
322 }
323 return 1.0;
324}
double clamp_row_est(double nrows)
Definition costsize.c:214
void set_opfuncid(OpExpr *opexpr)
Definition nodeFuncs.c:1879
#define IsA(nodeptr, _type_)
Definition nodes.h:164
double get_function_rows(PlannerInfo *root, Oid funcid, Node *node)
Definition plancat.c:2419
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 1997 of file clauses.c.

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

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 1936 of file clauses.c.

1937{
1938 List *result = NIL;
1939 Var *var;
1940 ListCell *l;
1941
1942 if (node == NULL)
1943 return NIL;
1944 /* Check single-clause cases using subroutine */
1945 var = find_forced_null_var(node);
1946 if (var)
1947 {
1949 var->varno,
1951 }
1952 /* Otherwise, handle AND-conditions */
1953 else if (IsA(node, List))
1954 {
1955 /*
1956 * At top level, we are examining an implicit-AND list: if any of the
1957 * arms produces FALSE-or-NULL then the result is FALSE-or-NULL.
1958 */
1959 foreach(l, (List *) node)
1960 {
1963 }
1964 }
1965 else if (IsA(node, BoolExpr))
1966 {
1967 BoolExpr *expr = (BoolExpr *) node;
1968
1969 /*
1970 * We don't bother considering the OR case, because it's fairly
1971 * unlikely anyone would write "v1 IS NULL OR v1 IS NULL". Likewise,
1972 * the NOT case isn't worth expending code on.
1973 */
1974 if (expr->boolop == AND_EXPR)
1975 {
1976 /* At top level we can just recurse (to the List case) */
1978 }
1979 }
1980 return result;
1981}
uint32 result
List * find_forced_null_vars(Node *node)
Definition clauses.c:1936
Var * find_forced_null_var(Node *node)
Definition clauses.c:1997
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, result, 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 1476 of file clauses.c.

1477{
1478 return find_nonnullable_rels_walker(clause, true);
1479}
static Relids find_nonnullable_rels_walker(Node *node, bool top_level)
Definition clauses.c:1482

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 1727 of file clauses.c.

1728{
1729 return find_nonnullable_vars_walker(clause, true);
1730}
static List * find_nonnullable_vars_walker(Node *node, bool top_level)
Definition clauses.c:1733

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 244 of file clauses.c.

245{
247
248 lists->numWindowFuncs = 0;
249 lists->maxWinRef = maxWinRef;
250 lists->windowFuncs = (List **) palloc0((maxWinRef + 1) * sizeof(List *));
252 return lists;
253}
static bool find_window_functions_walker(Node *node, WindowFuncLists *lists)
Definition clauses.c:256
#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 5803 of file clauses.c.

5804{
5805 RangeTblFunction *rtfunc;
5806 FuncExpr *fexpr;
5807 Oid func_oid;
5812 Datum tmp;
5813 char *src;
5814 inline_error_callback_arg callback_arg;
5816 Query *querytree = NULL;
5817
5818 Assert(rte->rtekind == RTE_FUNCTION);
5819
5820 /*
5821 * Guard against infinite recursion during expansion by checking for stack
5822 * overflow. (There's no need to do more.)
5823 */
5825
5826 /* Fail if the RTE has ORDINALITY - we don't implement that here. */
5827 if (rte->funcordinality)
5828 return NULL;
5829
5830 /* Fail if RTE isn't a single, simple FuncExpr */
5831 if (list_length(rte->functions) != 1)
5832 return NULL;
5833 rtfunc = (RangeTblFunction *) linitial(rte->functions);
5834
5835 if (!IsA(rtfunc->funcexpr, FuncExpr))
5836 return NULL;
5837 fexpr = (FuncExpr *) rtfunc->funcexpr;
5838
5839 func_oid = fexpr->funcid;
5840
5841 /*
5842 * Refuse to inline if the arguments contain any volatile functions or
5843 * sub-selects. Volatile functions are rejected because inlining may
5844 * result in the arguments being evaluated multiple times, risking a
5845 * change in behavior. Sub-selects are rejected partly for implementation
5846 * reasons (pushing them down another level might change their behavior)
5847 * and partly because they're likely to be expensive and so multiple
5848 * evaluation would be bad.
5849 */
5850 if (contain_volatile_functions((Node *) fexpr->args) ||
5851 contain_subplans((Node *) fexpr->args))
5852 return NULL;
5853
5854 /* Check permission to call function (fail later, if not) */
5856 return NULL;
5857
5858 /* Check whether a plugin wants to hook function entry/exit */
5860 return NULL;
5861
5862 /*
5863 * OK, let's take a look at the function's pg_proc entry.
5864 */
5867 elog(ERROR, "cache lookup failed for function %u", func_oid);
5869
5870 /*
5871 * If the function SETs any configuration parameters, inlining would cause
5872 * us to miss making those changes.
5873 */
5875 {
5877 return NULL;
5878 }
5879
5880 /*
5881 * Make a temporary memory context, so that we don't leak all the stuff
5882 * that parsing and rewriting might create. If we succeed, we'll copy
5883 * just the finished query tree back up to the caller's context.
5884 */
5886 "inline_function_in_from",
5889
5890 /* Fetch the function body */
5892 src = TextDatumGetCString(tmp);
5893
5894 /*
5895 * If the function has an attached support function that can handle
5896 * SupportRequestInlineInFrom, then attempt to inline with that.
5897 */
5898 if (funcform->prosupport)
5899 {
5901
5903 req.root = root;
5904 req.rtfunc = rtfunc;
5905 req.proc = func_tuple;
5906
5907 querytree = (Query *)
5909 PointerGetDatum(&req)));
5910 }
5911
5912 /*
5913 * Setup error traceback support for ereport(). This is so that we can
5914 * finger the function that bad information came from. We don't install
5915 * this while running the support function, since it'd be likely to do the
5916 * wrong thing: any parse errors reported during that are very likely not
5917 * against the raw function source text.
5918 */
5919 callback_arg.proname = NameStr(funcform->proname);
5920 callback_arg.prosrc = src;
5921
5923 sqlerrcontext.arg = &callback_arg;
5926
5927 /*
5928 * If SupportRequestInlineInFrom didn't work, try our built-in inlining
5929 * mechanism.
5930 */
5931 if (!querytree)
5933 func_tuple, funcform, src);
5934
5935 if (!querytree)
5936 goto fail; /* no luck there either, fail */
5937
5938 /*
5939 * The result had better be a SELECT Query.
5940 */
5942 Assert(querytree->commandType == CMD_SELECT);
5943
5944 /*
5945 * Looks good --- substitute parameters into the query.
5946 */
5948 funcform->pronargs,
5949 fexpr->args);
5950
5951 /*
5952 * Copy the modified query out of the temporary memory context, and clean
5953 * up.
5954 */
5956
5958
5962
5963 /*
5964 * We don't have to fix collations here because the upper query is already
5965 * parsed, ie, the collations in the RTE are what count.
5966 */
5967
5968 /*
5969 * Since there is now no trace of the function in the plan tree, we must
5970 * explicitly record the plan's dependency on the function.
5971 */
5973
5974 /*
5975 * We must also notice if the inserted query adds a dependency on the
5976 * calling role due to RLS quals.
5977 */
5978 if (querytree->hasRowSecurity)
5979 root->glob->dependsOnRole = true;
5980
5981 return querytree;
5982
5983 /* Here if func is not inlinable: release temp memory and return NULL */
5984fail:
5989
5990 return NULL;
5991}
Datum querytree(PG_FUNCTION_ARGS)
Definition _int_bool.c:665
@ ACLCHECK_OK
Definition acl.h:184
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
Definition aclchk.c:3879
#define TextDatumGetCString(d)
Definition builtins.h:99
#define NameStr(name)
Definition c.h:835
#define Assert(condition)
Definition c.h:943
static Query * substitute_actual_parameters_in_from(Query *expr, int nargs, List *args)
Definition clauses.c:6167
static void sql_inline_error_callback(void *arg)
Definition clauses.c:5687
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:6007
bool contain_subplans(Node *clause)
Definition clauses.c:343
bool contain_volatile_functions(Node *clause)
Definition clauses.c:551
ErrorContextCallback * error_context_stack
Definition elog.c:100
#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 ObjectIdGetDatum(Oid X)
Definition postgres.h:252
uint64_t Datum
Definition postgres.h:70
static Pointer DatumGetPointer(Datum X)
Definition postgres.h:332
#define PointerGetDatum(X)
Definition postgres.h:354
void record_plan_function_dependency(PlannerInfo *root, Oid funcid)
Definition setrefs.c:3632
void check_stack_depth(void)
Definition stack_depth.c:95
struct ErrorContextCallback * previous
Definition elog.h:299
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:265
Datum SysCacheGetAttrNotNull(SysCacheIdentifier cacheId, HeapTuple tup, AttrNumber attributeNumber)
Definition syscache.c:626
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:221

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 766 of file clauses.c.

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

2334{
2335 /*
2336 * We could implement this check in one recursive scan. But since the
2337 * check for volatile functions is both moderately expensive and unlikely
2338 * to fail, it seems better to look for Vars first and only check for
2339 * volatile functions if we find no Vars.
2340 */
2341 if (!contain_var_clause(clause) &&
2343 return true;
2344 return false;
2345}
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 2353 of file clauses.c.

2354{
2355 if (bms_is_empty(relids) &&
2357 return true;
2358 return false;
2359}
#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 2375 of file clauses.c.

2376{
2377 int result;
2378 Relids varnos = pull_varnos(root, clause);
2379
2380 varnos = bms_del_members(varnos, root->outer_join_rels);
2381 result = bms_num_members(varnos);
2382 bms_free(varnos);
2383 return result;
2384}
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(), result, and root.

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

◆ pull_paramids()

Bitmapset * pull_paramids ( Expr expr)
extern

Definition at line 6227 of file clauses.c.

6228{
6230
6231 (void) pull_paramids_walker((Node *) expr, &result);
6232
6233 return result;
6234}
static bool pull_paramids_walker(Node *node, Bitmapset **context)
Definition clauses.c:6237

References fb(), pull_paramids_walker(), and result.

Referenced by create_memoize_plan().

◆ query_outputs_are_not_nullable()

bool query_outputs_are_not_nullable ( Query query)
extern

Definition at line 2051 of file clauses.c.

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

Referenced by convert_ANY_sublink_to_join().