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

Go to the source code of this file.

Macros

#define make_simple_restrictinfo(root, clause)    make_restrictinfo(root, clause, true, false, 0, NULL, NULL)
 

Functions

RestrictInfomake_restrictinfo (PlannerInfo *root, Expr *clause, bool is_pushed_down, bool pseudoconstant, Index security_level, Relids required_relids, Relids outer_relids)
 
RestrictInfocommute_restrictinfo (RestrictInfo *rinfo, Oid comm_op)
 
bool restriction_is_or_clause (RestrictInfo *restrictinfo)
 
bool restriction_is_securely_promotable (RestrictInfo *restrictinfo, RelOptInfo *rel)
 
Listget_actual_clauses (List *restrictinfo_list)
 
Listextract_actual_clauses (List *restrictinfo_list, bool pseudoconstant)
 
void extract_actual_join_clauses (List *restrictinfo_list, Relids joinrelids, List **joinquals, List **otherquals)
 
bool clause_is_computable_at (PlannerInfo *root, Relids clause_relids, Relids eval_relids)
 
bool join_clause_is_movable_to (RestrictInfo *rinfo, RelOptInfo *baserel)
 
bool join_clause_is_movable_into (RestrictInfo *rinfo, Relids currentrelids, Relids current_and_outer)
 

Macro Definition Documentation

◆ make_simple_restrictinfo

#define make_simple_restrictinfo (   root,
  clause 
)     make_restrictinfo(root, clause, true, false, 0, NULL, NULL)

Definition at line 21 of file restrictinfo.h.

Function Documentation

◆ clause_is_computable_at()

bool clause_is_computable_at ( PlannerInfo root,
Relids  clause_relids,
Relids  eval_relids 
)

Definition at line 543 of file restrictinfo.c.

546 {
547  ListCell *lc;
548 
549  /* Nothing to do if no outer joins have been performed yet. */
550  if (!bms_overlap(eval_relids, root->outer_join_rels))
551  return true;
552 
553  foreach(lc, root->join_info_list)
554  {
555  SpecialJoinInfo *sjinfo = (SpecialJoinInfo *) lfirst(lc);
556 
557  /* Ignore outer joins that are not yet performed. */
558  if (!bms_is_member(sjinfo->ojrelid, eval_relids))
559  continue;
560 
561  /* OK if clause lists it (we assume all Vars in it agree). */
562  if (bms_is_member(sjinfo->ojrelid, clause_relids))
563  continue;
564 
565  /* Else, trouble if clause mentions any nullable Vars. */
566  if (bms_overlap(clause_relids, sjinfo->min_righthand) ||
567  (sjinfo->jointype == JOIN_FULL &&
568  bms_overlap(clause_relids, sjinfo->min_lefthand)))
569  return false; /* doesn't work */
570  }
571 
572  return true; /* OK */
573 }
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:444
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:511
@ JOIN_FULL
Definition: nodes.h:306
#define lfirst(lc)
Definition: pg_list.h:172
Relids outer_join_rels
Definition: pathnodes.h:261
List * join_info_list
Definition: pathnodes.h:340
Relids min_righthand
Definition: pathnodes.h:2830
JoinType jointype
Definition: pathnodes.h:2833
Relids min_lefthand
Definition: pathnodes.h:2829

References bms_is_member(), bms_overlap(), JOIN_FULL, PlannerInfo::join_info_list, SpecialJoinInfo::jointype, lfirst, SpecialJoinInfo::min_lefthand, SpecialJoinInfo::min_righthand, SpecialJoinInfo::ojrelid, and PlannerInfo::outer_join_rels.

Referenced by subbuild_joinrel_restrictlist().

◆ commute_restrictinfo()

RestrictInfo* commute_restrictinfo ( RestrictInfo rinfo,
Oid  comm_op 
)

Definition at line 329 of file restrictinfo.c.

