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)
 
static void set_foreign_rel_properties (RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
 
static void add_join_rel (PlannerInfo *root, RelOptInfo *joinrel)
 
void setup_simple_rel_arrays (PlannerInfo *root)
 
RelOptInfobuild_simple_rel (PlannerInfo *root, int relid, RelOptInfo *parent)
 
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)
 
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

static void add_join_rel ( PlannerInfo root,
RelOptInfo joinrel 
)
static

Definition at line 409 of file relnode.c.

References Assert, HASH_ENTER, hash_search(), JoinHashEntry::join_rel, PlannerInfo::join_rel_hash, PlannerInfo::join_rel_list, lappend(), and RelOptInfo::relids.

Referenced by build_join_rel().

410 {
411  /* GEQO requires us to append the new joinrel to the end of the list! */
412  root->join_rel_list = lappend(root->join_rel_list, joinrel);
413 
414  /* store it into the auxiliary hashtable if there is one. */
415  if (root->join_rel_hash)
416  {
417  JoinHashEntry *hentry;
418  bool found;
419 
420  hentry = (JoinHashEntry *) hash_search(root->join_rel_hash,
421  &(joinrel->relids),
422  HASH_ENTER,
423  &found);
424  Assert(!found);
425  hentry->join_rel = joinrel;
426  }
427 }
List * join_rel_list
Definition: relation.h:215
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:525
List * lappend(List *list, void *datum)
Definition: list.c:128
#define Assert(condition)
Definition: c.h:675
struct HTAB * join_rel_hash
Definition: relation.h:216
RelOptInfo* build_empty_join_rel ( PlannerInfo root)

Definition at line 885 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().

886 {
887  RelOptInfo *joinrel;
888 
889  /* The dummy join relation should be the only one ... */
890  Assert(root->join_rel_list == NIL);
891 
892  joinrel = makeNode(RelOptInfo);
893  joinrel->reloptkind = RELOPT_JOINREL;
894  joinrel->relids = NULL; /* empty set */
895  joinrel->rows = 1; /* we produce one row for such cases */
896  joinrel->rtekind = RTE_JOIN;
897  joinrel->reltarget = create_empty_pathtarget();
898 
899  root->join_rel_list = lappend(root->join_rel_list, joinrel);
900 
901  return joinrel;
902 }
PathTarget * create_empty_pathtarget(void)
Definition: tlist.c:653
#define NIL
Definition: pg_list.h:69
RelOptKind reloptkind
Definition: relation.h:522
List * join_rel_list
Definition: relation.h:215
Relids relids
Definition: relation.h:525
List * lappend(List *list, void *datum)
Definition: list.c:128
RTEKind rtekind
Definition: relation.h:555
double rows
Definition: relation.h:528
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
struct PathTarget * reltarget
Definition: relation.h:536
RelOptInfo* build_join_rel ( PlannerInfo root,
Relids  joinrelids,
RelOptInfo outer_rel,
RelOptInfo inner_rel,
SpecialJoinInfo sjinfo,
List **  restrictlist_ptr 
)

Definition at line 446 of file relnode.c.

References add_join_rel(), 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(), RelOptInfo::has_eclass_joins, has_relevant_eclass_joinclause(), RelOptInfo::indexlist, InvalidOid, is_parallel_safe(), PlannerInfo::join_cur_level, PlannerInfo::join_rel_level, RelOptInfo::joininfo, lappend(), RelOptInfo::lateral_referencers, RelOptInfo::lateral_relids, RelOptInfo::lateral_vars, makeNode, RelOptInfo::max_attr, RelOptInfo::min_attr, min_join_parameterization(), NIL, RelOptInfo::non_unique_for_rels, NULL, 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_foreign_rel_properties(), set_joinrel_size_estimates(), QualCost::startup, RelOptInfo::statlist, RelOptInfo::subplan_params, RelOptInfo::subroot, RelOptInfo::top_parent_relids, PlannerInfo::tuple_fraction, RelOptInfo::tuples, RelOptInfo::unique_for_rels, RelOptInfo::userid, and RelOptInfo::useridiscurrent.

Referenced by make_join_rel().

