PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
relnode.c File Reference
#include "postgres.h"
#include <limits.h>
#include "miscadmin.h"
#include "optimizer/clauses.h"
#include "optimizer/cost.h"
#include "optimizer/pathnode.h"
#include "optimizer/paths.h"
#include "optimizer/placeholder.h"
#include "optimizer/plancat.h"
#include "optimizer/restrictinfo.h"
#include "optimizer/tlist.h"
#include "utils/hsearch.h"
Include dependency graph for relnode.c:

Go to the source code of this file.

Data Structures

struct  JoinHashEntry
 

Typedefs

typedef struct JoinHashEntry JoinHashEntry
 

Functions

static void build_joinrel_tlist (PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *input_rel)
 
static Listbuild_joinrel_restrictlist (PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
 
static void build_joinrel_joinlist (RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
 
static Listsubbuild_joinrel_restrictlist (RelOptInfo *joinrel, List *joininfo_list, List *new_restrictlist)
 
static Listsubbuild_joinrel_joinlist (RelOptInfo *joinrel, List *joininfo_list, List *new_joininfo)
 
void setup_simple_rel_arrays (PlannerInfo *root)
 
RelOptInfobuild_simple_rel (PlannerInfo *root, int relid, RelOptKind reloptkind)
 
RelOptInfofind_base_rel (PlannerInfo *root, int relid)
 
static void build_join_rel_hash (PlannerInfo *root)
 
RelOptInfofind_join_rel (PlannerInfo *root, Relids relids)
 
RelOptInfobuild_join_rel (PlannerInfo *root, Relids joinrelids, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List **restrictlist_ptr)
 
Relids min_join_parameterization (PlannerInfo *root, Relids joinrelids, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
 
RelOptInfobuild_empty_join_rel (PlannerInfo *root)
 
RelOptInfofetch_upper_rel (PlannerInfo *root, UpperRelationKind kind, Relids relids)
 
AppendRelInfofind_childrel_appendrelinfo (PlannerInfo *root, RelOptInfo *rel)
 
RelOptInfofind_childrel_top_parent (PlannerInfo *root, RelOptInfo *rel)
 
Relids find_childrel_parents (PlannerInfo *root, RelOptInfo *rel)
 
ParamPathInfoget_baserel_parampathinfo (PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
 
ParamPathInfoget_joinrel_parampathinfo (PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, Relids required_outer, List **restrict_clauses)
 
ParamPathInfoget_appendrel_parampathinfo (RelOptInfo *appendrel, Relids required_outer)
 

Typedef Documentation

Function Documentation

RelOptInfo* build_empty_join_rel ( PlannerInfo root)

Definition at line 836 of file relnode.c.

References Assert, create_empty_pathtarget(), PlannerInfo::join_rel_list, lappend(), makeNode, NIL, NULL, RelOptInfo::relids, RELOPT_JOINREL, RelOptInfo::reloptkind, RelOptInfo::reltarget, RelOptInfo::rows, RTE_JOIN, and RelOptInfo::rtekind.

Referenced by query_planner().

837 {
838  RelOptInfo *joinrel;
839 
840  /* The dummy join relation should be the only one ... */
841  Assert(root->join_rel_list == NIL);
842 
843  joinrel = makeNode(RelOptInfo);
844  joinrel->reloptkind = RELOPT_JOINREL;
845  joinrel->relids = NULL; /* empty set */
846  joinrel->rows = 1; /* we produce one row for such cases */
847  joinrel->rtekind = RTE_JOIN;
848  joinrel->reltarget = create_empty_pathtarget();
849 
850  root->join_rel_list = lappend(root->join_rel_list, joinrel);
851 
852  return joinrel;
853 }
PathTarget * create_empty_pathtarget(void)
Definition: tlist.c:653
#define NIL
Definition: pg_list.h:69
RelOptKind reloptkind
Definition: relation.h:487
List * join_rel_list
Definition: relation.h:212
Relids relids
Definition: relation.h:490
List * lappend(List *list, void *datum)
Definition: list.c:128
RTEKind rtekind
Definition: relation.h:520
double rows
Definition: relation.h:493
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
struct PathTarget * reltarget
Definition: relation.h:501
RelOptInfo* build_join_rel ( PlannerInfo root,
Relids  joinrelids,
RelOptInfo outer_rel,
RelOptInfo inner_rel,
SpecialJoinInfo sjinfo,
List **  restrictlist_ptr 
)

Definition at line 346 of file relnode.c.

References add_placeholders_to_joinrel(), RelOptInfo::allvisfrac, Assert, RelOptInfo::attr_needed, RelOptInfo::attr_widths, RelOptInfo::baserestrict_min_security, RelOptInfo::baserestrictcost, RelOptInfo::baserestrictinfo, bms_copy(), bms_del_members(), bms_is_empty(), bms_num_members(), bms_union(), build_joinrel_joinlist(), build_joinrel_restrictlist(), build_joinrel_tlist(), RelOptInfo::cheapest_parameterized_paths, RelOptInfo::cheapest_startup_path, RelOptInfo::cheapest_total_path, RelOptInfo::cheapest_unique_path, RelOptInfo::consider_parallel, RelOptInfo::consider_param_startup, RelOptInfo::consider_startup, create_empty_pathtarget(), RelOptInfo::direct_lateral_relids, PathTarget::exprs, RelOptInfo::fdw_private, RelOptInfo::fdwroutine, find_join_rel(), GetUserId(), RelOptInfo::has_eclass_joins, has_relevant_eclass_joinclause(), HASH_ENTER, hash_search(), RelOptInfo::indexlist, InvalidOid, is_parallel_safe(), PlannerInfo::join_cur_level, JoinHashEntry::join_rel, PlannerInfo::join_rel_hash, PlannerInfo::join_rel_level, PlannerInfo::join_rel_list, RelOptInfo::joininfo, lappend(), RelOptInfo::lateral_referencers, RelOptInfo::lateral_relids, RelOptInfo::lateral_vars, makeNode, RelOptInfo::max_attr, RelOptInfo::min_attr, min_join_parameterization(), NIL, NULL, OidIsValid, RelOptInfo::pages, RelOptInfo::partial_pathlist, RelOptInfo::pathlist, QualCost::per_tuple, RelOptInfo::ppilist, RelOptInfo::rel_parallel_workers, RelOptInfo::relid, RelOptInfo::relids, RELOPT_JOINREL, RelOptInfo::reloptkind, RelOptInfo::reltarget, RelOptInfo::rows, RTE_JOIN, RelOptInfo::rtekind, RelOptInfo::serverid, set_joinrel_size_estimates(), QualCost::startup, RelOptInfo::subplan_params, RelOptInfo::subroot, PlannerInfo::tuple_fraction, RelOptInfo::tuples, RelOptInfo::userid, and RelOptInfo::useridiscurrent.

Referenced by make_join_rel().

352 {
353  RelOptInfo *joinrel;
354  List *restrictlist;
355 
356  /*
357  * See if we already have a joinrel for this set of base rels.
358  */
359  joinrel = find_join_rel(root, joinrelids);
360 
361  if (joinrel)
362  {
363  /*
364  * Yes, so we only need to figure the restrictlist for this particular
365  * pair of component relations.
366  */
367  if (restrictlist_ptr)
368  *restrictlist_ptr = build_joinrel_restrictlist(root,
369  joinrel,
370  outer_rel,
371  inner_rel);
372  return joinrel;
373  }
374 
375  /*
376  * Nope, so make one.
377  */
378  joinrel = makeNode(RelOptInfo);
379  joinrel->reloptkind = RELOPT_JOINREL;
380  joinrel->relids = bms_copy(joinrelids);
381  joinrel->rows = 0;
382  /* cheap startup cost is interesting iff not all tuples to be retrieved */
383  joinrel->consider_startup = (root->tuple_fraction > 0);
384  joinrel->consider_param_startup = false;
385  joinrel->consider_parallel = false;
386  joinrel->reltarget = create_empty_pathtarget();
387  joinrel->pathlist = NIL;
388  joinrel->ppilist = NIL;
389  joinrel->partial_pathlist = NIL;
390  joinrel->cheapest_startup_path = NULL;
391  joinrel->cheapest_total_path = NULL;
392  joinrel->cheapest_unique_path = NULL;
394  /* init direct_lateral_relids from children; we'll finish it up below */
395  joinrel->direct_lateral_relids =
396  bms_union(outer_rel->direct_lateral_relids,
397  inner_rel->direct_lateral_relids);
398  joinrel->lateral_relids = min_join_parameterization(root, joinrel->relids,
399  outer_rel, inner_rel);
400  joinrel->relid = 0; /* indicates not a baserel */
401  joinrel->rtekind = RTE_JOIN;
402  joinrel->min_attr = 0;
403  joinrel->max_attr = 0;
404  joinrel->attr_needed = NULL;
405  joinrel->attr_widths = NULL;
406  joinrel->lateral_vars = NIL;
407  joinrel->lateral_referencers = NULL;
408  joinrel->indexlist = NIL;
409  joinrel->pages = 0;
410  joinrel->tuples = 0;
411  joinrel->allvisfrac = 0;
412  joinrel->subroot = NULL;
413  joinrel->subplan_params = NIL;
414  joinrel->rel_parallel_workers = -1;
415  joinrel->serverid = InvalidOid;
416  joinrel->userid = InvalidOid;
417  joinrel->useridiscurrent = false;
418  joinrel->fdwroutine = NULL;
419  joinrel->fdw_private = NULL;
420  joinrel->baserestrictinfo = NIL;
421  joinrel->baserestrictcost.startup = 0;
422  joinrel->baserestrictcost.per_tuple = 0;
423  joinrel->baserestrict_min_security = UINT_MAX;
424  joinrel->joininfo = NIL;
425  joinrel->has_eclass_joins = false;
426 
427  /*
428  * Set up foreign-join fields if outer and inner relation are foreign
429  * tables (or joins) belonging to the same server and assigned to the same
430  * user to check access permissions as. In addition to an exact match of
431  * userid, we allow the case where one side has zero userid (implying
432  * current user) and the other side has explicit userid that happens to
433  * equal the current user; but in that case, pushdown of the join is only
434  * valid for the current user. The useridiscurrent field records whether
435  * we had to make such an assumption for this join or any sub-join.
436  *
437  * Otherwise these fields are left invalid, so GetForeignJoinPaths will
438  * not be called for the join relation.
439  */
440  if (OidIsValid(outer_rel->serverid) &&
441  inner_rel->serverid == outer_rel->serverid)
442  {
443  if (inner_rel->userid == outer_rel->userid)
444  {
445  joinrel->serverid = outer_rel->serverid;
446  joinrel->userid = outer_rel->userid;
447  joinrel->useridiscurrent = outer_rel->useridiscurrent || inner_rel->useridiscurrent;
448  joinrel->fdwroutine = outer_rel->fdwroutine;
449  }
450  else if (!OidIsValid(inner_rel->userid) &&
451  outer_rel->userid == GetUserId())
452  {
453  joinrel->serverid = outer_rel->serverid;
454  joinrel->userid = outer_rel->userid;
455  joinrel->useridiscurrent = true;
456  joinrel->fdwroutine = outer_rel->fdwroutine;
457  }
458  else if (!OidIsValid(outer_rel->userid) &&
459  inner_rel->userid == GetUserId())
460  {
461  joinrel->serverid = outer_rel->serverid;
462  joinrel->userid = inner_rel->userid;
463  joinrel->useridiscurrent = true;
464  joinrel->fdwroutine = outer_rel->fdwroutine;
465  }
466  }
467 
468  /*
469  * Create a new tlist containing just the vars that need to be output from
470  * this join (ie, are needed for higher joinclauses or final output).
471  *
472  * NOTE: the tlist order for a join rel will depend on which pair of outer
473  * and inner rels we first try to build it from. But the contents should
474  * be the same regardless.
475  */
476  build_joinrel_tlist(root, joinrel, outer_rel);
477  build_joinrel_tlist(root, joinrel, inner_rel);
478  add_placeholders_to_joinrel(root, joinrel, outer_rel, inner_rel);
479 
480  /*
481  * add_placeholders_to_joinrel also took care of adding the ph_lateral
482  * sets of any PlaceHolderVars computed here to direct_lateral_relids, so
483  * now we can finish computing that. This is much like the computation of
484  * the transitively-closed lateral_relids in min_join_parameterization,
485  * except that here we *do* have to consider the added PHVs.
486  */
487  joinrel->direct_lateral_relids =
488  bms_del_members(joinrel->direct_lateral_relids, joinrel->relids);
489  if (bms_is_empty(joinrel->direct_lateral_relids))
490  joinrel->direct_lateral_relids = NULL;
491 
492  /*
493  * Construct restrict and join clause lists for the new joinrel. (The
494  * caller might or might not need the restrictlist, but I need it anyway
495  * for set_joinrel_size_estimates().)
496  */
497  restrictlist = build_joinrel_restrictlist(root, joinrel,
498  outer_rel, inner_rel);
499  if (restrictlist_ptr)
500  *restrictlist_ptr = restrictlist;
501  build_joinrel_joinlist(joinrel, outer_rel, inner_rel);
502 
503  /*
504  * This is also the right place to check whether the joinrel has any
505  * pending EquivalenceClass joins.
506  */
507  joinrel->has_eclass_joins = has_relevant_eclass_joinclause(root, joinrel);
508 
509  /*
510  * Set estimates of the joinrel's size.
511  */
512  set_joinrel_size_estimates(root, joinrel, outer_rel, inner_rel,
513  sjinfo, restrictlist);
514 
515  /*
516  * Set the consider_parallel flag if this joinrel could potentially be
517  * scanned within a parallel worker. If this flag is false for either
518  * inner_rel or outer_rel, then it must be false for the joinrel also.
519  * Even if both are true, there might be parallel-restricted expressions
520  * in the targetlist or quals.
521  *
522  * Note that if there are more than two rels in this relation, they could
523  * be divided between inner_rel and outer_rel in any arbitrary way. We
524  * assume this doesn't matter, because we should hit all the same baserels
525  * and joinclauses while building up to this joinrel no matter which we
526  * take; therefore, we should make the same decision here however we get
527  * here.
528  */
529  if (inner_rel->consider_parallel && outer_rel->consider_parallel &&
530  is_parallel_safe(root, (Node *) restrictlist) &&
531  is_parallel_safe(root, (Node *) joinrel->reltarget->exprs))
532  joinrel->consider_parallel = true;
533 
534  /*
535  * Add the joinrel to the query's joinrel list, and store it into the
536  * auxiliary hashtable if there is one. NB: GEQO requires us to append
537  * the new joinrel to the end of the list!
538  */
539  root->join_rel_list = lappend(root->join_rel_list, joinrel);
540 
541  if (root->join_rel_hash)
542  {
543  JoinHashEntry *hentry;
544  bool found;
545 
546  hentry = (JoinHashEntry *) hash_search(root->join_rel_hash,
547  &(joinrel->relids),
548  HASH_ENTER,
549  &found);
550  Assert(!found);
551  hentry->join_rel = joinrel;
552  }
553 
554  /*
555  * Also, if dynamic-programming join search is active, add the new joinrel
556  * to the appropriate sublist. Note: you might think the Assert on number
557  * of members should be for equality, but some of the level 1 rels might
558  * have been joinrels already, so we can only assert <=.
559  */
560  if (root->join_rel_level)
561  {
562  Assert(root->join_cur_level > 0);
563  Assert(root->join_cur_level <= bms_num_members(joinrel->relids));
564  root->join_rel_level[root->join_cur_level] =
565  lappend(root->join_rel_level[root->join_cur_level], joinrel);
566  }
567 
568  return joinrel;
569 }
bool has_eclass_joins
Definition: relation.h:551
struct Path * cheapest_unique_path
Definition: relation.h:509
PathTarget * create_empty_pathtarget(void)
Definition: tlist.c:653
#define NIL
Definition: pg_list.h:69
int join_cur_level
Definition: relation.h:223
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:110
RelOptKind reloptkind
Definition: relation.h:487
Relids * attr_needed
Definition: relation.h:523
RelOptInfo * find_join_rel(PlannerInfo *root, Relids relids)
Definition: relnode.c:284
Oid GetUserId(void)
Definition: miscinit.c:282
void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: costsize.c:3845
struct Path * cheapest_startup_path
Definition: relation.h:507
Oid userid
Definition: relation.h:537
double tuples
Definition: relation.h:529
List * baserestrictinfo
Definition: relation.h:544
bool consider_param_startup
Definition: relation.h:497
Definition: nodes.h:509
List * partial_pathlist
Definition: relation.h:506
List * join_rel_list
Definition: relation.h:212
List * cheapest_parameterized_paths
Definition: relation.h:510
Index baserestrict_min_security
Definition: relation.h:547
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:885
bool useridiscurrent
Definition: relation.h:538
#define OidIsValid(objectId)
Definition: c.h:534
void add_placeholders_to_joinrel(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: placeholder.c:411
Cost startup
Definition: relation.h:45
double allvisfrac
Definition: relation.h:530
PlannerInfo * subroot
Definition: relation.h:531
bool consider_startup
Definition: relation.h:496
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:1071
Relids lateral_relids
Definition: relation.h:515
Cost per_tuple
Definition: relation.h:46
double tuple_fraction
Definition: relation.h:286
static void build_joinrel_tlist(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *input_rel)
Definition: relnode.c:623
Relids min_join_parameterization(PlannerInfo *root, Relids joinrelids, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:580
RelOptInfo * join_rel
Definition: relnode.c:34
int bms_num_members(const Bitmapset *a)
Definition: bitmapset.c:575
struct Path * cheapest_total_path
Definition: relation.h:508
static List * build_joinrel_restrictlist(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:709
List * joininfo
Definition: relation.h:549
struct FdwRoutine * fdwroutine
Definition: relation.h:540
Relids relids
Definition: relation.h:490
bool has_relevant_eclass_joinclause(PlannerInfo *root, RelOptInfo *rel1)
Definition: equivclass.c:2354
List * ppilist
Definition: relation.h:505
Index relid
Definition: relation.h:518
List * lappend(List *list, void *datum)
Definition: list.c:128
Relids lateral_referencers
Definition: relation.h:526
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:633
Oid serverid
Definition: relation.h:536
List * exprs
Definition: relation.h:824
Relids direct_lateral_relids
Definition: relation.h:514
int rel_parallel_workers
Definition: relation.h:533
RTEKind rtekind
Definition: relation.h:520
List * indexlist
Definition: relation.h:527
double rows
Definition: relation.h:493
#define InvalidOid
Definition: postgres_ext.h:36
void * fdw_private
Definition: relation.h:541
#define makeNode(_type_)
Definition: nodes.h:557
BlockNumber pages
Definition: relation.h:528
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
List ** join_rel_level
Definition: relation.h:222
List * lateral_vars
Definition: relation.h:525
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:217
struct HTAB * join_rel_hash
Definition: relation.h:213
bool consider_parallel
Definition: relation.h:498
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:787
AttrNumber max_attr
Definition: relation.h:522
List * pathlist
Definition: relation.h:504
int32 * attr_widths
Definition: relation.h:524
Definition: pg_list.h:45
struct PathTarget * reltarget
Definition: relation.h:501
QualCost baserestrictcost
Definition: relation.h:546
List * subplan_params
Definition: relation.h:532
static void build_joinrel_joinlist(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:739
AttrNumber min_attr
Definition: relation.h:521
static void build_join_rel_hash ( PlannerInfo root)
static

Definition at line 242 of file relnode.c.

References Assert, bitmap_hash(), bitmap_match(), CurrentMemoryContext, HASHCTL::entrysize, HASHCTL::hash, HASH_COMPARE, HASH_CONTEXT, hash_create(), HASH_ELEM, HASH_ENTER, HASH_FUNCTION, hash_search(), HASHCTL::hcxt, JoinHashEntry::join_rel, PlannerInfo::join_rel_hash, PlannerInfo::join_rel_list, HASHCTL::keysize, lfirst, HASHCTL::match, MemSet, and RelOptInfo::relids.

Referenced by find_join_rel().

243 {
244  HTAB *hashtab;
245  HASHCTL hash_ctl;
246  ListCell *l;
247 
248  /* Create the hash table */
249  MemSet(&hash_ctl, 0, sizeof(hash_ctl));
250  hash_ctl.keysize = sizeof(Relids);
251  hash_ctl.entrysize = sizeof(JoinHashEntry);
252  hash_ctl.hash = bitmap_hash;
253  hash_ctl.match = bitmap_match;
254  hash_ctl.hcxt = CurrentMemoryContext;
255  hashtab = hash_create("JoinRelHashTable",
256  256L,
257  &hash_ctl,
259 
260  /* Insert all the already-existing joinrels */
261  foreach(l, root->join_rel_list)
262  {
263  RelOptInfo *rel = (RelOptInfo *) lfirst(l);
264  JoinHashEntry *hentry;
265  bool found;
266 
267  hentry = (JoinHashEntry *) hash_search(hashtab,
268  &(rel->relids),
269  HASH_ENTER,
270  &found);
271  Assert(!found);
272  hentry->join_rel = rel;
273  }
274 
275  root->join_rel_hash = hashtab;
276 }
#define HASH_CONTEXT
Definition: hsearch.h:93
#define HASH_ELEM
Definition: hsearch.h:87
MemoryContext hcxt
Definition: hsearch.h:78
Size entrysize
Definition: hsearch.h:73
#define MemSet(start, val, len)
Definition: c.h:853
List * join_rel_list
Definition: relation.h:212
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:885
Definition: dynahash.c:193
struct JoinHashEntry JoinHashEntry
uint32 bitmap_hash(const void *key, Size keysize)
Definition: hashfn.c:76
RelOptInfo * join_rel
Definition: relnode.c:34
Relids relids
Definition: relation.h:490
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
int bitmap_match(const void *key1, const void *key2, Size keysize)
Definition: hashfn.c:86
Bitmapset * Relids
Definition: relation.h:28
HTAB * hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)
Definition: dynahash.c:301
Size keysize
Definition: hsearch.h:72
HashCompareFunc match
Definition: hsearch.h:75
#define Assert(condition)
Definition: c.h:671
#define lfirst(lc)
Definition: pg_list.h:106
#define HASH_COMPARE
Definition: hsearch.h:90
struct HTAB * join_rel_hash
Definition: relation.h:213
HashValueFunc hash
Definition: hsearch.h:74
#define HASH_FUNCTION
Definition: hsearch.h:89
static void build_joinrel_joinlist ( RelOptInfo joinrel,
RelOptInfo outer_rel,
RelOptInfo inner_rel 
)
static

Definition at line 739 of file relnode.c.

References RelOptInfo::joininfo, NIL, and subbuild_joinrel_joinlist().

Referenced by build_join_rel().

742 {
743  List *result;
744 
745  /*
746  * Collect all the clauses that syntactically belong above this level,
747  * eliminating any duplicates (important since we will see many of the
748  * same clauses arriving from both input relations).
749  */
750  result = subbuild_joinrel_joinlist(joinrel, outer_rel->joininfo, NIL);
751  result = subbuild_joinrel_joinlist(joinrel, inner_rel->joininfo, result);
752 
753  joinrel->joininfo = result;
754 }
#define NIL
Definition: pg_list.h:69
List * joininfo
Definition: relation.h:549
static List * subbuild_joinrel_joinlist(RelOptInfo *joinrel, List *joininfo_list, List *new_joininfo)
Definition: relnode.c:791
Definition: pg_list.h:45
static List * build_joinrel_restrictlist ( PlannerInfo root,
RelOptInfo joinrel,
RelOptInfo outer_rel,
RelOptInfo inner_rel 
)
static

Definition at line 709 of file relnode.c.

References generate_join_implied_equalities(), RelOptInfo::joininfo, list_concat(), NIL, RelOptInfo::relids, and subbuild_joinrel_restrictlist().

Referenced by build_join_rel().

713 {
714  List *result;
715 
716  /*
717  * Collect all the clauses that syntactically belong at this level,
718  * eliminating any duplicates (important since we will see many of the
719  * same clauses arriving from both input relations).
720  */
721  result = subbuild_joinrel_restrictlist(joinrel, outer_rel->joininfo, NIL);
722  result = subbuild_joinrel_restrictlist(joinrel, inner_rel->joininfo, result);
723 
724  /*
725  * Add on any clauses derived from EquivalenceClasses. These cannot be
726  * redundant with the clauses in the joininfo lists, so don't bother
727  * checking.
728  */
729  result = list_concat(result,
731  joinrel->relids,
732  outer_rel->relids,
733  inner_rel));
734 
735  return result;
736 }
#define NIL
Definition: pg_list.h:69
static List * subbuild_joinrel_restrictlist(RelOptInfo *joinrel, List *joininfo_list, List *new_restrictlist)
Definition: relnode.c:757
List * list_concat(List *list1, List *list2)
Definition: list.c:321
List * generate_join_implied_equalities(PlannerInfo *root, Relids join_relids, Relids outer_relids, RelOptInfo *inner_rel)
Definition: equivclass.c:1033
List * joininfo
Definition: relation.h:549
Relids relids
Definition: relation.h:490
Definition: pg_list.h:45
static void build_joinrel_tlist ( PlannerInfo root,
RelOptInfo joinrel,
RelOptInfo input_rel 
)
static

Definition at line 623 of file relnode.c.

References RelOptInfo::attr_needed, RelOptInfo::attr_widths, bms_nonempty_difference(), elog, ERROR, PathTarget::exprs, find_base_rel(), IsA, lappend(), lfirst, RelOptInfo::min_attr, nodeTag, RelOptInfo::relids, RelOptInfo::reltarget, Var::varattno, Var::varno, and PathTarget::width.

Referenced by build_join_rel().

625 {
626  Relids relids = joinrel->relids;
627  ListCell *vars;
628 
629  foreach(vars, input_rel->reltarget->exprs)
630  {
631  Var *var = (Var *) lfirst(vars);
632  RelOptInfo *baserel;
633  int ndx;
634 
635  /*
636  * Ignore PlaceHolderVars in the input tlists; we'll make our own
637  * decisions about whether to copy them.
638  */
639  if (IsA(var, PlaceHolderVar))
640  continue;
641 
642  /*
643  * Otherwise, anything in a baserel or joinrel targetlist ought to be
644  * a Var. (More general cases can only appear in appendrel child
645  * rels, which will never be seen here.)
646  */
647  if (!IsA(var, Var))
648  elog(ERROR, "unexpected node type in rel targetlist: %d",
649  (int) nodeTag(var));
650 
651  /* Get the Var's original base rel */
652  baserel = find_base_rel(root, var->varno);
653 
654  /* Is it still needed above this joinrel? */
655  ndx = var->varattno - baserel->min_attr;
656  if (bms_nonempty_difference(baserel->attr_needed[ndx], relids))
657  {
658  /* Yup, add it to the output */
659  joinrel->reltarget->exprs = lappend(joinrel->reltarget->exprs, var);
660  /* Vars have cost zero, so no need to adjust reltarget->cost */
661  joinrel->reltarget->width += baserel->attr_widths[ndx];
662  }
663  }
664 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:560
Relids * attr_needed
Definition: relation.h:523
AttrNumber varattno
Definition: primnodes.h:146
Definition: primnodes.h:141
#define ERROR
Definition: elog.h:43
Relids relids
Definition: relation.h:490
List * lappend(List *list, void *datum)
Definition: list.c:128
Index varno
Definition: primnodes.h:144
List * exprs
Definition: relation.h:824
#define lfirst(lc)
Definition: pg_list.h:106
#define nodeTag(nodeptr)
Definition: nodes.h:514
int width
Definition: relation.h:827
#define elog
Definition: elog.h:219
RelOptInfo * find_base_rel(PlannerInfo *root, int relid)
Definition: relnode.c:219
int32 * attr_widths
Definition: relation.h:524
Definition: regcomp.c:226
struct PathTarget * reltarget
Definition: relation.h:501
bool bms_nonempty_difference(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:464
AttrNumber min_attr
Definition: relation.h:521
RelOptInfo* build_simple_rel ( PlannerInfo root,
int  relid,
RelOptKind  reloptkind 
)

Definition at line 88 of file relnode.c.

References RelOptInfo::allvisfrac, PlannerInfo::append_rel_list, Assert, RelOptInfo::attr_needed, RelOptInfo::attr_widths, RelOptInfo::baserestrict_min_security, RelOptInfo::baserestrictcost, RelOptInfo::baserestrictinfo, bms_make_singleton(), build_simple_rel(), RelOptInfo::cheapest_parameterized_paths, RelOptInfo::cheapest_startup_path, RelOptInfo::cheapest_total_path, RelOptInfo::cheapest_unique_path, RangeTblEntry::checkAsUser, AppendRelInfo::child_relid, Alias::colnames, RelOptInfo::consider_parallel, RelOptInfo::consider_param_startup, RelOptInfo::consider_startup, create_empty_pathtarget(), RelOptInfo::direct_lateral_relids, elog, RangeTblEntry::eref, ERROR, RelOptInfo::fdw_private, RelOptInfo::fdwroutine, get_relation_info(), RelOptInfo::has_eclass_joins, RelOptInfo::indexlist, RangeTblEntry::inh, InvalidOid, RelOptInfo::joininfo, RelOptInfo::lateral_referencers, RelOptInfo::lateral_relids, RelOptInfo::lateral_vars, lfirst, list_length(), makeNode, Max, RelOptInfo::max_attr, RelOptInfo::min_attr, NIL, NULL, RelOptInfo::pages, palloc0(), AppendRelInfo::parent_relid, RelOptInfo::partial_pathlist, RelOptInfo::pathlist, QualCost::per_tuple, RelOptInfo::ppilist, PlannerInfo::qual_security_level, RelOptInfo::rel_parallel_workers, RelOptInfo::relid, RangeTblEntry::relid, RelOptInfo::relids, RELOPT_OTHER_MEMBER_REL, RelOptInfo::reloptkind, RelOptInfo::reltarget, RelOptInfo::rows, RTE_CTE, RTE_FUNCTION, RTE_RELATION, RTE_SUBQUERY, RTE_VALUES, RelOptInfo::rtekind, RangeTblEntry::rtekind, RangeTblEntry::securityQuals, RelOptInfo::serverid, PlannerInfo::simple_rel_array, PlannerInfo::simple_rte_array, QualCost::startup, RelOptInfo::subplan_params, RelOptInfo::subroot, PlannerInfo::tuple_fraction, RelOptInfo::tuples, RelOptInfo::userid, and RelOptInfo::useridiscurrent.

Referenced by add_base_rels_to_query(), build_simple_rel(), plan_cluster_use_sort(), and recurse_set_operations().

89 {
90  RelOptInfo *rel;
91  RangeTblEntry *rte;
92 
93  /* Rel should not exist already */
94  Assert(relid > 0 && relid < root->simple_rel_array_size);
95  if (root->simple_rel_array[relid] != NULL)
96  elog(ERROR, "rel %d already exists", relid);
97 
98  /* Fetch RTE for relation */
99  rte = root->simple_rte_array[relid];
100  Assert(rte != NULL);
101 
102  rel = makeNode(RelOptInfo);
103  rel->reloptkind = reloptkind;
104  rel->relids = bms_make_singleton(relid);
105  rel->rows = 0;
106  /* cheap startup cost is interesting iff not all tuples to be retrieved */
107  rel->consider_startup = (root->tuple_fraction > 0);
108  rel->consider_param_startup = false; /* might get changed later */
109  rel->consider_parallel = false; /* might get changed later */
111  rel->pathlist = NIL;
112  rel->ppilist = NIL;
113  rel->partial_pathlist = NIL;
115  rel->cheapest_total_path = NULL;
116  rel->cheapest_unique_path = NULL;
119  rel->lateral_relids = NULL;
120  rel->relid = relid;
121  rel->rtekind = rte->rtekind;
122  /* min_attr, max_attr, attr_needed, attr_widths are set below */
123  rel->lateral_vars = NIL;
124  rel->lateral_referencers = NULL;
125  rel->indexlist = NIL;
126  rel->pages = 0;
127  rel->tuples = 0;
128  rel->allvisfrac = 0;
129  rel->subroot = NULL;
130  rel->subplan_params = NIL;
131  rel->rel_parallel_workers = -1; /* set up in get_relation_info */
132  rel->serverid = InvalidOid;
133  rel->userid = rte->checkAsUser;
134  rel->useridiscurrent = false;
135  rel->fdwroutine = NULL;
136  rel->fdw_private = NULL;
137  rel->baserestrictinfo = NIL;
138  rel->baserestrictcost.startup = 0;
139  rel->baserestrictcost.per_tuple = 0;
140  rel->baserestrict_min_security = UINT_MAX;
141  rel->joininfo = NIL;
142  rel->has_eclass_joins = false;
143 
144  /* Check type of rtable entry */
145  switch (rte->rtekind)
146  {
147  case RTE_RELATION:
148  /* Table --- retrieve statistics from the system catalogs */
149  get_relation_info(root, rte->relid, rte->inh, rel);
150  break;
151  case RTE_SUBQUERY:
152  case RTE_FUNCTION:
153  case RTE_VALUES:
154  case RTE_CTE:
155 
156  /*
157  * Subquery, function, or values list --- set up attr range and
158  * arrays
159  *
160  * Note: 0 is included in range to support whole-row Vars
161  */
162  rel->min_attr = 0;
163  rel->max_attr = list_length(rte->eref->colnames);
164  rel->attr_needed = (Relids *)
165  palloc0((rel->max_attr - rel->min_attr + 1) * sizeof(Relids));
166  rel->attr_widths = (int32 *)
167  palloc0((rel->max_attr - rel->min_attr + 1) * sizeof(int32));
168  break;
169  default:
170  elog(ERROR, "unrecognized RTE kind: %d",
171  (int) rte->rtekind);
172  break;
173  }
174 
175  /* Save the finished struct in the query's simple_rel_array */
176  root->simple_rel_array[relid] = rel;
177 
178  /*
179  * This is a convenient spot at which to note whether rels participating
180  * in the query have any securityQuals attached. If so, increase
181  * root->qual_security_level to ensure it's larger than the maximum
182  * security level needed for securityQuals.
183  */
184  if (rte->securityQuals)
186  list_length(rte->securityQuals));
187 
188  /*
189  * If this rel is an appendrel parent, recurse to build "other rel"
190  * RelOptInfos for its children. They are "other rels" because they are
191  * not in the main join tree, but we will need RelOptInfos to plan access
192  * to them.
193  */
194  if (rte->inh)
195  {
196  ListCell *l;
197 
198  foreach(l, root->append_rel_list)
199  {
200  AppendRelInfo *appinfo = (AppendRelInfo *) lfirst(l);
201 
202  /* append_rel_list contains all append rels; ignore others */
203  if (appinfo->parent_relid != relid)
204  continue;
205 
206  (void) build_simple_rel(root, appinfo->child_relid,
208  }
209  }
210 
211  return rel;
212 }
bool has_eclass_joins
Definition: relation.h:551
struct Path * cheapest_unique_path
Definition: relation.h:509
PathTarget * create_empty_pathtarget(void)
Definition: tlist.c:653
#define NIL
Definition: pg_list.h:69
RelOptKind reloptkind
Definition: relation.h:487
Relids * attr_needed
Definition: relation.h:523
List * colnames
Definition: primnodes.h:42
struct Path * cheapest_startup_path
Definition: relation.h:507
Oid userid
Definition: relation.h:537
List * securityQuals
Definition: parsenodes.h:970
double tuples
Definition: relation.h:529
List * baserestrictinfo
Definition: relation.h:544
bool consider_param_startup
Definition: relation.h:497
List * partial_pathlist
Definition: relation.h:506
List * cheapest_parameterized_paths
Definition: relation.h:510
Index baserestrict_min_security
Definition: relation.h:547
bool useridiscurrent
Definition: relation.h:538
Cost startup
Definition: relation.h:45
double allvisfrac
Definition: relation.h:530
signed int int32
Definition: c.h:253
struct RelOptInfo ** simple_rel_array
Definition: relation.h:176
PlannerInfo * subroot
Definition: relation.h:531
bool consider_startup
Definition: relation.h:496
Relids lateral_relids
Definition: relation.h:515
Cost per_tuple
Definition: relation.h:46
double tuple_fraction
Definition: relation.h:286
#define ERROR
Definition: elog.h:43
struct Path * cheapest_total_path
Definition: relation.h:508
Bitmapset * bms_make_singleton(int x)
Definition: bitmapset.c:178
List * joininfo
Definition: relation.h:549
struct FdwRoutine * fdwroutine
Definition: relation.h:540
Relids relids
Definition: relation.h:490
List * ppilist
Definition: relation.h:505
Index relid
Definition: relation.h:518
Bitmapset * Relids
Definition: relation.h:28
RangeTblEntry ** simple_rte_array
Definition: relation.h:185
Relids lateral_referencers
Definition: relation.h:526
Oid serverid
Definition: relation.h:536
Relids direct_lateral_relids
Definition: relation.h:514
void * palloc0(Size size)
Definition: mcxt.c:920
int rel_parallel_workers
Definition: relation.h:533
List * append_rel_list
Definition: relation.h:249
RTEKind rtekind
Definition: relation.h:520
List * indexlist
Definition: relation.h:527
double rows
Definition: relation.h:493
#define InvalidOid
Definition: postgres_ext.h:36
RelOptInfo * build_simple_rel(PlannerInfo *root, int relid, RelOptKind reloptkind)
Definition: relnode.c:88
void * fdw_private
Definition: relation.h:541
#define Max(x, y)
Definition: c.h:796
#define makeNode(_type_)
Definition: nodes.h:557
BlockNumber pages
Definition: relation.h:528
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
#define lfirst(lc)
Definition: pg_list.h:106
List * lateral_vars
Definition: relation.h:525
static int list_length(const List *l)
Definition: pg_list.h:89
Index qual_security_level
Definition: relation.h:289
bool consider_parallel
Definition: relation.h:498
RTEKind rtekind
Definition: parsenodes.h:882
AttrNumber max_attr
Definition: relation.h:522
List * pathlist
Definition: relation.h:504
#define elog
Definition: elog.h:219
Index child_relid
Definition: relation.h:1866
Alias * eref
Definition: parsenodes.h:961
Index parent_relid
Definition: relation.h:1865
int32 * attr_widths
Definition: relation.h:524
struct PathTarget * reltarget
Definition: relation.h:501
QualCost baserestrictcost
Definition: relation.h:546
List * subplan_params
Definition: relation.h:532
void get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, RelOptInfo *rel)
Definition: plancat.c:96
AttrNumber min_attr
Definition: relation.h:521
RelOptInfo* fetch_upper_rel ( PlannerInfo root,
UpperRelationKind  kind,
Relids  relids 
)

Definition at line 870 of file relnode.c.

References bms_copy(), bms_equal(), RelOptInfo::cheapest_parameterized_paths, RelOptInfo::cheapest_startup_path, RelOptInfo::cheapest_total_path, RelOptInfo::cheapest_unique_path, RelOptInfo::consider_parallel, RelOptInfo::consider_param_startup, RelOptInfo::consider_startup, create_empty_pathtarget(), lappend(), lfirst, makeNode, NIL, NULL, RelOptInfo::pathlist, RelOptInfo::relids, RELOPT_UPPER_REL, RelOptInfo::reloptkind, RelOptInfo::reltarget, PlannerInfo::tuple_fraction, and PlannerInfo::upper_rels.

Referenced by add_rtes_to_flat_rtable(), create_distinct_paths(), create_grouping_paths(), create_ordered_paths(), create_window_paths(), generate_nonunion_path(), generate_recursion_path(), generate_union_path(), grouping_planner(), inheritance_planner(), make_subplan(), make_union_unique(), plan_set_operations(), preprocess_minmax_aggregates(), recurse_set_operations(), set_subquery_pathlist(), set_subquery_size_estimates(), SS_process_ctes(), standard_planner(), and subquery_planner().

871 {
872  RelOptInfo *upperrel;
873  ListCell *lc;
874 
875  /*
876  * For the moment, our indexing data structure is just a List for each
877  * relation kind. If we ever get so many of one kind that this stops
878  * working well, we can improve it. No code outside this function should
879  * assume anything about how to find a particular upperrel.
880  */
881 
882  /* If we already made this upperrel for the query, return it */
883  foreach(lc, root->upper_rels[kind])
884  {
885  upperrel = (RelOptInfo *) lfirst(lc);
886 
887  if (bms_equal(upperrel->relids, relids))
888  return upperrel;
889  }
890 
891  upperrel = makeNode(RelOptInfo);
892  upperrel->reloptkind = RELOPT_UPPER_REL;
893  upperrel->relids = bms_copy(relids);
894 
895  /* cheap startup cost is interesting iff not all tuples to be retrieved */
896  upperrel->consider_startup = (root->tuple_fraction > 0);
897  upperrel->consider_param_startup = false;
898  upperrel->consider_parallel = false; /* might get changed later */
899  upperrel->reltarget = create_empty_pathtarget();
900  upperrel->pathlist = NIL;
901  upperrel->cheapest_startup_path = NULL;
902  upperrel->cheapest_total_path = NULL;
903  upperrel->cheapest_unique_path = NULL;
904  upperrel->cheapest_parameterized_paths = NIL;
905 
906  root->upper_rels[kind] = lappend(root->upper_rels[kind], upperrel);
907 
908  return upperrel;
909 }
struct Path * cheapest_unique_path
Definition: relation.h:509
PathTarget * create_empty_pathtarget(void)
Definition: tlist.c:653
#define NIL
Definition: pg_list.h:69
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:110
RelOptKind reloptkind
Definition: relation.h:487
struct Path * cheapest_startup_path
Definition: relation.h:507
bool consider_param_startup
Definition: relation.h:497
List * cheapest_parameterized_paths
Definition: relation.h:510
bool consider_startup
Definition: relation.h:496
double tuple_fraction
Definition: relation.h:286
struct Path * cheapest_total_path
Definition: relation.h:508
Relids relids
Definition: relation.h:490
List * lappend(List *list, void *datum)
Definition: list.c:128
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:226
#define lfirst(lc)
Definition: pg_list.h:106
bool consider_parallel
Definition: relation.h:498
List * pathlist
Definition: relation.h:504
struct PathTarget * reltarget
Definition: relation.h:501
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:130
List * upper_rels[UPPERREL_FINAL+1]
Definition: relation.h:267
RelOptInfo* find_base_rel ( PlannerInfo root,
int  relid 
)

Definition at line 219 of file relnode.c.

References Assert, elog, ERROR, NULL, and PlannerInfo::simple_rel_array.

Referenced by add_join_clause_to_rels(), add_placeholders_to_base_rels(), add_vars_to_targetlist(), adjust_appendrel_attrs_multilevel(), build_joinrel_tlist(), clause_selectivity(), create_lateral_join_info(), distribute_restrictinfo_to_rels(), examine_simple_variable(), examine_variable(), finalize_plan(), find_childrel_parents(), find_childrel_top_parent(), find_join_input_rel(), get_foreign_key_join_selectivity(), join_is_removable(), make_rel_from_joinlist(), remove_join_clause_from_rels(), remove_rel_from_query(), set_append_rel_size(), set_base_rel_consider_startup(), set_subquery_size_estimates(), and set_subqueryscan_references().

220 {
221  RelOptInfo *rel;
222 
223  Assert(relid > 0);
224 
225  if (relid < root->simple_rel_array_size)
226  {
227  rel = root->simple_rel_array[relid];
228  if (rel)
229  return rel;
230  }
231 
232  elog(ERROR, "no relation entry for relid %d", relid);
233 
234  return NULL; /* keep compiler quiet */
235 }
struct RelOptInfo ** simple_rel_array
Definition: relation.h:176
#define ERROR
Definition: elog.h:43
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
#define elog
Definition: elog.h:219
AppendRelInfo* find_childrel_appendrelinfo ( PlannerInfo root,
RelOptInfo rel 
)

Definition at line 921 of file relnode.c.

References PlannerInfo::append_rel_list, Assert, AppendRelInfo::child_relid, elog, ERROR, lfirst, NULL, RelOptInfo::relid, RELOPT_OTHER_MEMBER_REL, and RelOptInfo::reloptkind.

Referenced by adjust_appendrel_attrs_multilevel(), find_childrel_parents(), and find_childrel_top_parent().

922 {
923  Index relid = rel->relid;
924  ListCell *lc;
925 
926  /* Should only be called on child rels */
928 
929  foreach(lc, root->append_rel_list)
930  {
931  AppendRelInfo *appinfo = (AppendRelInfo *) lfirst(lc);
932 
933  if (appinfo->child_relid == relid)
934  return appinfo;
935  }
936  /* should have found the entry ... */
937  elog(ERROR, "child rel %d not found in append_rel_list", relid);
938  return NULL; /* not reached */
939 }
RelOptKind reloptkind
Definition: relation.h:487
#define ERROR
Definition: elog.h:43
Index relid
Definition: relation.h:518
List * append_rel_list
Definition: relation.h:249
unsigned int Index
Definition: c.h:362
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
#define lfirst(lc)
Definition: pg_list.h:106
#define elog
Definition: elog.h:219
Index child_relid
Definition: relation.h:1866
Relids find_childrel_parents ( PlannerInfo root,
RelOptInfo rel 
)

Definition at line 977 of file relnode.c.

References Assert, bms_add_member(), find_base_rel(), find_childrel_appendrelinfo(), NULL, AppendRelInfo::parent_relid, RELOPT_BASEREL, RELOPT_OTHER_MEMBER_REL, and RelOptInfo::reloptkind.

Referenced by check_index_predicates(), and generate_implied_equalities_for_column().

978 {
979  Relids result = NULL;
980 
981  do
982  {
983  AppendRelInfo *appinfo = find_childrel_appendrelinfo(root, rel);
984  Index prelid = appinfo->parent_relid;
985 
986  result = bms_add_member(result, prelid);
987 
988  /* traverse up to the parent rel, loop if it's also a child rel */
989  rel = find_base_rel(root, prelid);
990  } while (rel->reloptkind == RELOPT_OTHER_MEMBER_REL);
991 
993 
994  return result;
995 }
RelOptKind reloptkind
Definition: relation.h:487
AppendRelInfo * find_childrel_appendrelinfo(PlannerInfo *root, RelOptInfo *rel)
Definition: relnode.c:921
unsigned int Index
Definition: c.h:362
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:668
RelOptInfo * find_base_rel(PlannerInfo *root, int relid)
Definition: relnode.c:219
Index parent_relid
Definition: relation.h:1865
RelOptInfo* find_childrel_top_parent ( PlannerInfo root,
RelOptInfo rel 
)

Definition at line 951 of file relnode.c.

References Assert, find_base_rel(), find_childrel_appendrelinfo(), AppendRelInfo::parent_relid, RELOPT_BASEREL, RELOPT_OTHER_MEMBER_REL, and RelOptInfo::reloptkind.

Referenced by eclass_useful_for_merging(), generate_join_implied_equalities_for_ecs(), and get_useful_ecs_for_relation().

952 {
953  do
954  {
955  AppendRelInfo *appinfo = find_childrel_appendrelinfo(root, rel);
956  Index prelid = appinfo->parent_relid;
957 
958  /* traverse up to the parent rel, loop if it's also a child rel */
959  rel = find_base_rel(root, prelid);
960  } while (rel->reloptkind == RELOPT_OTHER_MEMBER_REL);
961 
963 
964  return rel;
965 }
RelOptKind reloptkind
Definition: relation.h:487
AppendRelInfo * find_childrel_appendrelinfo(PlannerInfo *root, RelOptInfo *rel)
Definition: relnode.c:921
unsigned int Index
Definition: c.h:362
#define Assert(condition)
Definition: c.h:671
RelOptInfo * find_base_rel(PlannerInfo *root, int relid)
Definition: relnode.c:219
Index parent_relid
Definition: relation.h:1865
RelOptInfo* find_join_rel ( PlannerInfo root,
Relids  relids 
)

Definition at line 284 of file relnode.c.

References bms_equal(), build_join_rel_hash(), HASH_FIND, hash_search(), JoinHashEntry::join_rel, PlannerInfo::join_rel_hash, PlannerInfo::join_rel_list, lfirst, list_length(), NULL, and RelOptInfo::relids.

Referenced by build_join_rel(), examine_variable(), and find_join_input_rel().

285 {
286  /*
287  * Switch to using hash lookup when list grows "too long". The threshold
288  * is arbitrary and is known only here.
289  */
290  if (!root->join_rel_hash && list_length(root->join_rel_list) > 32)
291  build_join_rel_hash(root);
292 
293  /*
294  * Use either hashtable lookup or linear search, as appropriate.
295  *
296  * Note: the seemingly redundant hashkey variable is used to avoid taking
297  * the address of relids; unless the compiler is exceedingly smart, doing
298  * so would force relids out of a register and thus probably slow down the
299  * list-search case.
300  */
301  if (root->join_rel_hash)
302  {
303  Relids hashkey = relids;
304  JoinHashEntry *hentry;
305 
306  hentry = (JoinHashEntry *) hash_search(root->join_rel_hash,
307  &hashkey,
308  HASH_FIND,
309  NULL);
310  if (hentry)
311  return hentry->join_rel;
312  }
313  else
314  {
315  ListCell *l;
316 
317  foreach(l, root->join_rel_list)
318  {
319  RelOptInfo *rel = (RelOptInfo *) lfirst(l);
320 
321  if (bms_equal(rel->relids, relids))
322  return rel;
323  }
324  }
325 
326  return NULL;
327 }
List * join_rel_list
Definition: relation.h:212
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:885
RelOptInfo * join_rel
Definition: relnode.c:34
Relids relids
Definition: relation.h:490
static void build_join_rel_hash(PlannerInfo *root)
Definition: relnode.c:242
#define NULL
Definition: c.h:226
#define lfirst(lc)
Definition: pg_list.h:106
static int list_length(const List *l)
Definition: pg_list.h:89
struct HTAB * join_rel_hash
Definition: relation.h:213
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:130
ParamPathInfo* get_appendrel_parampathinfo ( RelOptInfo appendrel,
Relids  required_outer 
)

Definition at line 1309 of file relnode.c.

References Assert, bms_equal(), bms_is_empty(), bms_overlap(), lappend(), lfirst, makeNode, NIL, NULL, ParamPathInfo::ppi_clauses, ParamPathInfo::ppi_req_outer, ParamPathInfo::ppi_rows, RelOptInfo::ppilist, and RelOptInfo::relids.

Referenced by create_append_path(), and create_merge_append_path().

1310 {
1311  ParamPathInfo *ppi;
1312  ListCell *lc;
1313 
1314  /* Unparameterized paths have no ParamPathInfo */
1315  if (bms_is_empty(required_outer))
1316  return NULL;
1317 
1318  Assert(!bms_overlap(appendrel->relids, required_outer));
1319 
1320  /* If we already have a PPI for this parameterization, just return it */
1321  foreach(lc, appendrel->ppilist)
1322  {
1323  ppi = (ParamPathInfo *) lfirst(lc);
1324  if (bms_equal(ppi->ppi_req_outer, required_outer))
1325  return ppi;
1326  }
1327 
1328  /* Else build the ParamPathInfo */
1329  ppi = makeNode(ParamPathInfo);
1330  ppi->ppi_req_outer = required_outer;
1331  ppi->ppi_rows = 0;
1332  ppi->ppi_clauses = NIL;
1333  appendrel->ppilist = lappend(appendrel->ppilist, ppi);
1334 
1335  return ppi;
1336 }
#define NIL
Definition: pg_list.h:69
Relids relids
Definition: relation.h:490
List * ppilist
Definition: relation.h:505
List * lappend(List *list, void *datum)
Definition: list.c:128
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:633
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
#define lfirst(lc)
Definition: pg_list.h:106
List * ppi_clauses
Definition: relation.h:855
double ppi_rows
Definition: relation.h:854
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:442
Relids ppi_req_outer
Definition: relation.h:853
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:130
ParamPathInfo* get_baserel_parampathinfo ( PlannerInfo root,
RelOptInfo baserel,
Relids  required_outer 
)

Definition at line 1010 of file relnode.c.

References Assert, bms_equal(), bms_is_empty(), bms_overlap(), bms_union(), generate_join_implied_equalities(), get_parameterized_baserel_size(), join_clause_is_movable_into(), RelOptInfo::joininfo, lappend(), lfirst, list_concat(), makeNode, NIL, NULL, ParamPathInfo::ppi_clauses, ParamPathInfo::ppi_req_outer, ParamPathInfo::ppi_rows, RelOptInfo::ppilist, and RelOptInfo::relids.

Referenced by bitmap_and_cost_est(), bitmap_scan_cost_est(), create_bitmap_heap_path(), create_ctescan_path(), create_foreignscan_path(), create_functionscan_path(), create_gather_path(), create_index_path(), create_samplescan_path(), create_seqscan_path(), create_subqueryscan_path(), create_tidscan_path(), create_valuesscan_path(), create_worktablescan_path(), postgresGetForeignPaths(), and reparameterize_path().

1012 {
1013  ParamPathInfo *ppi;
1014  Relids joinrelids;
1015  List *pclauses;
1016  double rows;
1017  ListCell *lc;
1018 
1019  /* Unparameterized paths have no ParamPathInfo */
1020  if (bms_is_empty(required_outer))
1021  return NULL;
1022 
1023  Assert(!bms_overlap(baserel->relids, required_outer));
1024 
1025  /* If we already have a PPI for this parameterization, just return it */
1026  foreach(lc, baserel->ppilist)
1027  {
1028  ppi = (ParamPathInfo *) lfirst(lc);
1029  if (bms_equal(ppi->ppi_req_outer, required_outer))
1030  return ppi;
1031  }
1032 
1033  /*
1034  * Identify all joinclauses that are movable to this base rel given this
1035  * parameterization.
1036  */
1037  joinrelids = bms_union(baserel->relids, required_outer);
1038  pclauses = NIL;
1039  foreach(lc, baserel->joininfo)
1040  {
1041  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
1042 
1043  if (join_clause_is_movable_into(rinfo,
1044  baserel->relids,
1045  joinrelids))
1046  pclauses = lappend(pclauses, rinfo);
1047  }
1048 
1049  /*
1050  * Add in joinclauses generated by EquivalenceClasses, too. (These
1051  * necessarily satisfy join_clause_is_movable_into.)
1052  */
1053  pclauses = list_concat(pclauses,
1055  joinrelids,
1056  required_outer,
1057  baserel));
1058 
1059  /* Estimate the number of rows returned by the parameterized scan */
1060  rows = get_parameterized_baserel_size(root, baserel, pclauses);
1061 
1062  /* And now we can build the ParamPathInfo */
1063  ppi = makeNode(ParamPathInfo);
1064  ppi->ppi_req_outer = required_outer;
1065  ppi->ppi_rows = rows;
1066  ppi->ppi_clauses = pclauses;
1067  baserel->ppilist = lappend(baserel->ppilist, ppi);
1068 
1069  return ppi;
1070 }
#define NIL
Definition: pg_list.h:69
List * list_concat(List *list1, List *list2)
Definition: list.c:321
List * generate_join_implied_equalities(PlannerInfo *root, Relids join_relids, Relids outer_relids, RelOptInfo *inner_rel)
Definition: equivclass.c:1033
List * joininfo
Definition: relation.h:549
Relids relids
Definition: relation.h:490
bool join_clause_is_movable_into(RestrictInfo *rinfo, Relids currentrelids, Relids current_and_outer)
Definition: restrictinfo.c:508
List * ppilist
Definition: relation.h:505
List * lappend(List *list, void *datum)
Definition: list.c:128
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:633
double get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel, List *param_clauses)
Definition: costsize.c:3795
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
#define lfirst(lc)
Definition: pg_list.h:106
List * ppi_clauses
Definition: relation.h:855
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:217
double ppi_rows
Definition: relation.h:854
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:442
Relids ppi_req_outer
Definition: relation.h:853
Definition: pg_list.h:45
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:130
ParamPathInfo* get_joinrel_parampathinfo ( PlannerInfo root,
RelOptInfo joinrel,
Path outer_path,
Path inner_path,
SpecialJoinInfo sjinfo,
Relids  required_outer,
List **  restrict_clauses 
)

Definition at line 1101 of file relnode.c.

References Assert, bms_equal(), bms_is_empty(), bms_overlap(), bms_union(), generate_join_implied_equalities(), generate_join_implied_equalities_for_ecs(), get_parameterized_joinrel_size(), join_clause_is_movable_into(), RelOptInfo::joininfo, lappend(), RestrictInfo::left_ec, lfirst, list_concat(), makeNode, NIL, NULL, Path::param_info, Path::parent, PATH_REQ_OUTER, ParamPathInfo::ppi_clauses, ParamPathInfo::ppi_req_outer, ParamPathInfo::ppi_rows, RelOptInfo::ppilist, RelOptInfo::relids, and RestrictInfo::right_ec.

Referenced by create_hashjoin_path(), create_mergejoin_path(), and create_nestloop_path().

1107 {
1108  ParamPathInfo *ppi;
1109  Relids join_and_req;
1110  Relids outer_and_req;
1111  Relids inner_and_req;
1112  List *pclauses;
1113  List *eclauses;
1114  List *dropped_ecs;
1115  double rows;
1116  ListCell *lc;
1117 
1118  /* Unparameterized paths have no ParamPathInfo or extra join clauses */
1119  if (bms_is_empty(required_outer))
1120  return NULL;
1121 
1122  Assert(!bms_overlap(joinrel->relids, required_outer));
1123 
1124  /*
1125  * Identify all joinclauses that are movable to this join rel given this
1126  * parameterization. These are the clauses that are movable into this
1127  * join, but not movable into either input path. Treat an unparameterized
1128  * input path as not accepting parameterized clauses (because it won't,
1129  * per the shortcut exit above), even though the joinclause movement rules
1130  * might allow the same clauses to be moved into a parameterized path for
1131  * that rel.
1132  */
1133  join_and_req = bms_union(joinrel->relids, required_outer);
1134  if (outer_path->param_info)
1135  outer_and_req = bms_union(outer_path->parent->relids,
1136  PATH_REQ_OUTER(outer_path));
1137  else
1138  outer_and_req = NULL; /* outer path does not accept parameters */
1139  if (inner_path->param_info)
1140  inner_and_req = bms_union(inner_path->parent->relids,
1141  PATH_REQ_OUTER(inner_path));
1142  else
1143  inner_and_req = NULL; /* inner path does not accept parameters */
1144 
1145  pclauses = NIL;
1146  foreach(lc, joinrel->joininfo)
1147  {
1148  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
1149 
1150  if (join_clause_is_movable_into(rinfo,
1151  joinrel->relids,
1152  join_and_req) &&
1154  outer_path->parent->relids,
1155  outer_and_req) &&
1157  inner_path->parent->relids,
1158  inner_and_req))
1159  pclauses = lappend(pclauses, rinfo);
1160  }
1161 
1162  /* Consider joinclauses generated by EquivalenceClasses, too */
1163  eclauses = generate_join_implied_equalities(root,
1164  join_and_req,
1165  required_outer,
1166  joinrel);
1167  /* We only want ones that aren't movable to lower levels */
1168  dropped_ecs = NIL;
1169  foreach(lc, eclauses)
1170  {
1171  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
1172 
1173  /*
1174  * In principle, join_clause_is_movable_into() should accept anything
1175  * returned by generate_join_implied_equalities(); but because its
1176  * analysis is only approximate, sometimes it doesn't. So we
1177  * currently cannot use this Assert; instead just assume it's okay to
1178  * apply the joinclause at this level.
1179  */
1180 #ifdef NOT_USED
1182  joinrel->relids,
1183  join_and_req));
1184 #endif
1185  if (join_clause_is_movable_into(rinfo,
1186  outer_path->parent->relids,
1187  outer_and_req))
1188  continue; /* drop if movable into LHS */
1189  if (join_clause_is_movable_into(rinfo,
1190  inner_path->parent->relids,
1191  inner_and_req))
1192  {
1193  /* drop if movable into RHS, but remember EC for use below */
1194  Assert(rinfo->left_ec == rinfo->right_ec);
1195  dropped_ecs = lappend(dropped_ecs, rinfo->left_ec);
1196  continue;
1197  }
1198  pclauses = lappend(pclauses, rinfo);
1199  }
1200 
1201  /*
1202  * EquivalenceClasses are harder to deal with than we could wish, because
1203  * of the fact that a given EC can generate different clauses depending on
1204  * context. Suppose we have an EC {X.X, Y.Y, Z.Z} where X and Y are the
1205  * LHS and RHS of the current join and Z is in required_outer, and further
1206  * suppose that the inner_path is parameterized by both X and Z. The code
1207  * above will have produced either Z.Z = X.X or Z.Z = Y.Y from that EC,
1208  * and in the latter case will have discarded it as being movable into the
1209  * RHS. However, the EC machinery might have produced either Y.Y = X.X or
1210  * Y.Y = Z.Z as the EC enforcement clause within the inner_path; it will
1211  * not have produced both, and we can't readily tell from here which one
1212  * it did pick. If we add no clause to this join, we'll end up with
1213  * insufficient enforcement of the EC; either Z.Z or X.X will fail to be
1214  * constrained to be equal to the other members of the EC. (When we come
1215  * to join Z to this X/Y path, we will certainly drop whichever EC clause
1216  * is generated at that join, so this omission won't get fixed later.)
1217  *
1218  * To handle this, for each EC we discarded such a clause from, try to
1219  * generate a clause connecting the required_outer rels to the join's LHS
1220  * ("Z.Z = X.X" in the terms of the above example). If successful, and if
1221  * the clause can't be moved to the LHS, add it to the current join's
1222  * restriction clauses. (If an EC cannot generate such a clause then it
1223  * has nothing that needs to be enforced here, while if the clause can be
1224  * moved into the LHS then it should have been enforced within that path.)
1225  *
1226  * Note that we don't need similar processing for ECs whose clause was
1227  * considered to be movable into the LHS, because the LHS can't refer to
1228  * the RHS so there is no comparable ambiguity about what it might
1229  * actually be enforcing internally.
1230  */
1231  if (dropped_ecs)
1232  {
1233  Relids real_outer_and_req;
1234 
1235  real_outer_and_req = bms_union(outer_path->parent->relids,
1236  required_outer);
1237  eclauses =
1239  dropped_ecs,
1240  real_outer_and_req,
1241  required_outer,
1242  outer_path->parent);
1243  foreach(lc, eclauses)
1244  {
1245  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
1246 
1247  /* As above, can't quite assert this here */
1248 #ifdef NOT_USED
1250  outer_path->parent->relids,
1251  real_outer_and_req));
1252 #endif
1253  if (!join_clause_is_movable_into(rinfo,
1254  outer_path->parent->relids,
1255  outer_and_req))
1256  pclauses = lappend(pclauses, rinfo);
1257  }
1258  }
1259 
1260  /*
1261  * Now, attach the identified moved-down clauses to the caller's
1262  * restrict_clauses list. By using list_concat in this order, we leave
1263  * the original list structure of restrict_clauses undamaged.
1264  */
1265  *restrict_clauses = list_concat(pclauses, *restrict_clauses);
1266 
1267  /* If we already have a PPI for this parameterization, just return it */
1268  foreach(lc, joinrel->ppilist)
1269  {
1270  ppi = (ParamPathInfo *) lfirst(lc);
1271  if (bms_equal(ppi->ppi_req_outer, required_outer))
1272  return ppi;
1273  }
1274 
1275  /* Estimate the number of rows returned by the parameterized join */
1276  rows = get_parameterized_joinrel_size(root, joinrel,
1277  outer_path,
1278  inner_path,
1279  sjinfo,
1280  *restrict_clauses);
1281 
1282  /*
1283  * And now we can build the ParamPathInfo. No point in saving the
1284  * input-pair-dependent clause list, though.
1285  *
1286  * Note: in GEQO mode, we'll be called in a temporary memory context, but
1287  * the joinrel structure is there too, so no problem.
1288  */
1289  ppi = makeNode(ParamPathInfo);
1290  ppi->ppi_req_outer = required_outer;
1291  ppi->ppi_rows = rows;
1292  ppi->ppi_clauses = NIL;
1293  joinrel->ppilist = lappend(joinrel->ppilist, ppi);
1294 
1295  return ppi;
1296 }
#define NIL
Definition: pg_list.h:69
ParamPathInfo * param_info
Definition: relation.h:897
List * list_concat(List *list1, List *list2)
Definition: list.c:321
EquivalenceClass * right_ec
Definition: relation.h:1686
List * generate_join_implied_equalities(PlannerInfo *root, Relids join_relids, Relids outer_relids, RelOptInfo *inner_rel)
Definition: equivclass.c:1033
RelOptInfo * parent
Definition: relation.h:894
double get_parameterized_joinrel_size(PlannerInfo *root, RelOptInfo *rel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, List *restrict_clauses)
Definition: costsize.c:3876
List * joininfo
Definition: relation.h:549
Relids relids
Definition: relation.h:490
bool join_clause_is_movable_into(RestrictInfo *rinfo, Relids currentrelids, Relids current_and_outer)
Definition: restrictinfo.c:508
List * ppilist
Definition: relation.h:505
List * lappend(List *list, void *datum)
Definition: list.c:128
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:633
List * generate_join_implied_equalities_for_ecs(PlannerInfo *root, List *eclasses, Relids join_relids, Relids outer_relids, RelOptInfo *inner_rel)
Definition: equivclass.c:1050
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
#define lfirst(lc)
Definition: pg_list.h:106
#define PATH_REQ_OUTER(path)
Definition: relation.h:914
List * ppi_clauses
Definition: relation.h:855
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:217
double ppi_rows
Definition: relation.h:854
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:442
EquivalenceClass * left_ec
Definition: relation.h:1685
Relids ppi_req_outer
Definition: relation.h:853
Definition: pg_list.h:45
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:130
Relids min_join_parameterization ( PlannerInfo root,
Relids  joinrelids,
RelOptInfo outer_rel,
RelOptInfo inner_rel 
)

