MCPcopy Create free account
hub / github.com/apache/cloudberry / qual_is_pushdown_safe

Function qual_is_pushdown_safe

src/backend/optimizer/path/allpaths.c:4361–4448  ·  view source on GitHub ↗

* qual_is_pushdown_safe - is a particular rinfo safe to push down? * * rinfo is a restriction clause applying to the given subquery (whose RTE * has index rti in the parent query). * * Conditions checked here: * * 1. rinfo's clause must not contain any SubPlans (mainly because it's * unclear that it will work correctly: SubLinks will already have been * transformed into SubPlans in the qu

Source from the content-addressed store, hash-verified

4359 * found to be unsafe to reference by subquery_is_pushdown_safe().
4360 */
4361static bool
4362qual_is_pushdown_safe(Query *subquery, Index rti, RestrictInfo *rinfo,
4363 pushdown_safety_info *safetyInfo)
4364{
4365 bool safe = true;
4366 Node *qual = (Node *) rinfo->clause;
4367 List *vars;
4368 ListCell *vl;
4369
4370 /* Refuse subselects (point 1) */
4371 if (contain_subplans(qual))
4372 return false;
4373
4374 /* Refuse volatile quals if we found they'd be unsafe (point 2) */
4375 if (safetyInfo->unsafeVolatile &&
4376 contain_volatile_functions((Node *) rinfo))
4377 return false;
4378
4379 /* Refuse leaky quals if told to (point 3) */
4380 if (safetyInfo->unsafeLeaky &&
4381 contain_leaked_vars(qual))
4382 return false;
4383
4384 /*
4385 * It would be unsafe to push down window function calls, but at least for
4386 * the moment we could never see any in a qual anyhow. (The same applies
4387 * to aggregates, which we check for in pull_var_clause below.)
4388 */
4389 Assert(!contain_window_function(qual));
4390
4391 /*
4392 * Examine all Vars used in clause. Since it's a restriction clause, all
4393 * such Vars must refer to subselect output columns ... unless this is
4394 * part of a LATERAL subquery, in which case there could be lateral
4395 * references.
4396 */
4397 vars = pull_var_clause(qual, PVC_INCLUDE_PLACEHOLDERS);
4398 foreach(vl, vars)
4399 {
4400 Var *var = (Var *) lfirst(vl);
4401
4402 /*
4403 * XXX Punt if we find any PlaceHolderVars in the restriction clause.
4404 * It's not clear whether a PHV could safely be pushed down, and even
4405 * less clear whether such a situation could arise in any cases of
4406 * practical interest anyway. So for the moment, just refuse to push
4407 * down.
4408 */
4409 if (!IsA(var, Var))
4410 {
4411 safe = false;
4412 break;
4413 }
4414
4415 /*
4416 * Punt if we find any lateral references. It would be safe to push
4417 * these down, but we'd have to convert them into outer references,
4418 * which subquery_push_qual lacks the infrastructure to do. The case

Callers 1

push_down_restrictFunction · 0.85

Calls 7

contain_subplansFunction · 0.85
contain_leaked_varsFunction · 0.85
contain_window_functionFunction · 0.85
pull_var_clauseFunction · 0.85
foreachFunction · 0.50
list_freeFunction · 0.50

Tested by

no test coverage detected