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)
 

Functions

RestrictInfomake_restrictinfo (PlannerInfo *root, Expr *clause, bool is_pushed_down, bool has_clone, bool is_clone, bool pseudoconstant, Index security_level, Relids required_relids, Relids incompatible_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 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 
)
Value:
make_restrictinfo(root, clause, true, false, false, false, 0, \
NULL, NULL, NULL)
tree ctl root
Definition: radixtree.h:1840
RestrictInfo * make_restrictinfo(PlannerInfo *root, Expr *clause, bool is_pushed_down, bool has_clone, bool is_clone, bool pseudoconstant, Index security_level, Relids required_relids, Relids incompatible_relids, Relids outer_relids)
Definition: restrictinfo.c:63

Definition at line 21 of file restrictinfo.h.

Function Documentation

◆ commute_restrictinfo()

RestrictInfo* commute_restrictinfo ( RestrictInfo rinfo,
Oid  comm_op 
)

Definition at line 359 of file restrictinfo.c.

360 {
361  RestrictInfo *result;
362  OpExpr *newclause;
363  OpExpr *clause = castNode(OpExpr, rinfo->clause);
364 
365  Assert(list_length(clause->args) == 2);
366 
367  /* flat-copy all the fields of clause ... */
368  newclause = makeNode(OpExpr);
369  memcpy(newclause, clause, sizeof(OpExpr));
370 
371  /* ... and adjust those we need to change to commute it */
372  newclause->opno = comm_op;
373  newclause->opfuncid = InvalidOid;
374  newclause->args = list_make2(lsecond(clause->args),
375  linitial(clause->args));
376 
377  /* likewise, flat-copy all the fields of rinfo ... */
378  result = makeNode(RestrictInfo);
379  memcpy(result, rinfo, sizeof(RestrictInfo));
380 
381  /*
382  * ... and adjust those we need to change. Note in particular that we can
383  * preserve any cached selectivity or cost estimates, since those ought to
384  * be the same for the new clause. Likewise we can keep the source's
385  * parent_ec. It's also important that we keep the same rinfo_serial.
386  */
387  result->clause = (Expr *) newclause;
388  result->left_relids = rinfo->right_relids;
389  result->right_relids = rinfo->left_relids;
390  Assert(result->orclause == NULL);
391  result->left_ec = rinfo->right_ec;
392  result->right_ec = rinfo->left_ec;
393  result->left_em = rinfo->right_em;
394  result->right_em = rinfo->left_em;
395  result->scansel_cache = NIL; /* not worth updating this */
396  if (rinfo->hashjoinoperator == clause->opno)
397  result->hashjoinoperator = comm_op;
398  else
399  result->hashjoinoperator = InvalidOid;
400  result->left_bucketsize = rinfo->right_bucketsize;
401  result->right_bucketsize = rinfo->left_bucketsize;
402  result->left_mcvfreq = rinfo->right_mcvfreq;
403  result->right_mcvfreq = rinfo->left_mcvfreq;
404  result->left_hasheqoperator = InvalidOid;
405  result->right_hasheqoperator = InvalidOid;
406 
407  return result;
408 }
Assert(fmt[strlen(fmt) - 1] !='\n')
#define makeNode(_type_)
Definition: nodes.h:155
#define castNode(_type_, nodeptr)
Definition: nodes.h:176
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:774
List * args
Definition: primnodes.h:792
Expr * clause
Definition: pathnodes.h:2546

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 494 of file restrictinfo.c.

496 {
497  List *result = NIL;
498  ListCell *l;
499 
500  foreach(l, restrictinfo_list)
501  {
503 
504  if (rinfo->pseudoconstant == pseudoconstant &&
505  !rinfo_is_constant_true(rinfo))
506  result = lappend(result, rinfo->clause);
507  }
508  return result;
509 }
List * lappend(List *list, void *datum)
Definition: list.c:339
#define lfirst_node(type, lc)
Definition: pg_list.h:176
static bool rinfo_is_constant_true(RestrictInfo *rinfo)
Definition: restrictinfo.c:453
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 522 of file restrictinfo.c.

526 {
527  ListCell *l;
528 
529  *joinquals = NIL;
530  *otherquals = NIL;
531 
532  foreach(l, restrictinfo_list)
533  {
535 
536  if (RINFO_IS_PUSHED_DOWN(rinfo, joinrelids))
537  {
538  if (!rinfo->pseudoconstant &&
539  !rinfo_is_constant_true(rinfo))
540  *otherquals = lappend(*otherquals, rinfo->clause);
541  }
542  else
543  {
544  /* joinquals shouldn't have been marked pseudoconstant */
545  Assert(!rinfo->pseudoconstant);
546  if (!rinfo_is_constant_true(rinfo))
547  *joinquals = lappend(*joinquals, rinfo->clause);
548  }
549  }
550 }
#define RINFO_IS_PUSHED_DOWN(rinfo, joinrelids)
Definition: pathnodes.h:2703

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 469 of file restrictinfo.c.