Definition at line 580 of file relnode.c.

References bms_del_members(), bms_is_empty(), bms_union(), RelOptInfo::lateral_relids, and NULL.

Referenced by build_join_rel(), and join_is_legal().

584 {
585  Relids result;
586 
587  /*
588  * Basically we just need the union of the inputs' lateral_relids, less
589  * whatever is already in the join.
590  *
591  * It's not immediately obvious that this is a valid way to compute the
592  * result, because it might seem that we're ignoring possible lateral refs
593  * of PlaceHolderVars that are due to be computed at the join but not in
594  * either input. However, because create_lateral_join_info() already
595  * charged all such PHV refs to each member baserel of the join, they'll
596  * be accounted for already in the inputs' lateral_relids. Likewise, we
597  * do not need to worry about doing transitive closure here, because that
598  * was already accounted for in the original baserel lateral_relids.
599  */
600  result = bms_union(outer_rel->lateral_relids, inner_rel->lateral_relids);
601  result = bms_del_members(result, joinrelids);
602 
603  /* Maintain invariant that result is exactly NULL if empty */
604  if (bms_is_empty(result))
605  result = NULL;
606 
607  return result;
608 }
Relids lateral_relids
Definition: relation.h:515
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:633
#define NULL
Definition: c.h:226
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:217
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:787
void setup_simple_rel_arrays ( PlannerInfo root)