330 {
331  RestrictInfo *result;
332  OpExpr *newclause;
333  OpExpr *clause = castNode(OpExpr, rinfo->clause);
334 
335  Assert(list_length(clause->args) == 2);
336 
337  /* flat-copy all the fields of clause ... */
338  newclause = makeNode(OpExpr);
339  memcpy(newclause, clause, sizeof(OpExpr));
340 
341  /* ... and adjust those we need to change to commute it */
342  newclause->opno = comm_op;
343  newclause->opfuncid = InvalidOid;
344  newclause->args = list_make2(lsecond(clause->args),
345  linitial(clause->args));
346 
347  /* likewise, flat-copy all the fields of rinfo ... */
348  result = makeNode(RestrictInfo);
349  memcpy(result, rinfo, sizeof(RestrictInfo));
350 
351  /*
352  * ... and adjust those we need to change. Note in particular that we can
353  * preserve any cached selectivity or cost estimates, since those ought to
354  * be the same for the new clause. Likewise we can keep the source's
355  * parent_ec. It's also important that we keep the same rinfo_serial.
356  */
357  result->clause = (Expr *) newclause;
358  result->left_relids = rinfo->right_relids;
359  result->right_relids = rinfo->left_relids;
360  Assert(result->orclause == NULL);
361  result->left_ec = rinfo->right_ec;
362  result->right_ec = rinfo->left_ec;
363  result->left_em = rinfo->right_em;
364  result->right_em = rinfo->left_em;
365  result->scansel_cache = NIL; /* not worth updating this */
366  if (rinfo->hashjoinoperator == clause->opno)
367  result->hashjoinoperator = comm_op;
368  else
369  result->hashjoinoperator = InvalidOid;
370  result->left_bucketsize = rinfo->right_bucketsize;
371  result->right_bucketsize = rinfo->left_bucketsize;
372  result->left_mcvfreq = rinfo->right_mcvfreq;
373  result->right_mcvfreq = rinfo->left_mcvfreq;
374  result->left_hasheqoperator = InvalidOid;
375  result->right_hasheqoperator = InvalidOid;
376 
377  return result;
378 }
Assert(fmt[strlen(fmt) - 1] !='\n')
#define makeNode(_type_)
Definition: nodes.h:176
#define castNode(_type_, nodeptr)
Definition: nodes.h:197
static int list_length(const List *l)
Definition: pg_list.h:152
#define NIL
Definition: pg_list.h:68
#define linitial(l)
Definition: pg_list.h:178
#define lsecond(l)
Definition: pg_list.h:183
#define list_make2(x1, x2)
Definition: pg_list.h:214
#define InvalidOid
Definition: postgres_ext.h:36
Oid opno
Definition: primnodes.h:745
List * args
Definition: primnodes.h:763
Expr * clause
Definition: pathnodes.h:2513

References OpExpr::args, Assert(), castNode, RestrictInfo::clause, InvalidOid, linitial, list_length(), list_make2, lsecond, makeNode, NIL, and OpExpr::opno.

Referenced by match_opclause_to_indexcol().

◆ extract_actual_clauses()

List* extract_actual_clauses ( List restrictinfo_list,
bool  pseudoconstant 
)

Definition at line 464 of file restrictinfo.c.

466 {
467  List *result = NIL;
468  ListCell *l;
469 
470  foreach(l, restrictinfo_list)
471  {
473 
474  if (rinfo->pseudoconstant == pseudoconstant &&
475  !rinfo_is_constant_true(rinfo))
476  result = lappend(result, rinfo->clause);
477  }
478  return result;
479 }
List * lappend(List *list, void *datum)
Definition: list.c:338
#define lfirst_node(type, lc)
Definition: pg_list.h:176
static bool rinfo_is_constant_true(RestrictInfo *rinfo)
Definition: restrictinfo.c:423
Definition: pg_list.h:54

References RestrictInfo::clause, lappend(), lfirst_node, NIL, and rinfo_is_constant_true().

Referenced by create_append_plan(), create_bitmap_scan_plan(), create_ctescan_plan(), create_functionscan_plan(), create_hashjoin_plan(), create_indexscan_plan(), create_merge_append_plan(), create_mergejoin_plan(), create_namedtuplestorescan_plan(), create_nestloop_plan(), create_resultscan_plan(), create_samplescan_plan(), create_seqscan_plan(), create_subqueryscan_plan(), create_tablefuncscan_plan(), create_tidrangescan_plan(), create_tidscan_plan(), create_valuesscan_plan(), create_worktablescan_plan(), fileGetForeignPlan(), get_gating_quals(), and postgresGetForeignPlan().