452 {
453  RelOptInfo *joinrel;
454  List *restrictlist;
455 
456  /*
457  * See if we already have a joinrel for this set of base rels.
458  */
459  joinrel = find_join_rel(root, joinrelids);
460 
461  if (joinrel)
462  {
463  /*
464  * Yes, so we only need to figure the restrictlist for this particular
465  * pair of component relations.
466  */
467  if (restrictlist_ptr)
468  *restrictlist_ptr = build_joinrel_restrictlist(root,
469  joinrel,
470  outer_rel,
471  inner_rel);
472  return joinrel;
473  }
474 
475  /*
476  * Nope, so make one.
477  */
478  joinrel = makeNode(RelOptInfo);
479  joinrel->reloptkind = RELOPT_JOINREL;
480  joinrel->relids = bms_copy(joinrelids);
481  joinrel->rows = 0;
482  /* cheap startup cost is interesting iff not all tuples to be retrieved */
483  joinrel->consider_startup = (root->tuple_fraction > 0);
484  joinrel->consider_param_startup = false;
485  joinrel->consider_parallel = false;
486  joinrel->reltarget = create_empty_pathtarget();
487  joinrel->pathlist = NIL;
488  joinrel->ppilist = NIL;
489  joinrel->partial_pathlist = NIL;
490  joinrel->cheapest_startup_path = NULL;
491  joinrel->cheapest_total_path = NULL;
492  joinrel->cheapest_unique_path = NULL;
494  /* init direct_lateral_relids from children; we'll finish it up below */
495  joinrel->direct_lateral_relids =
496  bms_union(outer_rel->direct_lateral_relids,
497  inner_rel->direct_lateral_relids);
498  joinrel->lateral_relids = min_join_parameterization(root, joinrel->relids,
499  outer_rel, inner_rel);
500  joinrel->relid = 0; /* indicates not a baserel */
501  joinrel->rtekind = RTE_JOIN;
502  joinrel->min_attr = 0;
503  joinrel->max_attr = 0;
504  joinrel->attr_needed = NULL;
505  joinrel->attr_widths = NULL;
506  joinrel->lateral_vars = NIL;
507  joinrel->lateral_referencers = NULL;
508  joinrel->indexlist = NIL;
509  joinrel->statlist = NIL;
510  joinrel->pages = 0;
511  joinrel->tuples = 0;
512  joinrel->allvisfrac = 0;
513  joinrel->subroot = NULL;
514  joinrel->subplan_params = NIL;
515  joinrel->rel_parallel_workers = -1;
516  joinrel->serverid = InvalidOid;
517  joinrel->userid = InvalidOid;
518  joinrel->useridiscurrent = false;
519  joinrel->fdwroutine = NULL;
520  joinrel->fdw_private = NULL;
521  joinrel->unique_for_rels = NIL;
522  joinrel->non_unique_for_rels = NIL;
523  joinrel->baserestrictinfo = NIL;
524  joinrel->baserestrictcost.startup = 0;
525  joinrel->baserestrictcost.per_tuple = 0;
526  joinrel->baserestrict_min_security = UINT_MAX;
527  joinrel->joininfo = NIL;
528  joinrel->has_eclass_joins = false;
529  joinrel->top_parent_relids = NULL;
530 
531  /* Compute information relevant to the foreign relations. */
532  set_foreign_rel_properties(joinrel, outer_rel, inner_rel);
533 
534  /*
535  * Create a new tlist containing just the vars that need to be output from
536  * this join (ie, are needed for higher joinclauses or final output).
537  *
538  * NOTE: the tlist order for a join rel will depend on which pair of outer
539  * and inner rels we first try to build it from. But the contents should
540  * be the same regardless.
541  */
542  build_joinrel_tlist(root, joinrel, outer_rel);
543  build_joinrel_tlist(root, joinrel, inner_rel);
544  add_placeholders_to_joinrel(root, joinrel, outer_rel, inner_rel);
545 
546  /*
547  * add_placeholders_to_joinrel also took care of adding the ph_lateral
548  * sets of any PlaceHolderVars computed here to direct_lateral_relids, so
549  * now we can finish computing that. This is much like the computation of
550  * the transitively-closed lateral_relids in min_join_parameterization,
551  * except that here we *do* have to consider the added PHVs.
552  */
553  joinrel->direct_lateral_relids =
554  bms_del_members(joinrel->direct_lateral_relids, joinrel->relids);
555  if (bms_is_empty(joinrel->direct_lateral_relids))
556  joinrel->direct_lateral_relids = NULL;
557 
558  /*
559  * Construct restrict and join clause lists for the new joinrel. (The
560  * caller might or might not need the restrictlist, but I need it anyway
561  * for set_joinrel_size_estimates().)
562  */
563  restrictlist = build_joinrel_restrictlist(root, joinrel,
564  outer_rel, inner_rel);
565  if (restrictlist_ptr)
566  *restrictlist_ptr = restrictlist;
567  build_joinrel_joinlist(joinrel, outer_rel, inner_rel);
568 
569  /*
570  * This is also the right place to check whether the joinrel has any
571  * pending EquivalenceClass joins.
572  */
573  joinrel->has_eclass_joins = has_relevant_eclass_joinclause(root, joinrel);
574 
575  /*
576  * Set estimates of the joinrel's size.
577  */
578  set_joinrel_size_estimates(root, joinrel, outer_rel, inner_rel,
579  sjinfo, restrictlist);
580 
581  /*
582  * Set the consider_parallel flag if this joinrel could potentially be
583  * scanned within a parallel worker. If this flag is false for either
584  * inner_rel or outer_rel, then it must be false for the joinrel also.
585  * Even if both are true, there might be parallel-restricted expressions
586  * in the targetlist or quals.
587  *
588  * Note that if there are more than two rels in this relation, they could
589  * be divided between inner_rel and outer_rel in any arbitrary way. We
590  * assume this doesn't matter, because we should hit all the same baserels
591  * and joinclauses while building up to this joinrel no matter which we
592  * take; therefore, we should make the same decision here however we get
593  * here.
594  */
595  if (inner_rel->consider_parallel && outer_rel->consider_parallel &&
596  is_parallel_safe(root, (Node *) restrictlist) &&
597  is_parallel_safe(root, (Node *) joinrel->reltarget->exprs))
598  joinrel->consider_parallel = true;
599 
600  /* Add the joinrel to the PlannerInfo. */
601  add_join_rel(root, joinrel);
602 
603  /*
604  * Also, if dynamic-programming join search is active, add the new joinrel
605  * to the appropriate sublist. Note: you might think the Assert on number
606  * of members should be for equality, but some of the level 1 rels might
607  * have been joinrels already, so we can only assert <=.
608  */
609  if (root->join_rel_level)
610  {
611  Assert(root->join_cur_level > 0);
612  Assert(root->join_cur_level <= bms_num_members(joinrel->relids));
613  root->join_rel_level[root->join_cur_level] =
614  lappend(root->join_rel_level[root->join_cur_level], joinrel);
615  }
616 
617  return joinrel;
618 }
bool has_eclass_joins
Definition: relation.h:591
struct Path * cheapest_unique_path
Definition: relation.h:544
PathTarget * create_empty_pathtarget(void)
Definition: tlist.c:653
#define NIL
Definition: pg_list.h:69
int join_cur_level
Definition: relation.h:226
List * unique_for_rels
Definition: relation.h:580
List * statlist
Definition: relation.h:563
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:111
RelOptKind reloptkind
Definition: relation.h:522
Relids * attr_needed
Definition: relation.h:558
RelOptInfo * find_join_rel(PlannerInfo *root, Relids relids)
Definition: relnode.c:308
void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: costsize.c:4073
struct Path * cheapest_startup_path
Definition: relation.h:542
Oid userid
Definition: relation.h:573
double tuples
Definition: relation.h:565
List * baserestrictinfo
Definition: relation.h:584
bool consider_param_startup
Definition: relation.h:532
Definition: nodes.h:509
List * partial_pathlist
Definition: relation.h:541
List * cheapest_parameterized_paths
Definition: relation.h:545
Index baserestrict_min_security
Definition: relation.h:587
bool useridiscurrent
Definition: relation.h:574
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:566
PlannerInfo * subroot
Definition: relation.h:567
bool consider_startup
Definition: relation.h:531
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:1073
Relids lateral_relids
Definition: relation.h:550
Cost per_tuple
Definition: relation.h:46
static void set_foreign_rel_properties(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:371
double tuple_fraction
Definition: relation.h:291
static void build_joinrel_tlist(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *input_rel)
Definition: relnode.c:672
Relids min_join_parameterization(PlannerInfo *root, Relids joinrelids, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:629
int bms_num_members(const Bitmapset *a)
Definition: bitmapset.c:605
struct Path * cheapest_total_path
Definition: relation.h:543
static List * build_joinrel_restrictlist(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:758
List * joininfo
Definition: relation.h:589
struct FdwRoutine * fdwroutine
Definition: relation.h:576
Relids relids
Definition: relation.h:525
bool has_relevant_eclass_joinclause(PlannerInfo *root, RelOptInfo *rel1)
Definition: equivclass.c:2358
List * non_unique_for_rels
Definition: relation.h:581
List * ppilist
Definition: relation.h:540
Index relid
Definition: relation.h:553
List * lappend(List *list, void *datum)
Definition: list.c:128
Relids lateral_referencers
Definition: relation.h:561
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:663
Oid serverid
Definition: relation.h:572
List * exprs
Definition: relation.h:883
Relids direct_lateral_relids
Definition: relation.h:549
int rel_parallel_workers
Definition: relation.h:569
RTEKind rtekind
Definition: relation.h:555
List * indexlist
Definition: relation.h:562
double rows
Definition: relation.h:528
#define InvalidOid
Definition: postgres_ext.h:36
void * fdw_private
Definition: relation.h:577
#define makeNode(_type_)
Definition: nodes.h:557
BlockNumber pages
Definition: relation.h:564
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
List ** join_rel_level
Definition: relation.h:225
List * lateral_vars
Definition: relation.h:560
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:218
bool consider_parallel
Definition: relation.h:533
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:817
AttrNumber max_attr
Definition: relation.h:557
List * pathlist
Definition: relation.h:539
int32 * attr_widths
Definition: relation.h:559
Definition: pg_list.h:45
struct PathTarget * reltarget
Definition: relation.h:536
QualCost baserestrictcost
Definition: relation.h:586
static void add_join_rel(PlannerInfo *root, RelOptInfo *joinrel)
Definition: relnode.c:409
List * subplan_params
Definition: relation.h:568
static void build_joinrel_joinlist(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:788
Relids top_parent_relids
Definition: relation.h:594
AttrNumber min_attr
Definition: relation.h:556
static void build_join_rel_hash ( PlannerInfo root)
static

Definition at line 266 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().

267 {
268  HTAB *hashtab;
269  HASHCTL hash_ctl;
270  ListCell *l;
271 
272  /* Create the hash table */
273  MemSet(&hash_ctl, 0, sizeof(hash_ctl));
274  hash_ctl.keysize = sizeof(Relids);
275  hash_ctl.entrysize = sizeof(JoinHashEntry);
276  hash_ctl.hash = bitmap_hash;
277  hash_ctl.match = bitmap_match;
278  hash_ctl.hcxt = CurrentMemoryContext;
279  hashtab = hash_create("JoinRelHashTable",
280  256L,
281  &hash_ctl,
283 
284  /* Insert all the already-existing joinrels */
285  foreach(l, root->join_rel_list)
286  {
287  RelOptInfo *rel = (RelOptInfo *) lfirst(l);
288  JoinHashEntry *hentry;
289  bool found;
290 
291  hentry = (JoinHashEntry *) hash_search(hashtab,
292  &(rel->relids),
293  HASH_ENTER,
294  &found);
295  Assert(!found);
296  hentry->join_rel = rel;
297  }
298 
299  root->join_rel_hash = hashtab;
300 }
#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:857
List * join_rel_list
Definition: relation.h:215
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:525
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:675
#define lfirst(lc)
Definition: pg_list.h:106
#define HASH_COMPARE
Definition: hsearch.h:90
struct HTAB * join_rel_hash
Definition: relation.h:216
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 788 of file relnode.c.

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

Referenced by build_join_rel().

791 {
792  List *result;
793 
794  /*
795  * Collect all the clauses that syntactically belong above this level,
796  * eliminating any duplicates (important since we will see many of the
797  * same clauses arriving from both input relations).
798  */
799  result = subbuild_joinrel_joinlist(joinrel, outer_rel->joininfo, NIL);
800  result = subbuild_joinrel_joinlist(joinrel, inner_rel->joininfo, result);
801 
802  joinrel->joininfo = result;
803 }
#define NIL
Definition: pg_list.h:69
return result
Definition: formatting.c:1632
List * joininfo
Definition: relation.h:589
static List * subbuild_joinrel_joinlist(RelOptInfo *joinrel, List *joininfo_list, List *new_joininfo)
Definition: relnode.c:840
Definition: pg_list.h:45
static List * build_joinrel_restrictlist ( PlannerInfo root,
RelOptInfo joinrel,
RelOptInfo outer_rel,
RelOptInfo inner_rel 
)
static

Definition at line 758 of file relnode.c.

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

Referenced by build_join_rel().

762 {
763  List *result;
764 
765  /*
766  * Collect all the clauses that syntactically belong at this level,
767  * eliminating any duplicates (important since we will see many of the
768  * same clauses arriving from both input relations).
769  */
770  result = subbuild_joinrel_restrictlist(joinrel, outer_rel->joininfo, NIL);
771  result = subbuild_joinrel_restrictlist(joinrel, inner_rel->joininfo, result);
772 
773  /*
774  * Add on any clauses derived from EquivalenceClasses. These cannot be
775  * redundant with the clauses in the joininfo lists, so don't bother
776  * checking.
777  */
778  result = list_concat(result,
780  joinrel->relids,
781  outer_rel->relids,
782  inner_rel));
783 
784  return result;
785 }
#define NIL
Definition: pg_list.h:69
static List * subbuild_joinrel_restrictlist(RelOptInfo *joinrel, List *joininfo_list, List *new_restrictlist)
Definition: relnode.c:806
List * list_concat(List *list1, List *list2)
Definition: list.c:321
return result
Definition: formatting.c:1632
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:589
Relids relids
Definition: relation.h:525
Definition: pg_list.h:45
static void build_joinrel_tlist ( PlannerInfo root,
RelOptInfo joinrel,
RelOptInfo input_rel 
)
static

Definition at line 672 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().

674 {
675  Relids relids = joinrel->relids;
676  ListCell *vars;
677 
678  foreach(vars, input_rel->reltarget->exprs)
679  {
680  Var *var = (Var *) lfirst(vars);
681  RelOptInfo *baserel;
682  int ndx;
683 
684  /*
685  * Ignore PlaceHolderVars in the input tlists; we'll make our own
686  * decisions about whether to copy them.
687  */
688  if (IsA(var, PlaceHolderVar))
689  continue;
690 
691  /*
692  * Otherwise, anything in a baserel or joinrel targetlist ought to be
693  * a Var. (More general cases can only appear in appendrel child
694  * rels, which will never be seen here.)
695  */
696  if (!IsA(var, Var))
697  elog(ERROR, "unexpected node type in rel targetlist: %d",
698  (int) nodeTag(var));
699 
700  /* Get the Var's original base rel */
701  baserel = find_base_rel(root, var->varno);
702 
703  /* Is it still needed above this joinrel? */
704  ndx = var->varattno - baserel->min_attr;
705  if (bms_nonempty_difference(baserel->attr_needed[ndx], relids))
706  {
707  /* Yup, add it to the output */
708  joinrel->reltarget->exprs = lappend(joinrel->reltarget->exprs, var);
709  /* Vars have cost zero, so no need to adjust reltarget->cost */
710  joinrel->reltarget->width += baserel->attr_widths[ndx];
711  }
712  }
713 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:560
Relids * attr_needed
Definition: relation.h:558
AttrNumber varattno
Definition: primnodes.h:168
Definition: primnodes.h:163
#define ERROR
Definition: elog.h:43
Relids relids
Definition: relation.h:525
List * lappend(List *list, void *datum)
Definition: list.c:128
Index varno
Definition: primnodes.h:166
List * exprs
Definition: relation.h:883
#define lfirst(lc)
Definition: pg_list.h:106
#define nodeTag(nodeptr)
Definition: nodes.h:514
int width
Definition: relation.h:886
#define elog
Definition: elog.h:219
RelOptInfo * find_base_rel(PlannerInfo *root, int relid)
Definition: relnode.c:243
int32 * attr_widths
Definition: relation.h:559
Definition: regcomp.c:224
struct PathTarget * reltarget
Definition: relation.h:536
bool bms_nonempty_difference(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:494
AttrNumber min_attr
Definition: relation.h:556
RelOptInfo* build_simple_rel ( PlannerInfo root,
int  relid,
RelOptInfo parent 
)

Definition at line 91 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_copy(), 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, RelOptInfo::non_unique_for_rels, 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_BASEREL, RELOPT_OTHER_MEMBER_REL, RelOptInfo::reloptkind, RelOptInfo::reltarget, RelOptInfo::rows, RTE_CTE, RTE_FUNCTION, RTE_NAMEDTUPLESTORE, RTE_RELATION, RTE_SUBQUERY, RTE_TABLEFUNC, RTE_VALUES, RelOptInfo::rtekind, RangeTblEntry::rtekind, RangeTblEntry::securityQuals, RelOptInfo::serverid, PlannerInfo::simple_rel_array, PlannerInfo::simple_rte_array, QualCost::startup, RelOptInfo::statlist, RelOptInfo::subplan_params, RelOptInfo::subroot, RelOptInfo::top_parent_relids, PlannerInfo::tuple_fraction, RelOptInfo::tuples, RelOptInfo::unique_for_rels, RelOptInfo::userid, and RelOptInfo::useridiscurrent.

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

92 {
93  RelOptInfo *rel;
94  RangeTblEntry *rte;
95 
96  /* Rel should not exist already */
97  Assert(relid > 0 && relid < root->simple_rel_array_size);
98  if (root->simple_rel_array[relid] != NULL)
99  elog(ERROR, "rel %d already exists", relid);
100 
101  /* Fetch RTE for relation */
102  rte = root->simple_rte_array[relid];
103  Assert(rte != NULL);
104 
105  rel = makeNode(RelOptInfo);
107  rel->relids = bms_make_singleton(relid);
108  rel->rows = 0;
109  /* cheap startup cost is interesting iff not all tuples to be retrieved */
110  rel->consider_startup = (root->tuple_fraction > 0);
111  rel->consider_param_startup = false; /* might get changed later */
112  rel->consider_parallel = false; /* might get changed later */
114  rel->pathlist = NIL;
115  rel->ppilist = NIL;
116  rel->partial_pathlist = NIL;
118  rel->cheapest_total_path = NULL;
119  rel->cheapest_unique_path = NULL;
122  rel->lateral_relids = NULL;
123  rel->relid = relid;
124  rel->rtekind = rte->rtekind;
125  /* min_attr, max_attr, attr_needed, attr_widths are set below */
126  rel->lateral_vars = NIL;
127  rel->lateral_referencers = NULL;
128  rel->indexlist = NIL;
129  rel->statlist = NIL;
130  rel->pages = 0;
131  rel->tuples = 0;
132  rel->allvisfrac = 0;
133  rel->subroot = NULL;
134  rel->subplan_params = NIL;
135  rel->rel_parallel_workers = -1; /* set up in get_relation_info */
136  rel->serverid = InvalidOid;
137  rel->userid = rte->checkAsUser;
138  rel->useridiscurrent = false;
139  rel->fdwroutine = NULL;
140  rel->fdw_private = NULL;
141  rel->unique_for_rels = NIL;
142  rel->non_unique_for_rels = NIL;
143  rel->baserestrictinfo = NIL;
144  rel->baserestrictcost.startup = 0;
145  rel->baserestrictcost.per_tuple = 0;
146  rel->baserestrict_min_security = UINT_MAX;
147  rel->joininfo = NIL;
148  rel->has_eclass_joins = false;
149 
150  /*
151  * Pass top parent's relids down the inheritance hierarchy. If the parent
152  * has top_parent_relids set, it's a direct or an indirect child of the
153  * top parent indicated by top_parent_relids. By extension this child is
154  * also an indirect child of that parent.
155  */
156  if (parent)
157  {
158  if (parent->top_parent_relids)
159  rel->top_parent_relids = parent->top_parent_relids;
160  else
161  rel->top_parent_relids = bms_copy(parent->relids);
162  }
163  else
164  rel->top_parent_relids = NULL;
165 
166  /* Check type of rtable entry */
167  switch (rte->rtekind)
168  {
169  case RTE_RELATION:
170  /* Table --- retrieve statistics from the system catalogs */
171  get_relation_info(root, rte->relid, rte->inh, rel);
172  break;
173  case RTE_SUBQUERY:
174  case RTE_FUNCTION:
175  case RTE_TABLEFUNC:
176  case RTE_VALUES:
177  case RTE_CTE:
178  case RTE_NAMEDTUPLESTORE:
179 
180  /*
181  * Subquery, function, tablefunc, or values list --- set up attr
182  * range and arrays
183  *
184  * Note: 0 is included in range to support whole-row Vars
185  */
186  rel->min_attr = 0;
187  rel->max_attr = list_length(rte->eref->colnames);
188  rel->attr_needed = (Relids *)
189  palloc0((rel->max_attr - rel->min_attr + 1) * sizeof(Relids));
190  rel->attr_widths = (int32 *)
191  palloc0((rel->max_attr - rel->min_attr + 1) * sizeof(int32));
192  break;
193  default:
194  elog(ERROR, "unrecognized RTE kind: %d",
195  (int) rte->rtekind);
196  break;
197  }
198 
199  /* Save the finished struct in the query's simple_rel_array */
200  root->simple_rel_array[relid] = rel;
201 
202  /*
203  * This is a convenient spot at which to note whether rels participating
204  * in the query have any securityQuals attached. If so, increase
205  * root->qual_security_level to ensure it's larger than the maximum
206  * security level needed for securityQuals.
207  */
208  if (rte->securityQuals)
210  list_length(rte->securityQuals));
211 
212  /*
213  * If this rel is an appendrel parent, recurse to build "other rel"
214  * RelOptInfos for its children. They are "other rels" because they are
215  * not in the main join tree, but we will need RelOptInfos to plan access
216  * to them.
217  */
218  if (rte->inh)
219  {
220  ListCell *l;
221 
222  foreach(l, root->append_rel_list)
223  {
224  AppendRelInfo *appinfo = (AppendRelInfo *) lfirst(l);
225 
226  /* append_rel_list contains all append rels; ignore others */
227  if (appinfo->parent_relid != relid)
228  continue;
229 
230  (void) build_simple_rel(root, appinfo->child_relid,
231  rel);
232  }
233  }
234 
235  return rel;
236 }
bool has_eclass_joins
Definition: relation.h:591
struct Path * cheapest_unique_path
Definition: relation.h:544
PathTarget * create_empty_pathtarget(void)
Definition: tlist.c:653
#define NIL
Definition: pg_list.h:69
List * unique_for_rels
Definition: relation.h:580
List * statlist
Definition: relation.h:563
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:111
RelOptKind reloptkind
Definition: relation.h:522
Relids * attr_needed
Definition: relation.h:558
List * colnames
Definition: primnodes.h:43
struct Path * cheapest_startup_path
Definition: relation.h:542
Oid userid
Definition: relation.h:573
List * securityQuals
Definition: parsenodes.h:1025
double tuples
Definition: relation.h:565
List * baserestrictinfo
Definition: relation.h:584
bool consider_param_startup
Definition: relation.h:532
List * partial_pathlist
Definition: relation.h:541
List * cheapest_parameterized_paths
Definition: relation.h:545
Index baserestrict_min_security
Definition: relation.h:587
bool useridiscurrent
Definition: relation.h:574
Cost startup
Definition: relation.h:45
double allvisfrac
Definition: relation.h:566
signed int int32
Definition: c.h:256
struct RelOptInfo ** simple_rel_array
Definition: relation.h:179
PlannerInfo * subroot
Definition: relation.h:567
bool consider_startup
Definition: relation.h:531
Relids lateral_relids
Definition: relation.h:550
Cost per_tuple
Definition: relation.h:46
double tuple_fraction
Definition: relation.h:291
#define ERROR
Definition: elog.h:43
struct Path * cheapest_total_path
Definition: relation.h:543
Bitmapset * bms_make_singleton(int x)
Definition: bitmapset.c:179
List * joininfo
Definition: relation.h:589
struct FdwRoutine * fdwroutine
Definition: relation.h:576
Relids relids
Definition: relation.h:525
RelOptInfo * build_simple_rel(PlannerInfo *root, int relid, RelOptInfo *parent)
Definition: relnode.c:91
List * non_unique_for_rels
Definition: relation.h:581
List * ppilist
Definition: relation.h:540
Index relid
Definition: relation.h:553
Bitmapset * Relids
Definition: relation.h:28
RangeTblEntry ** simple_rte_array
Definition: relation.h:188
Relids lateral_referencers
Definition: relation.h:561
Oid serverid
Definition: relation.h:572
Relids direct_lateral_relids
Definition: relation.h:549
void * palloc0(Size size)
Definition: mcxt.c:878
int rel_parallel_workers
Definition: relation.h:569
List * append_rel_list
Definition: relation.h:252
RTEKind rtekind
Definition: relation.h:555
List * indexlist
Definition: relation.h:562
double rows
Definition: relation.h:528
#define InvalidOid
Definition: postgres_ext.h:36
void * fdw_private
Definition: relation.h:577
#define Max(x, y)
Definition: c.h:800
#define makeNode(_type_)
Definition: nodes.h:557
BlockNumber pages
Definition: relation.h:564
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define lfirst(lc)
Definition: pg_list.h:106
List * lateral_vars
Definition: relation.h:560
static int list_length(const List *l)
Definition: pg_list.h:89
Index qual_security_level
Definition: relation.h:294
bool consider_parallel
Definition: relation.h:533
RTEKind rtekind
Definition: parsenodes.h:929
AttrNumber max_attr
Definition: relation.h:557
List * pathlist
Definition: relation.h:539
#define elog
Definition: elog.h:219
Index child_relid
Definition: relation.h:1976
Alias * eref
Definition: parsenodes.h:1016
Index parent_relid
Definition: relation.h:1975
int32 * attr_widths
Definition: relation.h:559
struct PathTarget * reltarget
Definition: relation.h:536
QualCost baserestrictcost
Definition: relation.h:586
List * subplan_params
Definition: relation.h:568
void get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, RelOptInfo *rel)
Definition: plancat.c:101
Relids top_parent_relids
Definition: relation.h:594
AttrNumber min_attr
Definition: relation.h:556
RelOptInfo* fetch_upper_rel ( PlannerInfo root,
UpperRelationKind  kind,
Relids  relids 
)

Definition at line 919 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().

920 {
921  RelOptInfo *upperrel;
922  ListCell *lc;
923 
924  /*
925  * For the moment, our indexing data structure is just a List for each
926  * relation kind. If we ever get so many of one kind that this stops
927  * working well, we can improve it. No code outside this function should
928  * assume anything about how to find a particular upperrel.
929  */
930 
931  /* If we already made this upperrel for the query, return it */
932  foreach(lc, root->upper_rels[kind])
933  {
934  upperrel = (RelOptInfo *) lfirst(lc);
935 
936  if (bms_equal(upperrel->relids, relids))
937  return upperrel;
938  }
939 
940  upperrel = makeNode(RelOptInfo);
941  upperrel->reloptkind = RELOPT_UPPER_REL;
942  upperrel->relids = bms_copy(relids);
943 
944  /* cheap startup cost is interesting iff not all tuples to be retrieved */
945  upperrel->consider_startup = (root->tuple_fraction > 0);
946  upperrel->consider_param_startup = false;
947  upperrel->consider_parallel = false; /* might get changed later */
948  upperrel->reltarget = create_empty_pathtarget();
949  upperrel->pathlist = NIL;
950  upperrel->cheapest_startup_path = NULL;
951  upperrel->cheapest_total_path = NULL;
952  upperrel->cheapest_unique_path = NULL;
953  upperrel->cheapest_parameterized_paths = NIL;
954 
955  root->upper_rels[kind] = lappend(root->upper_rels[kind], upperrel);
956 
957  return upperrel;
958 }
struct Path * cheapest_unique_path
Definition: relation.h:544
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:111
RelOptKind reloptkind
Definition: relation.h:522
struct Path * cheapest_startup_path
Definition: relation.h:542
bool consider_param_startup
Definition: relation.h:532
List * cheapest_parameterized_paths
Definition: relation.h:545
bool consider_startup
Definition: relation.h:531
double tuple_fraction
Definition: relation.h:291
struct Path * cheapest_total_path
Definition: relation.h:543
Relids relids
Definition: relation.h:525
List * lappend(List *list, void *datum)
Definition: list.c:128
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
#define lfirst(lc)
Definition: pg_list.h:106
bool consider_parallel
Definition: relation.h:533
List * pathlist
Definition: relation.h:539
struct PathTarget * reltarget
Definition: relation.h:536
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:131
List * upper_rels[UPPERREL_FINAL+1]
Definition: relation.h:272
RelOptInfo* find_base_rel ( PlannerInfo root,
int  relid 
)

Definition at line 243 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_join_input_rel(), find_single_rel_for_clauses(), get_foreign_key_join_selectivity(), join_is_removable(), make_rel_from_joinlist(), reduce_unique_semijoins(), 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().

244 {
245  RelOptInfo *rel;
246 
247  Assert(relid > 0);
248 
249  if (relid < root->simple_rel_array_size)
250  {
251  rel = root->simple_rel_array[relid];
252  if (rel)
253  return rel;
254  }
255 
256  elog(ERROR, "no relation entry for relid %d", relid);
257 
258  return NULL; /* keep compiler quiet */
259 }
struct RelOptInfo ** simple_rel_array
Definition: relation.h:179
#define ERROR
Definition: elog.h:43
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define elog
Definition: elog.h:219
AppendRelInfo* find_childrel_appendrelinfo ( PlannerInfo root,
RelOptInfo rel 
)

Definition at line 970 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(), and find_childrel_parents().

971 {
972  Index relid = rel->relid;
973  ListCell *lc;
974 
975  /* Should only be called on child rels */
977 
978  foreach(lc, root->append_rel_list)
979  {
980  AppendRelInfo *appinfo = (AppendRelInfo *) lfirst(lc);
981 
982  if (appinfo->child_relid == relid)
983  return appinfo;
984  }
985  /* should have found the entry ... */
986  elog(ERROR, "child rel %d not found in append_rel_list", relid);
987  return NULL; /* not reached */
988 }
RelOptKind reloptkind
Definition: relation.h:522
#define ERROR
Definition: elog.h:43
Index relid
Definition: relation.h:553
List * append_rel_list
Definition: relation.h:252
unsigned int Index
Definition: c.h:365
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define lfirst(lc)
Definition: pg_list.h:106
#define elog
Definition: elog.h:219
Index child_relid
Definition: relation.h:1976
Relids find_childrel_parents ( PlannerInfo root,
RelOptInfo rel 
)

Definition at line 1000 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, RelOptInfo::reloptkind, and result.

Referenced by check_index_predicates(), and generate_implied_equalities_for_column().

1001 {
1002  Relids result = NULL;
1003 
1005 
1006  do
1007  {
1008  AppendRelInfo *appinfo = find_childrel_appendrelinfo(root, rel);
1009  Index prelid = appinfo->parent_relid;
1010 
1011  result = bms_add_member(result, prelid);
1012 
1013  /* traverse up to the parent rel, loop if it's also a child rel */
1014  rel = find_base_rel(root, prelid);
1015  } while (rel->reloptkind == RELOPT_OTHER_MEMBER_REL);
1016 
1017  Assert(rel->reloptkind == RELOPT_BASEREL);
1018 
1019  return result;
1020 }
RelOptKind reloptkind
Definition: relation.h:522
return result
Definition: formatting.c:1632
AppendRelInfo * find_childrel_appendrelinfo(PlannerInfo *root, RelOptInfo *rel)
Definition: relnode.c:970
unsigned int Index
Definition: c.h:365
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:698
RelOptInfo * find_base_rel(PlannerInfo *root, int relid)
Definition: relnode.c:243
Index parent_relid
Definition: relation.h:1975
RelOptInfo* find_join_rel ( PlannerInfo root,
Relids  relids 
)

Definition at line 308 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().

309 {
310  /*
311  * Switch to using hash lookup when list grows "too long". The threshold
312  * is arbitrary and is known only here.
313  */
314  if (!root->join_rel_hash && list_length(root->join_rel_list) > 32)
315  build_join_rel_hash(root);
316 
317  /*
318  * Use either hashtable lookup or linear search, as appropriate.
319  *
320  * Note: the seemingly redundant hashkey variable is used to avoid taking
321  * the address of relids; unless the compiler is exceedingly smart, doing
322  * so would force relids out of a register and thus probably slow down the
323  * list-search case.
324  */
325  if (root->join_rel_hash)
326  {
327  Relids hashkey = relids;
328  JoinHashEntry *hentry;
329 
330  hentry = (JoinHashEntry *) hash_search(root->join_rel_hash,
331  &hashkey,
332  HASH_FIND,
333  NULL);
334  if (hentry)
335  return hentry->join_rel;
336  }
337  else
338  {
339  ListCell *l;
340 
341  foreach(l, root->join_rel_list)
342  {
343  RelOptInfo *rel = (RelOptInfo *) lfirst(l);
344 
345  if (bms_equal(rel->relids, relids))
346  return rel;
347  }
348  }
349 
350  return NULL;
351 }
List * join_rel_list
Definition: relation.h:215
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:525
static void build_join_rel_hash(PlannerInfo *root)
Definition: relnode.c:266
#define NULL
Definition: c.h:229
#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:216
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:131
ParamPathInfo* get_appendrel_parampathinfo ( RelOptInfo appendrel,
Relids  required_outer 
)

Definition at line 1334 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().

1335 {
1336  ParamPathInfo *ppi;
1337  ListCell *lc;
1338 
1339  /* Unparameterized paths have no ParamPathInfo */
1340  if (bms_is_empty(required_outer))
1341  return NULL;
1342 
1343  Assert(!bms_overlap(appendrel->relids, required_outer));
1344 
1345  /* If we already have a PPI for this parameterization, just return it */
1346  foreach(lc, appendrel->ppilist)
1347  {
1348  ppi = (ParamPathInfo *) lfirst(lc);
1349  if (bms_equal(ppi->ppi_req_outer, required_outer))
1350  return ppi;
1351  }
1352 
1353  /* Else build the ParamPathInfo */
1354  ppi = makeNode(ParamPathInfo);
1355  ppi->ppi_req_outer = required_outer;
1356  ppi->ppi_rows = 0;
1357  ppi->ppi_clauses = NIL;
1358  appendrel->ppilist = lappend(appendrel->ppilist, ppi);
1359 
1360  return ppi;
1361 }
#define NIL
Definition: pg_list.h:69
Relids relids
Definition: relation.h:525
List * ppilist
Definition: relation.h:540
List * lappend(List *list, void *datum)
Definition: list.c:128
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:663
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define lfirst(lc)
Definition: pg_list.h:106
List * ppi_clauses
Definition: relation.h:914
double ppi_rows
Definition: relation.h:913
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:443
Relids ppi_req_outer
Definition: relation.h:912
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:131
ParamPathInfo* get_baserel_parampathinfo ( PlannerInfo root,
RelOptInfo baserel,
Relids  required_outer 
)

Definition at line 1035 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_merge_path(), create_gather_path(), create_index_path(), create_namedtuplestorescan_path(), create_samplescan_path(), create_seqscan_path(), create_subqueryscan_path(), create_tablefuncscan_path(), create_tidscan_path(), create_valuesscan_path(), create_worktablescan_path(), postgresGetForeignPaths(), and reparameterize_path().

1037 {
1038  ParamPathInfo *ppi;
1039  Relids joinrelids;
1040  List *pclauses;
1041  double rows;
1042  ListCell *lc;
1043 
1044  /* Unparameterized paths have no ParamPathInfo */
1045  if (bms_is_empty(required_outer))
1046  return NULL;
1047 
1048  Assert(!bms_overlap(baserel->relids, required_outer));
1049 
1050  /* If we already have a PPI for this parameterization, just return it */
1051  foreach(lc, baserel->ppilist)
1052  {
1053  ppi = (ParamPathInfo *) lfirst(lc);
1054  if (bms_equal(ppi->ppi_req_outer, required_outer))
1055  return ppi;
1056  }
1057 
1058  /*
1059  * Identify all joinclauses that are movable to this base rel given this
1060  * parameterization.
1061  */
1062  joinrelids = bms_union(baserel->relids, required_outer);
1063  pclauses = NIL;
1064  foreach(lc, baserel->joininfo)
1065  {
1066  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
1067 
1068  if (join_clause_is_movable_into(rinfo,
1069  baserel->relids,
1070  joinrelids))
1071  pclauses = lappend(pclauses, rinfo);
1072  }
1073 
1074  /*
1075  * Add in joinclauses generated by EquivalenceClasses, too. (These
1076  * necessarily satisfy join_clause_is_movable_into.)
1077  */
1078  pclauses = list_concat(pclauses,
1080  joinrelids,
1081  required_outer,
1082  baserel));
1083 
1084  /* Estimate the number of rows returned by the parameterized scan */
1085  rows = get_parameterized_baserel_size(root, baserel, pclauses);
1086 
1087  /* And now we can build the ParamPathInfo */
1088  ppi = makeNode(ParamPathInfo);
1089  ppi->ppi_req_outer = required_outer;
1090  ppi->ppi_rows = rows;
1091  ppi->ppi_clauses = pclauses;
1092  baserel->ppilist = lappend(baserel->ppilist, ppi);
1093 
1094  return ppi;
1095 }
#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:589
Relids relids
Definition: relation.h:525
bool join_clause_is_movable_into(RestrictInfo *rinfo, Relids currentrelids, Relids current_and_outer)
Definition: restrictinfo.c:508
List * ppilist
Definition: relation.h:540
List * lappend(List *list, void *datum)
Definition: list.c:128
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:663
double get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel, List *param_clauses)
Definition: costsize.c:4023
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define lfirst(lc)
Definition: pg_list.h:106
List * ppi_clauses
Definition: relation.h:914
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:218
double ppi_rows
Definition: relation.h:913
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:443
Relids ppi_req_outer
Definition: relation.h:912
Definition: pg_list.h:45
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:131
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 1126 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().

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

Definition at line 629 of file relnode.c.

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

Referenced by build_join_rel(), and join_is_legal().

633 {
634  Relids result;
635 
636  /*
637  * Basically we just need the union of the inputs' lateral_relids, less
638  * whatever is already in the join.
639  *
640  * It's not immediately obvious that this is a valid way to compute the
641  * result, because it might seem that we're ignoring possible lateral refs
642  * of PlaceHolderVars that are due to be computed at the join but not in
643  * either input. However, because create_lateral_join_info() already
644  * charged all such PHV refs to each member baserel of the join, they'll
645  * be accounted for already in the inputs' lateral_relids. Likewise, we
646  * do not need to worry about doing transitive closure here, because that
647  * was already accounted for in the original baserel lateral_relids.
648  */
649  result = bms_union(outer_rel->lateral_relids, inner_rel->lateral_relids);
650  result = bms_del_members(result, joinrelids);
651 
652  /* Maintain invariant that result is exactly NULL if empty */
653  if (bms_is_empty(result))
654  result = NULL;
655 
656  return result;
657 }
return result
Definition: formatting.c:1632
Relids lateral_relids
Definition: relation.h:550
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:663
#define NULL
Definition: c.h:229
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:218
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:817
static void set_foreign_rel_properties ( RelOptInfo joinrel,
RelOptInfo outer_rel,
RelOptInfo inner_rel 
)
static

Definition at line 371 of file relnode.c.

References RelOptInfo::fdwroutine, GetUserId(), OidIsValid, RelOptInfo::serverid, RelOptInfo::userid, and RelOptInfo::useridiscurrent.

Referenced by build_join_rel().

373 {
374  if (OidIsValid(outer_rel->serverid) &&
375  inner_rel->serverid == outer_rel->serverid)
376  {
377  if (inner_rel->userid == outer_rel->userid)
378  {
379  joinrel->serverid = outer_rel->serverid;
380  joinrel->userid = outer_rel->userid;
381  joinrel->useridiscurrent = outer_rel->useridiscurrent || inner_rel->useridiscurrent;
382  joinrel->fdwroutine = outer_rel->fdwroutine;
383  }
384  else if (!OidIsValid(inner_rel->userid) &&
385  outer_rel->userid == GetUserId())
386  {
387  joinrel->serverid = outer_rel->serverid;
388  joinrel->userid = outer_rel->userid;
389  joinrel->useridiscurrent = true;
390  joinrel->fdwroutine = outer_rel->fdwroutine;
391  }
392  else if (!OidIsValid(outer_rel->userid) &&
393  inner_rel->userid == GetUserId())
394  {
395  joinrel->serverid = outer_rel->serverid;
396  joinrel->userid = inner_rel->userid;
397  joinrel->useridiscurrent = true;
398  joinrel->fdwroutine = outer_rel->fdwroutine;
399  }
400  }
401 }
Oid GetUserId(void)
Definition: miscinit.c:283
Oid userid
Definition: relation.h:573
bool useridiscurrent
Definition: relation.h:574
#define OidIsValid(objectId)
Definition: c.h:538
struct FdwRoutine * fdwroutine
Definition: relation.h:576
Oid serverid
Definition: relation.h:572
void setup_simple_rel_arrays ( PlannerInfo root)

Definition at line 62 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().

63 {
64  Index rti;
65  ListCell *lc;
66 
67  /* Arrays are accessed using RT indexes (1..N) */
68  root->simple_rel_array_size = list_length(root->parse->rtable) + 1;
69 
70  /* simple_rel_array is initialized to all NULLs */
71  root->simple_rel_array = (RelOptInfo **)
72  palloc0(root->simple_rel_array_size * sizeof(RelOptInfo *));
73 
74  /* simple_rte_array is an array equivalent of the rtable list */
75  root->simple_rte_array = (RangeTblEntry **)
76  palloc0(root->simple_rel_array_size * sizeof(RangeTblEntry *));
77  rti = 1;
78  foreach(lc, root->parse->rtable)
79  {
80  RangeTblEntry *rte = (RangeTblEntry *) lfirst(lc);
81 
82  root->simple_rte_array[rti++] = rte;
83  }
84 }
Query * parse
Definition: relation.h:155
struct RelOptInfo ** simple_rel_array
Definition: relation.h:179
List * rtable
Definition: parsenodes.h:135
int simple_rel_array_size
Definition: relation.h:180
RangeTblEntry ** simple_rte_array
Definition: relation.h:188
void * palloc0(Size size)
Definition: mcxt.c:878
unsigned int Index
Definition: c.h:365
#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 840 of file relnode.c.

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

Referenced by build_joinrel_joinlist().

843 {
844  ListCell *l;
845 
846  foreach(l, joininfo_list)
847  {
848  RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
849 
850  if (bms_is_subset(rinfo->required_relids, joinrel->relids))
851  {
852  /*
853  * This clause becomes a restriction clause for the joinrel, since
854  * it refers to no outside rels. So we can ignore it in this
855  * routine.
856  */
857  }
858  else
859  {
860  /*
861  * This clause is still a join clause at this level, so add it to
862  * the new joininfo list, being careful to eliminate duplicates.
863  * (Since RestrictInfo nodes in different joinlists will have been
864  * multiply-linked rather than copied, pointer equality should be
865  * a sufficient test.)
866  */
867  new_joininfo = list_append_unique_ptr(new_joininfo, rinfo);
868  }
869  }
870 
871  return new_joininfo;
872 }
Relids required_relids
Definition: relation.h:1765
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:308
Relids relids
Definition: relation.h:525
#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 806 of file relnode.c.

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

Referenced by build_joinrel_restrictlist().

809 {
810  ListCell *l;
811 
812  foreach(l, joininfo_list)
813  {
814  RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
815 
816  if (bms_is_subset(rinfo->required_relids, joinrel->relids))
817  {
818  /*
819  * This clause becomes a restriction clause for the joinrel, since
820  * it refers to no outside rels. Add it to the list, being
821  * careful to eliminate duplicates. (Since RestrictInfo nodes in
822  * different joinlists will have been multiply-linked rather than
823  * copied, pointer equality should be a sufficient test.)
824  */
825  new_restrictlist = list_append_unique_ptr(new_restrictlist, rinfo);
826  }
827  else
828  {
829  /*
830  * This clause is still a join clause at this level, so we ignore
831  * it in this routine.
832  */
833  }
834  }
835 
836  return new_restrictlist;
837 }
Relids required_relids
Definition: relation.h:1765
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:308
Relids relids
Definition: relation.h:525
#define lfirst(lc)
Definition: pg_list.h:106