Definition at line 59 of file relnode.c.

References lfirst, list_length(), palloc0(), PlannerInfo::parse, Query::rtable, PlannerInfo::simple_rel_array, PlannerInfo::simple_rel_array_size, and PlannerInfo::simple_rte_array.

Referenced by plan_cluster_use_sort(), plan_set_operations(), and query_planner().

60 {
61  Index rti;
62  ListCell *lc;
63 
64  /* Arrays are accessed using RT indexes (1..N) */
65  root->simple_rel_array_size = list_length(root->parse->rtable) + 1;
66 
67  /* simple_rel_array is initialized to all NULLs */
68  root->simple_rel_array = (RelOptInfo **)
69  palloc0(root->simple_rel_array_size * sizeof(RelOptInfo *));
70 
71  /* simple_rte_array is an array equivalent of the rtable list */
72  root->simple_rte_array = (RangeTblEntry **)
73  palloc0(root->simple_rel_array_size * sizeof(RangeTblEntry *));
74  rti = 1;
75  foreach(lc, root->parse->rtable)
76  {
77  RangeTblEntry *rte = (RangeTblEntry *) lfirst(lc);
78 
79  root->simple_rte_array[rti++] = rte;
80  }
81 }
Query * parse
Definition: relation.h:152
struct RelOptInfo ** simple_rel_array
Definition: relation.h:176
List * rtable
Definition: parsenodes.h:128
int simple_rel_array_size
Definition: relation.h:177
RangeTblEntry ** simple_rte_array
Definition: relation.h:185
void * palloc0(Size size)
Definition: mcxt.c:920
unsigned int Index
Definition: c.h:362
#define lfirst(lc)
Definition: pg_list.h:106
static int list_length(const List *l)
Definition: pg_list.h:89
static List * subbuild_joinrel_joinlist ( RelOptInfo joinrel,
List joininfo_list,
List new_joininfo 
)
static