◆ extract_actual_join_clauses()

void extract_actual_join_clauses ( List restrictinfo_list,
Relids  joinrelids,
List **  joinquals,
List **  otherquals 
)

Definition at line 492 of file restrictinfo.c.

496 {
497  ListCell *l;
498 
499  *joinquals = NIL;
500  *otherquals = NIL;
501 
502  foreach(l, restrictinfo_list)
503  {
505 
506  if (RINFO_IS_PUSHED_DOWN(rinfo, joinrelids))
507  {
508  if (!rinfo->pseudoconstant &&
509  !rinfo_is_constant_true(rinfo))
510  *otherquals = lappend(*otherquals, rinfo->clause);
511  }
512  else
513  {
514  /* joinquals shouldn't have been marked pseudoconstant */
515  Assert(!rinfo->pseudoconstant);
517  *joinquals = lappend(*joinquals, rinfo->clause);
518  }
519  }
520 }
#define RINFO_IS_PUSHED_DOWN(rinfo, joinrelids)
Definition: pathnodes.h:2664

References Assert(), RestrictInfo::clause, lappend(), lfirst_node, NIL, rinfo_is_constant_true(), and RINFO_IS_PUSHED_DOWN.

Referenced by create_hashjoin_plan(), create_mergejoin_plan(), and create_nestloop_plan().

◆ get_actual_clauses()

List* get_actual_clauses ( List restrictinfo_list)

Definition at line 439 of file restrictinfo.c.

440 {
441  List *result = NIL;
442  ListCell *l;
443 
444  foreach(l, restrictinfo_list)
445  {
447 
448  Assert(!rinfo->pseudoconstant);
450 
451  result = lappend(result, rinfo->clause);
452  }
453  return result;
454 }

References Assert(), RestrictInfo::clause, lappend(), lfirst_node, NIL, and rinfo_is_constant_true().

Referenced by create_bitmap_subplan(), create_hashjoin_plan(), create_join_plan(), and create_mergejoin_plan().

◆ join_clause_is_movable_into()

bool join_clause_is_movable_into ( RestrictInfo rinfo,
Relids  currentrelids,
Relids  current_and_outer 
)

Definition at line 693 of file restrictinfo.c.

696 {
697  /* Clause must be evaluable given available context */
698  if (!bms_is_subset(rinfo->clause_relids, current_and_outer))
699  return false;
700 
701  /* Clause must physically reference at least one target rel */
702  if (!bms_overlap(currentrelids, rinfo->clause_relids))
703  return false;
704 
705  /* Cannot move an outer-join clause into the join's outer side */
706  if (bms_overlap(currentrelids, rinfo->outer_relids))
707  return false;
708 
709  return true;
710 }
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:332
Relids outer_relids
Definition: pathnodes.h:2547

References bms_is_subset(), bms_overlap(), and RestrictInfo::outer_relids.

Referenced by get_baserel_parampathinfo(), get_joinrel_parampathinfo(), and has_indexed_join_quals().

◆ join_clause_is_movable_to()

bool join_clause_is_movable_to ( RestrictInfo rinfo,
RelOptInfo baserel 
)

Definition at line 607 of file restrictinfo.c.

608 {
609  /* Clause must physically reference target rel */
610  if (!bms_is_member(baserel->relid, rinfo->clause_relids))
611  return false;
612 
613  /* Cannot move an outer-join clause into the join's outer side */
614  if (bms_is_member(baserel->relid, rinfo->outer_relids))
615  return false;
616 
617  /*
618  * Target rel's Vars must not be nulled by any outer join. We can check
619  * this without groveling through the individual Vars by seeing whether
620  * clause_relids (which includes all such Vars' varnullingrels) includes
621  * any outer join that can null the target rel. You might object that
622  * this could reject the clause on the basis of an OJ relid that came from
623  * some other rel's Var. However, that would still mean that the clause
624  * came from above that outer join and shouldn't be pushed down; so there
625  * should be no false positives.
626  */
627  if (bms_overlap(rinfo->clause_relids, baserel->nulling_relids))
628  return false;
629 
630  /* Clause must not use any rels with LATERAL references to this rel */
631  if (bms_overlap(baserel->lateral_referencers, rinfo->clause_relids))
632  return false;
633 
634  /* Ignore clones, too */
635  if (rinfo->is_clone)
636  return false;
637 
638  return true;
639 }
Index relid
Definition: pathnodes.h:909
Relids lateral_referencers
Definition: pathnodes.h:927
Relids nulling_relids
Definition: pathnodes.h:923

