PostgreSQL Source Code  git master
joininfo.h File Reference
#include "nodes/pathnodes.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.

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_ignore_join(root, cur_relid);
105 
106  /* We only need to add the clause to baserels */
107  if (rel == NULL)
108  continue;
109  rel->joininfo = lappend(rel->joininfo, restrictinfo);
110  }
111 }
int bms_next_member(const Bitmapset *a, int prevbit)
Definition: bitmapset.c:1039
List * lappend(List *list, void *datum)
Definition: list.c:338
RelOptInfo * find_base_rel_ignore_join(PlannerInfo *root, int relid)
Definition: relnode.c:433
List * joininfo
Definition: pathnodes.h:970

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

Referenced by distribute_restrictinfo_to_rels().

◆ have_relevant_joinclause()

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

Definition at line 36 of file joininfo.c.

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 bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:511
bool have_relevant_eclass_joinclause(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
Definition: equivclass.c:3016
#define lfirst(lc)
Definition: pg_list.h:172
static int list_length(const List *l)
Definition: pg_list.h:152
Definition: pg_list.h:54
Relids relids
Definition: pathnodes.h:856
bool has_eclass_joins
Definition: pathnodes.h:972
Relids required_relids
Definition: pathnodes.h:2547

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().

◆ remove_join_clause_from_rels()

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

Definition at line 125 of file joininfo.c.

128 {
129  int cur_relid;
130 
131  cur_relid = -1;
132  while ((cur_relid = bms_next_member(join_relids, cur_relid)) >= 0)
133  {
134  RelOptInfo *rel = find_base_rel_ignore_join(root, cur_relid);
135 
136  /* We would only have added the clause to baserels */
137  if (rel == NULL)
138  continue;
139 
140  /*
141  * Remove the restrictinfo from the list. Pointer comparison is
142  * sufficient.
143  */
144  Assert(list_member_ptr(rel->joininfo, restrictinfo));
145  rel->joininfo = list_delete_ptr(rel->joininfo, restrictinfo);
146  }
147 }
Assert(fmt[strlen(fmt) - 1] !='\n')
List * list_delete_ptr(List *list, void *datum)
Definition: list.c:871
bool list_member_ptr(const List *list, const void *datum)
Definition: list.c:681

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

Referenced by remove_rel_from_query().