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, false, 0, NULL, NULL, NULL)
 

Functions

RestrictInfomake_restrictinfo (PlannerInfo *root, Expr *clause, bool is_pushed_down, bool outerjoin_delayed, bool pseudoconstant, Index security_level, Relids required_relids, Relids outer_relids, Relids nullable_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 
)    make_restrictinfo(root, clause, true, false, false, 0, NULL, NULL, NULL)

Function Documentation

◆ commute_restrictinfo()

RestrictInfo* commute_restrictinfo ( RestrictInfo rinfo,
Oid  comm_op 
)

Definition at line 326 of file restrictinfo.c.

References OpExpr::args, Assert, castNode, RestrictInfo::clause, RestrictInfo::hasheqoperator, RestrictInfo::hashjoinoperator, InvalidOid, RestrictInfo::left_bucketsize, RestrictInfo::left_ec, RestrictInfo::left_em, RestrictInfo::left_mcvfreq, RestrictInfo::left_relids, linitial, list_length(), list_make2, lsecond, makeNode, NIL, OpExpr::opfuncid, OpExpr::opno, RestrictInfo::orclause, RestrictInfo::right_bucketsize, RestrictInfo::right_ec, RestrictInfo::right_em, RestrictInfo::right_mcvfreq, RestrictInfo::right_relids, and RestrictInfo::scansel_cache.

Referenced by match_opclause_to_indexcol().

327 {
328  RestrictInfo *result;
329  OpExpr *newclause;
330  OpExpr *clause = castNode(OpExpr, rinfo->clause);
331 
332  Assert(list_length(clause->args) == 2);
333 
334  /* flat-copy all the fields of clause ... */
335  newclause = makeNode(OpExpr);
336  memcpy(newclause, clause, sizeof(OpExpr));
337 
338  /* ... and adjust those we need to change to commute it */
339  newclause->opno = comm_op;
340  newclause->opfuncid = InvalidOid;
341  newclause->args = list_make2(lsecond(clause->args),
342  linitial(clause->args));
343 
344  /* likewise, flat-copy all the fields of rinfo ... */
345  result = makeNode(RestrictInfo);
346  memcpy(result, rinfo, sizeof(RestrictInfo));
347 
348  /*
349  * ... and adjust those we need to change. Note in particular that we can
350  * preserve any cached selectivity or cost estimates, since those ought to
351  * be the same for the new clause. Likewise we can keep the source's
352  * parent_ec.
353  */
354  result->clause = (Expr *) newclause;
355  result->left_relids = rinfo->right_relids;
356  result->right_relids = rinfo->left_relids;
357  Assert(result->orclause == NULL);
358  result->left_ec = rinfo->right_ec;
359  result->right_ec = rinfo->left_ec;
360  result->left_em = rinfo->right_em;
361  result->right_em = rinfo->left_em;
362  result->scansel_cache = NIL; /* not worth updating this */
363  if (rinfo->hashjoinoperator == clause->opno)
364  result->hashjoinoperator = comm_op;
365  else
366  result->hashjoinoperator = InvalidOid;
367  result->left_bucketsize = rinfo->right_bucketsize;
368  result->right_bucketsize = rinfo->left_bucketsize;
369  result->left_mcvfreq = rinfo->right_mcvfreq;
370  result->right_mcvfreq = rinfo->left_mcvfreq;
371  result->hasheqoperator = InvalidOid;
372 
373  return result;
374 }
#define list_make2(x1, x2)
Definition: pg_list.h:208
#define NIL
Definition: pg_list.h:65
Selectivity right_mcvfreq
Definition: pathnodes.h:2123
#define castNode(_type_, nodeptr)
Definition: nodes.h:605
Expr * orclause
Definition: pathnodes.h:2090
Relids left_relids
Definition: pathnodes.h:2086
EquivalenceClass * right_ec
Definition: pathnodes.h:2108
#define lsecond(l)
Definition: pg_list.h:179
#define linitial(l)
Definition: pg_list.h:174
EquivalenceMember * left_em
Definition: pathnodes.h:2109
Oid hasheqoperator
Definition: pathnodes.h:2126
EquivalenceMember * right_em
Definition: pathnodes.h:2110
Expr * clause
Definition: pathnodes.h:2056
Oid opfuncid
Definition: primnodes.h:543
#define InvalidOid
Definition: postgres_ext.h:36
Selectivity left_bucketsize
Definition: pathnodes.h:2120
#define makeNode(_type_)
Definition: nodes.h:584
Relids right_relids
Definition: pathnodes.h:2087
#define Assert(condition)
Definition: c.h:804
Selectivity left_mcvfreq
Definition: pathnodes.h:2122
Oid hashjoinoperator
Definition: pathnodes.h:2117
static int list_length(const List *l)
Definition: pg_list.h:149
Selectivity right_bucketsize
Definition: pathnodes.h:2121
EquivalenceClass * left_ec
Definition: pathnodes.h:2107
Oid opno
Definition: primnodes.h:542
List * args
Definition: primnodes.h:548
List * scansel_cache
Definition: pathnodes.h:2111

◆ extract_actual_clauses()

List* extract_actual_clauses ( List restrictinfo_list,
bool  pseudoconstant 
)

◆ extract_actual_join_clauses()

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

