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

Go to the source code of this file.

Functions

void extract_restriction_or_clauses (PlannerInfo *root)
 

Function Documentation

◆ extract_restriction_or_clauses()

void extract_restriction_or_clauses ( PlannerInfo root)

Definition at line 76 of file orclauses.c.

References Assert, consider_new_or_clause(), extract_or_clause(), join_clause_is_movable_to(), RelOptInfo::joininfo, lfirst, RestrictInfo::norm_selec, RelOptInfo::relid, RELOPT_BASEREL, RelOptInfo::reloptkind, restriction_is_or_clause(), PlannerInfo::simple_rel_array, and PlannerInfo::simple_rel_array_size.

Referenced by query_planner().

77 {
78  Index rti;
79 
80  /* Examine each baserel for potential join OR clauses */
81  for (rti = 1; rti < root->simple_rel_array_size; rti++)
82  {
83  RelOptInfo *rel = root->simple_rel_array[rti];
84  ListCell *lc;
85 
86  /* there may be empty slots corresponding to non-baserel RTEs */
87  if (rel == NULL)
88  continue;
89 
90  Assert(rel->relid == rti); /* sanity check on array */
91 
92  /* ignore RTEs that are "other rels" */
93  if (rel->reloptkind != RELOPT_BASEREL)
94  continue;
95 
96  /*
97  * Find potentially interesting OR joinclauses. We can use any
98  * joinclause that is considered safe to move to this rel by the
99  * parameterized-path machinery, even though what we are going to do
100  * with it is not exactly a parameterized path.
101  *
102  * However, it seems best to ignore clauses that have been marked
103  * redundant (by setting norm_selec > 1). That likely can't happen
104  * for OR clauses, but let's be safe.
105  */
106  foreach(lc, rel->joininfo)
107  {
108  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
109 
110  if (restriction_is_or_clause(rinfo) &&
111  join_clause_is_movable_to(rinfo, rel) &&
112  rinfo->norm_selec <= 1)
113  {
114  /* Try to extract a qual for this rel only */
115  Expr *orclause = extract_or_clause(rinfo, rel);
116 
117  /*
118  * If successful, decide whether we want to use the clause,
119  * and insert it into the rel's restrictinfo list if so.
120  */
121  if (orclause)
122  consider_new_or_clause(root, rel, orclause, rinfo);
123  }
124  }
125  }
126 }
RelOptKind reloptkind
Definition: pathnodes.h:638
static Expr * extract_or_clause(RestrictInfo *or_rinfo, RelOptInfo *rel)
Definition: orclauses.c:162
bool restriction_is_or_clause(RestrictInfo *restrictinfo)
Definition: restrictinfo.c:361
Selectivity norm_selec
Definition: pathnodes.h:1981
struct RelOptInfo ** simple_rel_array
Definition: pathnodes.h:201
List * joininfo
Definition: pathnodes.h:707
int simple_rel_array_size
Definition: pathnodes.h:202
Index relid
Definition: pathnodes.h:669
unsigned int Index
Definition: c.h:475
#define Assert(condition)
Definition: c.h:732
#define lfirst(lc)
Definition: pg_list.h:190
bool join_clause_is_movable_to(RestrictInfo *rinfo, RelOptInfo *baserel)
Definition: restrictinfo.c:504
static void consider_new_or_clause(PlannerInfo *root, RelOptInfo *rel, Expr *orclause, RestrictInfo *join_or_rinfo)
Definition: orclauses.c:260