Definition at line 791 of file relnode.c.

References bms_is_subset(), lfirst, list_append_unique_ptr(), RelOptInfo::relids, and RestrictInfo::required_relids.

Referenced by build_joinrel_joinlist().

794 {
795  ListCell *l;
796 
797  foreach(l, joininfo_list)
798  {
799  RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
800 
801  if (bms_is_subset(rinfo->required_relids, joinrel->relids))
802  {
803  /*
804  * This clause becomes a restriction clause for the joinrel, since
805  * it refers to no outside rels. So we can ignore it in this
806  * routine.
807  */
808  }
809  else
810  {
811  /*
812  * This clause is still a join clause at this level, so add it to
813  * the new joininfo list, being careful to eliminate duplicates.
814  * (Since RestrictInfo nodes in different joinlists will have been
815  * multiply-linked rather than copied, pointer equality should be
816  * a sufficient test.)
817  */
818  new_joininfo = list_append_unique_ptr(new_joininfo, rinfo);
819  }
820  }
821 
822  return new_joininfo;
823 }
Relids required_relids
Definition: relation.h:1655
List * list_append_unique_ptr(List *list, void *datum)
Definition: list.c:975
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:307
Relids relids
Definition: relation.h:490
#define lfirst(lc)
Definition: pg_list.h:106
static List * subbuild_joinrel_restrictlist ( RelOptInfo joinrel,
List joininfo_list,
List new_restrictlist 
)
static

Definition at line 757 of file relnode.c.

References bms_is_subset(), lfirst, list_append_unique_ptr(), RelOptInfo::relids, and RestrictInfo::required_relids.

Referenced by build_joinrel_restrictlist().

760 {
761  ListCell *l;
762 
763  foreach(l, joininfo_list)
764  {
765  RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
766 
767  if (bms_is_subset(rinfo->required_relids, joinrel->relids))
768  {
769  /*
770  * This clause becomes a restriction clause for the joinrel, since
771  * it refers to no outside rels. Add it to the list, being
772  * careful to eliminate duplicates. (Since RestrictInfo nodes in
773  * different joinlists will have been multiply-linked rather than
774  * copied, pointer equality should be a sufficient test.)
775  */
776  new_restrictlist = list_append_unique_ptr(new_restrictlist, rinfo);
777  }
778  else
779  {
780  /*
781  * This clause is still a join clause at this level, so we ignore
782  * it in this routine.
783  */
784  }
785  }
786 
787  return new_restrictlist;
788 }
Relids required_relids
Definition: relation.h:1655
List * list_append_unique_ptr(List *list, void *datum)
Definition: list.c:975
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:307
Relids relids
Definition: relation.h:490
#define lfirst(lc)
Definition: pg_list.h:106