470 {
471  List *result = NIL;
472  ListCell *l;
473 
474  foreach(l, restrictinfo_list)
475  {
477 
478  Assert(!rinfo->pseudoconstant);
480 
481  result = lappend(result, rinfo->clause);
482  }
483  return result;
484 }

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 670 of file restrictinfo.c.

673 {
674  /* Clause must be evaluable given available context */
675  if (!bms_is_subset(rinfo->clause_relids, current_and_outer))
676  return false;
677 
678  /* Clause must physically reference at least one target rel */
679  if (!bms_overlap(currentrelids, rinfo->clause_relids))
680  return false;
681 
682  /* Cannot move an outer-join clause into the join's outer side */
683  if (bms_overlap(currentrelids, rinfo->outer_relids))
684  return false;
685 
686  return true;
687 }
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:412
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:582
Relids outer_relids
Definition: pathnodes.h:2583

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 584 of file restrictinfo.c.

585 {
586  /* Clause must physically reference target rel */
587  if (!bms_is_member(baserel->relid, rinfo->clause_relids))
588  return false;
589 
590  /* Cannot move an outer-join clause into the join's outer side */
591  if (bms_is_member(baserel->relid, rinfo->outer_relids))
592  return false;
593 
594  /*
595  * Target rel's Vars must not be nulled by any outer join. We can check
596  * this without groveling through the individual Vars by seeing whether
597  * clause_relids (which includes all such Vars' varnullingrels) includes
598  * any outer join that can null the target rel. You might object that
599  * this could reject the clause on the basis of an OJ relid that came from
600  * some other rel's Var. However, that would still mean that the clause
601  * came from above that outer join and shouldn't be pushed down; so there
602  * should be no false positives.
603  */
604  if (bms_overlap(rinfo->clause_relids, baserel->nulling_relids))
605  return false;
606 
607  /* Clause must not use any rels with LATERAL references to this rel */
608  if (bms_overlap(baserel->lateral_referencers, rinfo->clause_relids))
609  return false;
610 
611  /* Ignore clones, too */
612  if (rinfo->is_clone)
613  return false;
614 
615  return true;
616 }
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:510
Index relid
Definition: pathnodes.h:908
Relids lateral_referencers
Definition: pathnodes.h:928
Relids nulling_relids
Definition: pathnodes.h:924

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  has_clone,
bool  is_clone,
bool  pseudoconstant,
Index  security_level,
Relids  required_relids,
Relids  incompatible_relids,
Relids  outer_relids 
)

Definition at line 63 of file restrictinfo.c.

73 {
74  /*
75  * If it's an OR clause, build a modified copy with RestrictInfos inserted
76  * above each subclause of the top-level AND/OR structure.
77  */
78  if (is_orclause(clause))
80  clause,
81  is_pushed_down,
82  has_clone,
83  is_clone,
84  pseudoconstant,
85  security_level,
86  required_relids,
87  incompatible_relids,
88  outer_relids);
89 
90  /* Shouldn't be an AND clause, else AND/OR flattening messed up */
91  Assert(!is_andclause(clause));
92 
94  clause,
95  NULL,
96  is_pushed_down,
97  has_clone,
98  is_clone,
99  pseudoconstant,
100  security_level,
101  required_relids,
102  incompatible_relids,
103  outer_relids);
104 }
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 has_clone, bool is_clone, bool pseudoconstant, Index security_level, Relids required_relids, Relids incompatible_relids, Relids outer_relids)
Definition: restrictinfo.c:112
static Expr * make_sub_restrictinfos(PlannerInfo *root, Expr *clause, bool is_pushed_down, bool has_clone, bool is_clone, bool pseudoconstant, Index security_level, Relids required_relids, Relids incompatible_relids, Relids outer_relids)
Definition: restrictinfo.c:271

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

Referenced by add_base_clause_to_rel(), add_join_clause_to_rels(), 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 416 of file restrictinfo.c.

417 {
418  if (restrictinfo->orclause != NULL)
419  return true;
420  else
421  return false;
422 }

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

◆ restriction_is_securely_promotable()

bool restriction_is_securely_promotable ( RestrictInfo restrictinfo,
RelOptInfo rel 
)

Definition at line 431 of file restrictinfo.c.

433 {
434  /*
435  * It's okay if there are no baserestrictinfo clauses for the rel that
436  * would need to go before this one, *or* if this one is leakproof.
437  */
438  if (restrictinfo->security_level <= rel->baserestrict_min_security ||
439  restrictinfo->leakproof)
440  return true;
441  else
442  return false;
443 }
Index baserestrict_min_security
Definition: pathnodes.h:975
Index security_level
Definition: pathnodes.h:2568

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

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