References bms_is_member(), bms_overlap(), RestrictInfo::is_clone, RelOptInfo::lateral_referencers, RelOptInfo::nulling_relids, RestrictInfo::outer_relids, and RelOptInfo::relid.

Referenced by BuildParameterizedTidPaths(), check_index_predicates(), extract_restriction_or_clauses(), match_join_clauses_to_index(), and postgresGetForeignPaths().

◆ make_restrictinfo()

RestrictInfo* make_restrictinfo ( PlannerInfo root,
Expr clause,
bool  is_pushed_down,
bool  pseudoconstant,
Index  security_level,
Relids  required_relids,
Relids  outer_relids 
)

Definition at line 61 of file restrictinfo.c.

68 {
69  /*
70  * If it's an OR clause, build a modified copy with RestrictInfos inserted
71  * above each subclause of the top-level AND/OR structure.
72  */
73  if (is_orclause(clause))
74  return (RestrictInfo *) make_sub_restrictinfos(root,
75  clause,
76  is_pushed_down,
77  pseudoconstant,
78  security_level,
79  required_relids,
80  outer_relids);
81 
82  /* Shouldn't be an AND clause, else AND/OR flattening messed up */
83  Assert(!is_andclause(clause));
84 
85  return make_restrictinfo_internal(root,
86  clause,
87  NULL,
88  is_pushed_down,
89  pseudoconstant,
90  security_level,
91  required_relids,
92  outer_relids);
93 }
static bool is_andclause(const void *clause)
Definition: nodeFuncs.h:105
static bool is_orclause(const void *clause)
Definition: nodeFuncs.h:114
static RestrictInfo * make_restrictinfo_internal(PlannerInfo *root, Expr *clause, Expr *orclause, bool is_pushed_down, bool pseudoconstant, Index security_level, Relids required_relids, Relids outer_relids)
Definition: restrictinfo.c:101
static Expr * make_sub_restrictinfos(PlannerInfo *root, Expr *clause, bool is_pushed_down, bool pseudoconstant, Index security_level, Relids required_relids, Relids outer_relids)
Definition: restrictinfo.c:256

References Assert(), is_andclause(), is_orclause(), make_restrictinfo_internal(), and make_sub_restrictinfos().

Referenced by apply_child_basequals(), build_implied_join_equality(), consider_new_or_clause(), distribute_qual_to_rels(), foreign_grouping_ok(), process_equivalence(), process_implied_equality(), and reconsider_outer_join_clauses().

◆ restriction_is_or_clause()

bool restriction_is_or_clause ( RestrictInfo restrictinfo)

Definition at line 386 of file restrictinfo.c.

387 {
388  if (restrictinfo->orclause != NULL)
389  return true;
390  else
391  return false;
392 }

Referenced by extract_or_clause(), extract_restriction_or_clauses(), generate_bitmap_or_paths(), match_join_clauses_to_index(), remove_rel_from_restrictinfo(), and TidQualFromRestrictInfoList().

◆ restriction_is_securely_promotable()

bool restriction_is_securely_promotable ( RestrictInfo restrictinfo,
RelOptInfo rel 
)

Definition at line 401 of file restrictinfo.c.

403 {
404  /*
405  * It's okay if there are no baserestrictinfo clauses for the rel that
406  * would need to go before this one, *or* if this one is leakproof.
407  */
408  if (restrictinfo->security_level <= rel->baserestrict_min_security ||
409  restrictinfo->leakproof)
410  return true;
411  else
412  return false;
413 }
Index baserestrict_min_security
Definition: pathnodes.h:974
Index security_level
Definition: pathnodes.h:2535

References RelOptInfo::baserestrict_min_security, and RestrictInfo::security_level.

Referenced by BuildParameterizedTidPaths(), match_clause_to_index(), and TidQualFromRestrictInfo().