Definition at line 470 of file restrictinfo.c.

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

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

474 {
475  ListCell *l;
476 
477  *joinquals = NIL;
478  *otherquals = NIL;
479 
480  foreach(l, restrictinfo_list)
481  {
483 
484  if (RINFO_IS_PUSHED_DOWN(rinfo, joinrelids))
485  {
486  if (!rinfo->pseudoconstant)
487  *otherquals = lappend(*otherquals, rinfo->clause);
488  }
489  else
490  {
491  /* joinquals shouldn't have been marked pseudoconstant */
492  Assert(!rinfo->pseudoconstant);
493  *joinquals = lappend(*joinquals, rinfo->clause);
494  }
495  }
496 }
#define NIL
Definition: pg_list.h:65
bool pseudoconstant
Definition: pathnodes.h:2064
#define lfirst_node(type, lc)
Definition: pg_list.h:172
List * lappend(List *list, void *datum)
Definition: list.c:336
Expr * clause
Definition: pathnodes.h:2056
#define RINFO_IS_PUSHED_DOWN(rinfo, joinrelids)
Definition: pathnodes.h:2139
#define Assert(condition)
Definition: c.h:804

◆ get_actual_clauses()

List* get_actual_clauses ( List restrictinfo_list)

Definition at line 420 of file restrictinfo.c.

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

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

421 {
422  List *result = NIL;
423  ListCell *l;
424 
425  foreach(l, restrictinfo_list)
426  {
428 
429  Assert(!rinfo->pseudoconstant);
430 
431  result = lappend(result, rinfo->clause);
432  }
433  return result;
434 }
#define NIL
Definition: pg_list.h:65
bool pseudoconstant
Definition: pathnodes.h:2064
#define lfirst_node(type, lc)
Definition: pg_list.h:172
List * lappend(List *list, void *datum)
Definition: list.c:336
Expr * clause
Definition: pathnodes.h:2056
#define Assert(condition)
Definition: c.h:804
Definition: pg_list.h:50

◆ join_clause_is_movable_into()

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

Definition at line 598 of file restrictinfo.c.

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

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

601 {
602  /* Clause must be evaluable given available context */
603  if (!bms_is_subset(rinfo->clause_relids, current_and_outer))
604  return false;
605 
606  /* Clause must physically reference at least one target rel */
607  if (!bms_overlap(currentrelids, rinfo->clause_relids))
608  return false;
609 
610  /* Cannot move an outer-join clause into the join's outer side */
611  if (bms_overlap(currentrelids, rinfo->outer_relids))
612  return false;
613 
614  /*
615  * Target rel(s) must not be nullable below the clause. This is
616  * approximate, in the safe direction, because the current join might be
617  * above the join where the nulling would happen, in which case the clause
618  * would work correctly here. But we don't have enough info to be sure.
619  */
620  if (bms_overlap(currentrelids, rinfo->nullable_relids))
621  return false;
622 
623  return true;
624 }
Relids clause_relids
Definition: pathnodes.h:2074
Relids outer_relids
Definition: pathnodes.h:2080
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:315
Relids nullable_relids
Definition: pathnodes.h:2083
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:494

◆ join_clause_is_movable_to()

bool join_clause_is_movable_to ( RestrictInfo rinfo,
RelOptInfo baserel 
)

Definition at line 525 of file restrictinfo.c.

References bms_is_member(), bms_overlap(), RestrictInfo::clause_relids, RelOptInfo::lateral_referencers, RestrictInfo::nullable_relids, RestrictInfo::outer_relids, and RelOptInfo::relid.

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

526 {
527  /* Clause must physically reference target rel */
528  if (!bms_is_member(baserel->relid, rinfo->clause_relids))
529  return false;
530 
531  /* Cannot move an outer-join clause into the join's outer side */
532  if (bms_is_member(baserel->relid, rinfo->outer_relids))
533  return false;
534 
535  /* Target rel must not be nullable below the clause */
536  if (bms_is_member(baserel->relid, rinfo->nullable_relids))
537  return false;
538 
539  /* Clause must not use any rels with LATERAL references to this rel */
540  if (bms_overlap(baserel->lateral_referencers, rinfo->clause_relids))
541  return false;
542 
543  return true;
544 }
Relids clause_relids
Definition: pathnodes.h:2074
Relids outer_relids
Definition: pathnodes.h:2080
Index relid
Definition: pathnodes.h:709
Relids lateral_referencers
Definition: pathnodes.h:717
Relids nullable_relids
Definition: pathnodes.h:2083
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:494
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:427

◆ make_restrictinfo()

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

Definition at line 61 of file restrictinfo.c.

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(), and process_implied_equality().

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

◆ restriction_is_or_clause()

bool restriction_is_or_clause ( RestrictInfo restrictinfo)

Definition at line 382 of file restrictinfo.c.

References RestrictInfo::orclause.

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

383 {
384  if (restrictinfo->orclause != NULL)
385  return true;
386  else
387  return false;
388 }
Expr * orclause
Definition: pathnodes.h:2090

◆ restriction_is_securely_promotable()

bool restriction_is_securely_promotable ( RestrictInfo restrictinfo,
RelOptInfo rel 
)

Definition at line 397 of file restrictinfo.c.

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

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

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