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

Go to the source code of this file.

Functions

bool have_relevant_joinclause (PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
 
void add_join_clause_to_rels (PlannerInfo *root, RestrictInfo *restrictinfo, Relids join_relids)
 
void remove_join_clause_from_rels (PlannerInfo *root, RestrictInfo *restrictinfo, Relids join_relids)
 

Function Documentation

◆ add_join_clause_to_rels()

void add_join_clause_to_rels ( PlannerInfo root,
RestrictInfo restrictinfo,
Relids  join_relids 
)

Definition at line 95 of file joininfo.c.

References bms_next_member(), find_base_rel(), RelOptInfo::joininfo, and lappend().

Referenced by distribute_restrictinfo_to_rels().

98 {
99  int cur_relid;
100 
101  cur_relid = -1;
102  while ((cur_relid = bms_next_member(join_relids, cur_relid)) >= 0)
103  {
104  RelOptInfo *rel = find_base_rel(root, cur_relid);
105 
106  rel->joininfo = lappend(rel->joininfo, restrictinfo);
107  }
108 }
int bms_next_member(const Bitmapset *a, int prevbit)
Definition: bitmapset.c:1009
List * joininfo
Definition: relation.h:649
List * lappend(List *list, void *datum)
Definition: list.c:128
RelOptInfo * find_base_rel(PlannerInfo *root, int relid)
Definition: relnode.c:277

◆ have_relevant_joinclause()

bool have_relevant_joinclause ( PlannerInfo root,
RelOptInfo rel1,
RelOptInfo rel2 
)

Definition at line 36 of file joininfo.c.

References bms_overlap(), RelOptInfo::has_eclass_joins, have_relevant_eclass_joinclause(), RelOptInfo::joininfo, lfirst, list_length(), RelOptInfo::relids, and RestrictInfo::required_relids.

Referenced by desirable_join(), has_legal_joinclause(), join_search_one_level(), and make_rels_by_clause_joins().

38 {
39  bool result = false;
40  List *joininfo;
41  Relids other_relids;
42  ListCell *l;
43 
44  /*
45  * We could scan either relation's joininfo list; may as well use the
46  * shorter one.
47  */
48  if (list_length(rel1->joininfo) <= list_length(rel2->joininfo))
49  {
50  joininfo = rel1->joininfo;
51  other_relids = rel2->relids;
52  }
53  else
54  {
55  joininfo = rel2->joininfo;
56  other_relids = rel1->relids;
57  }
58 
59  foreach(l, joininfo)
60  {
61  RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
62 
63  if (bms_overlap(other_relids, rinfo->required_relids))
64  {
65  result = true;
66  break;
67  }
68  }
69 
70  /*
71  * We also need to check the EquivalenceClass data structure, which might
72  * contain relationships not emitted into the joininfo lists.
73  */
74  if (!result && rel1->has_eclass_joins && rel2->has_eclass_joins)
75  result = have_relevant_eclass_joinclause(root, rel1, rel2);
76 
77  return result;
78 }
bool has_eclass_joins
Definition: relation.h:651
Relids required_relids
Definition: relation.h:1859
List * joininfo
Definition: relation.h:649
Relids relids
Definition: relation.h:585
bool have_relevant_eclass_joinclause(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
Definition: equivclass.c:2343
#define lfirst(lc)
Definition: pg_list.h:106
static int list_length(const List *l)
Definition: pg_list.h:89
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:443
Definition: pg_list.h:45

◆ remove_join_clause_from_rels()

void remove_join_clause_from_rels ( PlannerInfo root,
RestrictInfo restrictinfo,
Relids  join_relids 
)

Definition at line 122 of file joininfo.c.

References Assert, bms_next_member(), find_base_rel(), RelOptInfo::joininfo, list_delete_ptr(), and list_member_ptr().

Referenced by remove_rel_from_query().

125 {
126  int cur_relid;
127 
128  cur_relid = -1;
129  while ((cur_relid = bms_next_member(join_relids, cur_relid)) >= 0)
130  {
131  RelOptInfo *rel = find_base_rel(root, cur_relid);
132 
133  /*
134  * Remove the restrictinfo from the list. Pointer comparison is
135  * sufficient.
136  */
137  Assert(list_member_ptr(rel->joininfo, restrictinfo));
138  rel->joininfo = list_delete_ptr(rel->joininfo, restrictinfo);
139  }
140 }
int bms_next_member(const Bitmapset *a, int prevbit)
Definition: bitmapset.c:1009
List * list_delete_ptr(List *list, void *datum)
Definition: list.c:590
List * joininfo
Definition: relation.h:649
bool list_member_ptr(const List *list, const void *datum)
Definition: list.c:465
#define Assert(condition)
Definition: c.h:680
RelOptInfo * find_base_rel(PlannerInfo *root, int relid)
Definition: relnode.c:277