PostgreSQL Source Code  git master
joinrels.c File Reference
#include "postgres.h"
#include "miscadmin.h"
#include "catalog/partition.h"
#include "nodes/relation.h"
#include "optimizer/clauses.h"
#include "optimizer/joininfo.h"
#include "optimizer/pathnode.h"
#include "optimizer/paths.h"
#include "optimizer/prep.h"
#include "optimizer/cost.h"
#include "utils/memutils.h"
#include "utils/lsyscache.h"
Include dependency graph for joinrels.c:

Go to the source code of this file.

Functions

static void make_rels_by_clause_joins (PlannerInfo *root, RelOptInfo *old_rel, ListCell *other_rels)
 
static void make_rels_by_clauseless_joins (PlannerInfo *root, RelOptInfo *old_rel, ListCell *other_rels)
 
static bool has_join_restriction (PlannerInfo *root, RelOptInfo *rel)
 
static bool has_legal_joinclause (PlannerInfo *root, RelOptInfo *rel)
 
static bool is_dummy_rel (RelOptInfo *rel)
 
static bool restriction_is_constant_false (List *restrictlist, bool only_pushed_down)
 
static void populate_joinrel_with_paths (PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2, RelOptInfo *joinrel, SpecialJoinInfo *sjinfo, List *restrictlist)
 
static void try_partition_wise_join (PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2, RelOptInfo *joinrel, SpecialJoinInfo *parent_sjinfo, List *parent_restrictlist)
 
static int match_expr_to_partition_keys (Expr *expr, RelOptInfo *rel, bool strict_op)
 
void join_search_one_level (PlannerInfo *root, int level)
 
static bool join_is_legal (PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2, Relids joinrelids, SpecialJoinInfo **sjinfo_p, bool *reversed_p)
 
RelOptInfomake_join_rel (PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
 
bool have_join_order_restriction (PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
 
bool have_dangerous_phv (PlannerInfo *root, Relids outer_relids, Relids inner_params)
 
void mark_dummy_rel (RelOptInfo *rel)
 
bool have_partkey_equi_join (RelOptInfo *rel1, RelOptInfo *rel2, JoinType jointype, List *restrictlist)
 

Function Documentation

◆ has_join_restriction()

static bool has_join_restriction ( PlannerInfo root,
RelOptInfo rel 
)
static

Definition at line 1047 of file joinrels.c.

References bms_equal(), bms_is_subset(), bms_overlap(), JOIN_FULL, PlannerInfo::join_info_list, SpecialJoinInfo::jointype, RelOptInfo::lateral_referencers, RelOptInfo::lateral_relids, lfirst, SpecialJoinInfo::min_lefthand, SpecialJoinInfo::min_righthand, PlaceHolderInfo::ph_eval_at, PlannerInfo::placeholder_list, and RelOptInfo::relids.

Referenced by join_search_one_level().

1048 {
1049  ListCell *l;
1050 
1051  if (rel->lateral_relids != NULL || rel->lateral_referencers != NULL)
1052  return true;
1053 
1054  foreach(l, root->placeholder_list)
1055  {
1056  PlaceHolderInfo *phinfo = (PlaceHolderInfo *) lfirst(l);
1057 
1058  if (bms_is_subset(rel->relids, phinfo->ph_eval_at) &&
1059  !bms_equal(rel->relids, phinfo->ph_eval_at))
1060  return true;
1061  }
1062 
1063  foreach(l, root->join_info_list)
1064  {
1065  SpecialJoinInfo *sjinfo = (SpecialJoinInfo *) lfirst(l);
1066 
1067  /* ignore full joins --- other mechanisms preserve their ordering */
1068  if (sjinfo->jointype == JOIN_FULL)
1069  continue;
1070 
1071  /* ignore if SJ is already contained in rel */
1072  if (bms_is_subset(sjinfo->min_lefthand, rel->relids) &&
1073  bms_is_subset(sjinfo->min_righthand, rel->relids))
1074  continue;
1075 
1076  /* restricted if it overlaps LHS or RHS, but doesn't contain SJ */
1077  if (bms_overlap(sjinfo->min_lefthand, rel->relids) ||
1078  bms_overlap(sjinfo->min_righthand, rel->relids))
1079  return true;
1080  }
1081 
1082  return false;
1083 }
Relids ph_eval_at
Definition: relation.h:2154
List * join_info_list
Definition: relation.h:250
Relids min_righthand
Definition: relation.h:2008
Relids lateral_relids
Definition: relation.h:610
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:308
Relids relids
Definition: relation.h:585
Relids lateral_referencers
Definition: relation.h:621
#define lfirst(lc)
Definition: pg_list.h:106
JoinType jointype
Definition: relation.h:2011
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:443
List * placeholder_list
Definition: relation.h:258
Relids min_lefthand
Definition: relation.h:2007
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:131

◆ has_legal_joinclause()

static bool has_legal_joinclause ( PlannerInfo root,
RelOptInfo rel 
)
static

Definition at line 1103 of file joinrels.c.

References bms_free(), bms_overlap(), bms_union(), have_relevant_joinclause(), PlannerInfo::initial_rels, join_is_legal(), lfirst, and RelOptInfo::relids.

Referenced by have_join_order_restriction().

1104 {
1105  ListCell *lc;
1106 
1107  foreach(lc, root->initial_rels)
1108  {
1109  RelOptInfo *rel2 = (RelOptInfo *) lfirst(lc);
1110 
1111  /* ignore rels that are already in "rel" */
1112  if (bms_overlap(rel->relids, rel2->relids))
1113  continue;
1114 
1115  if (have_relevant_joinclause(root, rel, rel2))
1116  {
1117  Relids joinrelids;
1118  SpecialJoinInfo *sjinfo;
1119  bool reversed;
1120 
1121  /* join_is_legal needs relids of the union */
1122  joinrelids = bms_union(rel->relids, rel2->relids);
1123 
1124  if (join_is_legal(root, rel, rel2, joinrelids,
1125  &sjinfo, &reversed))
1126  {
1127  /* Yes, this will work */
1128  bms_free(joinrelids);
1129  return true;
1130  }
1131 
1132  bms_free(joinrelids);
1133  }
1134  }
1135 
1136  return false;
1137 }
static bool join_is_legal(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2, Relids joinrelids, SpecialJoinInfo **sjinfo_p, bool *reversed_p)
Definition: joinrels.c:342
Relids relids
Definition: relation.h:585
void bms_free(Bitmapset *a)
Definition: bitmapset.c:201
#define lfirst(lc)
Definition: pg_list.h:106
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:218
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:443
bool have_relevant_joinclause(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
Definition: joininfo.c:36
List * initial_rels
Definition: relation.h:272

◆ have_dangerous_phv()

bool have_dangerous_phv ( PlannerInfo root,
Relids  outer_relids,
Relids  inner_params 
)

Definition at line 1167 of file joinrels.c.

References bms_is_subset(), bms_overlap(), lfirst, PlaceHolderInfo::ph_eval_at, and PlannerInfo::placeholder_list.

Referenced by join_is_legal(), and try_nestloop_path().

1169 {
1170  ListCell *lc;
1171 
1172  foreach(lc, root->placeholder_list)
1173  {
1174  PlaceHolderInfo *phinfo = (PlaceHolderInfo *) lfirst(lc);
1175 
1176  if (!bms_is_subset(phinfo->ph_eval_at, inner_params))
1177  continue; /* ignore, could not be a nestloop param */
1178  if (!bms_overlap(phinfo->ph_eval_at, outer_relids))
1179  continue; /* ignore, not relevant to this join */
1180  if (bms_is_subset(phinfo->ph_eval_at, outer_relids))
1181  continue; /* safe, it can be eval'd within outerrel */
1182  /* Otherwise, it's potentially unsafe, so reject the join */
1183  return true;
1184  }
1185 
1186  /* OK to perform the join */
1187  return false;
1188 }
Relids ph_eval_at
Definition: relation.h:2154
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:308
#define lfirst(lc)
Definition: pg_list.h:106
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:443
List * placeholder_list
Definition: relation.h:258

◆ have_join_order_restriction()

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

Definition at line 934 of file joinrels.c.

References bms_is_subset(), bms_overlap(), RelOptInfo::direct_lateral_relids, has_legal_joinclause(), JOIN_FULL, PlannerInfo::join_info_list, SpecialJoinInfo::jointype, lfirst, SpecialJoinInfo::min_lefthand, SpecialJoinInfo::min_righthand, PlaceHolderInfo::ph_eval_at, PlannerInfo::placeholder_list, and RelOptInfo::relids.

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

936 {
937  bool result = false;
938  ListCell *l;
939 
940  /*
941  * If either side has a direct lateral reference to the other, attempt the
942  * join regardless of outer-join considerations.
943  */
944  if (bms_overlap(rel1->relids, rel2->direct_lateral_relids) ||
946  return true;
947 
948  /*
949  * Likewise, if both rels are needed to compute some PlaceHolderVar,
950  * attempt the join regardless of outer-join considerations. (This is not
951  * very desirable, because a PHV with a large eval_at set will cause a lot
952  * of probably-useless joins to be considered, but failing to do this can
953  * cause us to fail to construct a plan at all.)
954  */
955  foreach(l, root->placeholder_list)
956  {
957  PlaceHolderInfo *phinfo = (PlaceHolderInfo *) lfirst(l);
958 
959  if (bms_is_subset(rel1->relids, phinfo->ph_eval_at) &&
960  bms_is_subset(rel2->relids, phinfo->ph_eval_at))
961  return true;
962  }
963 
964  /*
965  * It's possible that the rels correspond to the left and right sides of a
966  * degenerate outer join, that is, one with no joinclause mentioning the
967  * non-nullable side; in which case we should force the join to occur.
968  *
969  * Also, the two rels could represent a clauseless join that has to be
970  * completed to build up the LHS or RHS of an outer join.
971  */
972  foreach(l, root->join_info_list)
973  {
974  SpecialJoinInfo *sjinfo = (SpecialJoinInfo *) lfirst(l);
975 
976  /* ignore full joins --- other mechanisms handle them */
977  if (sjinfo->jointype == JOIN_FULL)
978  continue;
979 
980  /* Can we perform the SJ with these rels? */
981  if (bms_is_subset(sjinfo->min_lefthand, rel1->relids) &&
982  bms_is_subset(sjinfo->min_righthand, rel2->relids))
983  {
984  result = true;
985  break;
986  }
987  if (bms_is_subset(sjinfo->min_lefthand, rel2->relids) &&
988  bms_is_subset(sjinfo->min_righthand, rel1->relids))
989  {
990  result = true;
991  break;
992  }
993 
994  /*
995  * Might we need to join these rels to complete the RHS? We have to
996  * use "overlap" tests since either rel might include a lower SJ that
997  * has been proven to commute with this one.
998  */
999  if (bms_overlap(sjinfo->min_righthand, rel1->relids) &&
1000  bms_overlap(sjinfo->min_righthand, rel2->relids))
1001  {
1002  result = true;
1003  break;
1004  }
1005 
1006  /* Likewise for the LHS. */
1007  if (bms_overlap(sjinfo->min_lefthand, rel1->relids) &&
1008  bms_overlap(sjinfo->min_lefthand, rel2->relids))
1009  {
1010  result = true;
1011  break;
1012  }
1013  }
1014 
1015  /*
1016  * We do not force the join to occur if either input rel can legally be
1017  * joined to anything else using joinclauses. This essentially means that
1018  * clauseless bushy joins are put off as long as possible. The reason is
1019  * that when there is a join order restriction high up in the join tree
1020  * (that is, with many rels inside the LHS or RHS), we would otherwise
1021  * expend lots of effort considering very stupid join combinations within
1022  * its LHS or RHS.
1023  */
1024  if (result)
1025  {
1026  if (has_legal_joinclause(root, rel1) ||
1027  has_legal_joinclause(root, rel2))
1028  result = false;
1029  }
1030 
1031  return result;
1032 }
Relids ph_eval_at
Definition: relation.h:2154
List * join_info_list
Definition: relation.h:250
Relids min_righthand
Definition: relation.h:2008
static bool has_legal_joinclause(PlannerInfo *root, RelOptInfo *rel)
Definition: joinrels.c:1103
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:308
Relids relids
Definition: relation.h:585
Relids direct_lateral_relids
Definition: relation.h:609
#define lfirst(lc)
Definition: pg_list.h:106
JoinType jointype
Definition: relation.h:2011
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:443
List * placeholder_list
Definition: relation.h:258
Relids min_lefthand
Definition: relation.h:2007

◆ have_partkey_equi_join()

bool have_partkey_equi_join ( RelOptInfo rel1,
RelOptInfo rel2,
JoinType  jointype,
List restrictlist 
)

Definition at line 1431 of file joinrels.c.

References OpExpr::args, Assert, bms_is_subset(), RestrictInfo::can_join, RestrictInfo::clause, RestrictInfo::hashjoinoperator, is_opclause, IS_OUTER_JOIN, RestrictInfo::is_pushed_down, RestrictInfo::left_relids, lfirst_node, linitial, list_member_oid(), lsecond, match_expr_to_partition_keys(), RestrictInfo::mergeopfamilies, OidIsValid, op_in_opfamily(), op_strict(), OpExpr::opno, RelOptInfo::part_scheme, PARTITION_MAX_KEYS, PARTITION_STRATEGY_HASH, PartitionSchemeData::partnatts, PartitionSchemeData::partopfamily, RelOptInfo::relids, RestrictInfo::right_relids, and PartitionSchemeData::strategy.

Referenced by build_joinrel_partition_info().

1433 {
1434  PartitionScheme part_scheme = rel1->part_scheme;
1435  ListCell *lc;
1436  int cnt_pks;
1437  bool pk_has_clause[PARTITION_MAX_KEYS];
1438  bool strict_op;
1439 
1440  /*
1441  * This function should be called when the joining relations have same
1442  * partitioning scheme.
1443  */
1444  Assert(rel1->part_scheme == rel2->part_scheme);
1445  Assert(part_scheme);
1446 
1447  memset(pk_has_clause, 0, sizeof(pk_has_clause));
1448  foreach(lc, restrictlist)
1449  {
1450  RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc);
1451  OpExpr *opexpr;
1452  Expr *expr1;
1453  Expr *expr2;
1454  int ipk1;
1455  int ipk2;
1456 
1457  /* If processing an outer join, only use its own join clauses. */
1458  if (IS_OUTER_JOIN(jointype) && rinfo->is_pushed_down)
1459  continue;
1460 
1461  /* Skip clauses which can not be used for a join. */
1462  if (!rinfo->can_join)
1463  continue;
1464 
1465  /* Skip clauses which are not equality conditions. */
1466  if (!rinfo->mergeopfamilies && !OidIsValid(rinfo->hashjoinoperator))
1467  continue;
1468 
1469  opexpr = (OpExpr *) rinfo->clause;
1470  Assert(is_opclause(opexpr));
1471 
1472  /*
1473  * The equi-join between partition keys is strict if equi-join between
1474  * at least one partition key is using a strict operator. See
1475  * explanation about outer join reordering identity 3 in
1476  * optimizer/README
1477  */
1478  strict_op = op_strict(opexpr->opno);
1479 
1480  /* Match the operands to the relation. */
1481  if (bms_is_subset(rinfo->left_relids, rel1->relids) &&
1482  bms_is_subset(rinfo->right_relids, rel2->relids))
1483  {
1484  expr1 = linitial(opexpr->args);
1485  expr2 = lsecond(opexpr->args);
1486  }
1487  else if (bms_is_subset(rinfo->left_relids, rel2->relids) &&
1488  bms_is_subset(rinfo->right_relids, rel1->relids))
1489  {
1490  expr1 = lsecond(opexpr->args);
1491  expr2 = linitial(opexpr->args);
1492  }
1493  else
1494  continue;
1495 
1496  /*
1497  * Only clauses referencing the partition keys are useful for
1498  * partition-wise join.
1499  */
1500  ipk1 = match_expr_to_partition_keys(expr1, rel1, strict_op);
1501  if (ipk1 < 0)
1502  continue;
1503  ipk2 = match_expr_to_partition_keys(expr2, rel2, strict_op);
1504  if (ipk2 < 0)
1505  continue;
1506 
1507  /*
1508  * If the clause refers to keys at different ordinal positions, it can
1509  * not be used for partition-wise join.
1510  */
1511  if (ipk1 != ipk2)
1512  continue;
1513 
1514  /*
1515  * The clause allows partition-wise join if only it uses the same
1516  * operator family as that specified by the partition key.
1517  */
1519  {
1520  if (!op_in_opfamily(rinfo->hashjoinoperator,
1521  part_scheme->partopfamily[ipk1]))
1522  continue;
1523  }
1524  else if (!list_member_oid(rinfo->mergeopfamilies,
1525  part_scheme->partopfamily[ipk1]))
1526  continue;
1527 
1528  /* Mark the partition key as having an equi-join clause. */
1529  pk_has_clause[ipk1] = true;
1530  }
1531 
1532  /* Check whether every partition key has an equi-join condition. */
1533  for (cnt_pks = 0; cnt_pks < part_scheme->partnatts; cnt_pks++)
1534  {
1535  if (!pk_has_clause[cnt_pks])
1536  return false;
1537  }
1538 
1539  return true;
1540 }
bool op_in_opfamily(Oid opno, Oid opfamily)
Definition: lsyscache.c:63
bool op_strict(Oid opno)
Definition: lsyscache.c:1281
#define IS_OUTER_JOIN(jointype)
Definition: nodes.h:723
#define PARTITION_MAX_KEYS
Relids left_relids
Definition: relation.h:1862
#define OidIsValid(objectId)
Definition: c.h:576
List * mergeopfamilies
Definition: relation.h:1880
#define lsecond(l)
Definition: pg_list.h:116
#define linitial(l)
Definition: pg_list.h:111
#define is_opclause(clause)
Definition: clauses.h:20
bool can_join
Definition: relation.h:1841
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:308
#define lfirst_node(type, lc)
Definition: pg_list.h:109
static int match_expr_to_partition_keys(Expr *expr, RelOptInfo *rel, bool strict_op)
Definition: joinrels.c:1547
Relids relids
Definition: relation.h:585
Expr * clause
Definition: relation.h:1835
#define PARTITION_STRATEGY_HASH
Definition: parsenodes.h:787
bool is_pushed_down
Definition: relation.h:1837
Relids right_relids
Definition: relation.h:1863
bool list_member_oid(const List *list, Oid datum)
Definition: list.c:505
#define Assert(condition)
Definition: c.h:670
Oid hashjoinoperator
Definition: relation.h:1893
PartitionScheme part_scheme
Definition: relation.h:657
Oid opno
Definition: primnodes.h:496
List * args
Definition: primnodes.h:502

◆ is_dummy_rel()

static bool is_dummy_rel ( RelOptInfo rel)
static

Definition at line 1195 of file joinrels.c.

References IS_DUMMY_REL.

Referenced by make_join_rel(), mark_dummy_rel(), and populate_joinrel_with_paths().

1196 {
1197  return IS_DUMMY_REL(rel);
1198 }
#define IS_DUMMY_REL(r)
Definition: relation.h:1275

◆ join_is_legal()

static bool join_is_legal ( PlannerInfo root,
RelOptInfo rel1,
RelOptInfo rel2,
Relids  joinrelids,
SpecialJoinInfo **  sjinfo_p,
bool reversed_p 
)
static

Definition at line 342 of file joinrels.c.

References bms_add_members(), bms_copy(), bms_equal(), bms_is_subset(), bms_overlap(), RelOptInfo::cheapest_total_path, create_unique_path(), RelOptInfo::direct_lateral_relids, PlannerInfo::hasLateralRTEs, have_dangerous_phv(), JOIN_FULL, PlannerInfo::join_info_list, JOIN_LEFT, JOIN_SEMI, SpecialJoinInfo::jointype, RelOptInfo::lateral_relids, lfirst, SpecialJoinInfo::lhs_strict, min_join_parameterization(), SpecialJoinInfo::min_lefthand, SpecialJoinInfo::min_righthand, RelOptInfo::relids, and SpecialJoinInfo::syn_righthand.

Referenced by has_legal_joinclause(), and make_join_rel().

345 {
346  SpecialJoinInfo *match_sjinfo;
347  bool reversed;
348  bool unique_ified;
349  bool must_be_leftjoin;
350  ListCell *l;
351 
352  /*
353  * Ensure output params are set on failure return. This is just to
354  * suppress uninitialized-variable warnings from overly anal compilers.
355  */
356  *sjinfo_p = NULL;
357  *reversed_p = false;
358 
359  /*
360  * If we have any special joins, the proposed join might be illegal; and
361  * in any case we have to determine its join type. Scan the join info
362  * list for matches and conflicts.
363  */
364  match_sjinfo = NULL;
365  reversed = false;
366  unique_ified = false;
367  must_be_leftjoin = false;
368 
369  foreach(l, root->join_info_list)
370  {
371  SpecialJoinInfo *sjinfo = (SpecialJoinInfo *) lfirst(l);
372 
373  /*
374  * This special join is not relevant unless its RHS overlaps the
375  * proposed join. (Check this first as a fast path for dismissing
376  * most irrelevant SJs quickly.)
377  */
378  if (!bms_overlap(sjinfo->min_righthand, joinrelids))
379  continue;
380 
381  /*
382  * Also, not relevant if proposed join is fully contained within RHS
383  * (ie, we're still building up the RHS).
384  */
385  if (bms_is_subset(joinrelids, sjinfo->min_righthand))
386  continue;
387 
388  /*
389  * Also, not relevant if SJ is already done within either input.
390  */
391  if (bms_is_subset(sjinfo->min_lefthand, rel1->relids) &&
392  bms_is_subset(sjinfo->min_righthand, rel1->relids))
393  continue;
394  if (bms_is_subset(sjinfo->min_lefthand, rel2->relids) &&
395  bms_is_subset(sjinfo->min_righthand, rel2->relids))
396  continue;
397 
398  /*
399  * If it's a semijoin and we already joined the RHS to any other rels
400  * within either input, then we must have unique-ified the RHS at that
401  * point (see below). Therefore the semijoin is no longer relevant in
402  * this join path.
403  */
404  if (sjinfo->jointype == JOIN_SEMI)
405  {
406  if (bms_is_subset(sjinfo->syn_righthand, rel1->relids) &&
407  !bms_equal(sjinfo->syn_righthand, rel1->relids))
408  continue;
409  if (bms_is_subset(sjinfo->syn_righthand, rel2->relids) &&
410  !bms_equal(sjinfo->syn_righthand, rel2->relids))
411  continue;
412  }
413 
414  /*
415  * If one input contains min_lefthand and the other contains
416  * min_righthand, then we can perform the SJ at this join.
417  *
418  * Reject if we get matches to more than one SJ; that implies we're
419  * considering something that's not really valid.
420  */
421  if (bms_is_subset(sjinfo->min_lefthand, rel1->relids) &&
422  bms_is_subset(sjinfo->min_righthand, rel2->relids))
423  {
424  if (match_sjinfo)
425  return false; /* invalid join path */
426  match_sjinfo = sjinfo;
427  reversed = false;
428  }
429  else if (bms_is_subset(sjinfo->min_lefthand, rel2->relids) &&
430  bms_is_subset(sjinfo->min_righthand, rel1->relids))
431  {
432  if (match_sjinfo)
433  return false; /* invalid join path */
434  match_sjinfo = sjinfo;
435  reversed = true;
436  }
437  else if (sjinfo->jointype == JOIN_SEMI &&
438  bms_equal(sjinfo->syn_righthand, rel2->relids) &&
439  create_unique_path(root, rel2, rel2->cheapest_total_path,
440  sjinfo) != NULL)
441  {
442  /*----------
443  * For a semijoin, we can join the RHS to anything else by
444  * unique-ifying the RHS (if the RHS can be unique-ified).
445  * We will only get here if we have the full RHS but less
446  * than min_lefthand on the LHS.
447  *
448  * The reason to consider such a join path is exemplified by
449  * SELECT ... FROM a,b WHERE (a.x,b.y) IN (SELECT c1,c2 FROM c)
450  * If we insist on doing this as a semijoin we will first have
451  * to form the cartesian product of A*B. But if we unique-ify
452  * C then the semijoin becomes a plain innerjoin and we can join
453  * in any order, eg C to A and then to B. When C is much smaller
454  * than A and B this can be a huge win. So we allow C to be
455  * joined to just A or just B here, and then make_join_rel has
456  * to handle the case properly.
457  *
458  * Note that actually we'll allow unique-ified C to be joined to
459  * some other relation D here, too. That is legal, if usually not
460  * very sane, and this routine is only concerned with legality not
461  * with whether the join is good strategy.
462  *----------
463  */
464  if (match_sjinfo)
465  return false; /* invalid join path */
466  match_sjinfo = sjinfo;
467  reversed = false;
468  unique_ified = true;
469  }
470  else if (sjinfo->jointype == JOIN_SEMI &&
471  bms_equal(sjinfo->syn_righthand, rel1->relids) &&
472  create_unique_path(root, rel1, rel1->cheapest_total_path,
473  sjinfo) != NULL)
474  {
475  /* Reversed semijoin case */
476  if (match_sjinfo)
477  return false; /* invalid join path */
478  match_sjinfo = sjinfo;
479  reversed = true;
480  unique_ified = true;
481  }
482  else
483  {
484  /*
485  * Otherwise, the proposed join overlaps the RHS but isn't a valid
486  * implementation of this SJ. But don't panic quite yet: the RHS
487  * violation might have occurred previously, in one or both input
488  * relations, in which case we must have previously decided that
489  * it was OK to commute some other SJ with this one. If we need
490  * to perform this join to finish building up the RHS, rejecting
491  * it could lead to not finding any plan at all. (This can occur
492  * because of the heuristics elsewhere in this file that postpone
493  * clauseless joins: we might not consider doing a clauseless join
494  * within the RHS until after we've performed other, validly
495  * commutable SJs with one or both sides of the clauseless join.)
496  * This consideration boils down to the rule that if both inputs
497  * overlap the RHS, we can allow the join --- they are either
498  * fully within the RHS, or represent previously-allowed joins to
499  * rels outside it.
500  */
501  if (bms_overlap(rel1->relids, sjinfo->min_righthand) &&
502  bms_overlap(rel2->relids, sjinfo->min_righthand))
503  continue; /* assume valid previous violation of RHS */
504 
505  /*
506  * The proposed join could still be legal, but only if we're
507  * allowed to associate it into the RHS of this SJ. That means
508  * this SJ must be a LEFT join (not SEMI or ANTI, and certainly
509  * not FULL) and the proposed join must not overlap the LHS.
510  */
511  if (sjinfo->jointype != JOIN_LEFT ||
512  bms_overlap(joinrelids, sjinfo->min_lefthand))
513  return false; /* invalid join path */
514 
515  /*
516  * To be valid, the proposed join must be a LEFT join; otherwise
517  * it can't associate into this SJ's RHS. But we may not yet have
518  * found the SpecialJoinInfo matching the proposed join, so we
519  * can't test that yet. Remember the requirement for later.
520  */
521  must_be_leftjoin = true;
522  }
523  }
524 
525  /*
526  * Fail if violated any SJ's RHS and didn't match to a LEFT SJ: the
527  * proposed join can't associate into an SJ's RHS.
528  *
529  * Also, fail if the proposed join's predicate isn't strict; we're
530  * essentially checking to see if we can apply outer-join identity 3, and
531  * that's a requirement. (This check may be redundant with checks in
532  * make_outerjoininfo, but I'm not quite sure, and it's cheap to test.)
533  */
534  if (must_be_leftjoin &&
535  (match_sjinfo == NULL ||
536  match_sjinfo->jointype != JOIN_LEFT ||
537  !match_sjinfo->lhs_strict))
538  return false; /* invalid join path */
539 
540  /*
541  * We also have to check for constraints imposed by LATERAL references.
542  */
543  if (root->hasLateralRTEs)
544  {
545  bool lateral_fwd;
546  bool lateral_rev;
547  Relids join_lateral_rels;
548 
549  /*
550  * The proposed rels could each contain lateral references to the
551  * other, in which case the join is impossible. If there are lateral
552  * references in just one direction, then the join has to be done with
553  * a nestloop with the lateral referencer on the inside. If the join
554  * matches an SJ that cannot be implemented by such a nestloop, the
555  * join is impossible.
556  *
557  * Also, if the lateral reference is only indirect, we should reject
558  * the join; whatever rel(s) the reference chain goes through must be
559  * joined to first.
560  *
561  * Another case that might keep us from building a valid plan is the
562  * implementation restriction described by have_dangerous_phv().
563  */
564  lateral_fwd = bms_overlap(rel1->relids, rel2->lateral_relids);
565  lateral_rev = bms_overlap(rel2->relids, rel1->lateral_relids);
566  if (lateral_fwd && lateral_rev)
567  return false; /* have lateral refs in both directions */
568  if (lateral_fwd)
569  {
570  /* has to be implemented as nestloop with rel1 on left */
571  if (match_sjinfo &&
572  (reversed ||
573  unique_ified ||
574  match_sjinfo->jointype == JOIN_FULL))
575  return false; /* not implementable as nestloop */
576  /* check there is a direct reference from rel2 to rel1 */
577  if (!bms_overlap(rel1->relids, rel2->direct_lateral_relids))
578  return false; /* only indirect refs, so reject */
579  /* check we won't have a dangerous PHV */
580  if (have_dangerous_phv(root, rel1->relids, rel2->lateral_relids))
581  return false; /* might be unable to handle required PHV */
582  }
583  else if (lateral_rev)
584  {
585  /* has to be implemented as nestloop with rel2 on left */
586  if (match_sjinfo &&
587  (!reversed ||
588  unique_ified ||
589  match_sjinfo->jointype == JOIN_FULL))
590  return false; /* not implementable as nestloop */
591  /* check there is a direct reference from rel1 to rel2 */
592  if (!bms_overlap(rel2->relids, rel1->direct_lateral_relids))
593  return false; /* only indirect refs, so reject */
594  /* check we won't have a dangerous PHV */
595  if (have_dangerous_phv(root, rel2->relids, rel1->lateral_relids))
596  return false; /* might be unable to handle required PHV */
597  }
598 
599  /*
600  * LATERAL references could also cause problems later on if we accept
601  * this join: if the join's minimum parameterization includes any rels
602  * that would have to be on the inside of an outer join with this join
603  * rel, then it's never going to be possible to build the complete
604  * query using this join. We should reject this join not only because
605  * it'll save work, but because if we don't, the clauseless-join
606  * heuristics might think that legality of this join means that some
607  * other join rel need not be formed, and that could lead to failure
608  * to find any plan at all. We have to consider not only rels that
609  * are directly on the inner side of an OJ with the joinrel, but also
610  * ones that are indirectly so, so search to find all such rels.
611  */
612  join_lateral_rels = min_join_parameterization(root, joinrelids,
613  rel1, rel2);
614  if (join_lateral_rels)
615  {
616  Relids join_plus_rhs = bms_copy(joinrelids);
617  bool more;
618 
619  do
620  {
621  more = false;
622  foreach(l, root->join_info_list)
623  {
624  SpecialJoinInfo *sjinfo = (SpecialJoinInfo *) lfirst(l);
625 
626  if (bms_overlap(sjinfo->min_lefthand, join_plus_rhs) &&
627  !bms_is_subset(sjinfo->min_righthand, join_plus_rhs))
628  {
629  join_plus_rhs = bms_add_members(join_plus_rhs,
630  sjinfo->min_righthand);
631  more = true;
632  }
633  /* full joins constrain both sides symmetrically */
634  if (sjinfo->jointype == JOIN_FULL &&
635  bms_overlap(sjinfo->min_righthand, join_plus_rhs) &&
636  !bms_is_subset(sjinfo->min_lefthand, join_plus_rhs))
637  {
638  join_plus_rhs = bms_add_members(join_plus_rhs,
639  sjinfo->min_lefthand);
640  more = true;
641  }
642  }
643  } while (more);
644  if (bms_overlap(join_plus_rhs, join_lateral_rels))
645  return false; /* will not be able to join to some RHS rel */
646  }
647  }
648 
649  /* Otherwise, it's a valid join */
650  *sjinfo_p = match_sjinfo;
651  *reversed_p = reversed;
652  return true;
653 }
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:111
List * join_info_list
Definition: relation.h:250
Relids min_righthand
Definition: relation.h:2008
UniquePath * create_unique_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, SpecialJoinInfo *sjinfo)
Definition: pathnode.c:1440
Relids syn_righthand
Definition: relation.h:2010
Relids lateral_relids
Definition: relation.h:610
bool hasLateralRTEs
Definition: relation.h:303
Relids min_join_parameterization(PlannerInfo *root, Relids joinrelids, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:807
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:308
struct Path * cheapest_total_path
Definition: relation.h:603
Relids relids
Definition: relation.h:585
Relids direct_lateral_relids
Definition: relation.h:609
#define lfirst(lc)
Definition: pg_list.h:106
JoinType jointype
Definition: relation.h:2011
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:443
Relids min_lefthand
Definition: relation.h:2007
Bitmapset * bms_add_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:755
bool have_dangerous_phv(PlannerInfo *root, Relids outer_relids, Relids inner_params)
Definition: joinrels.c:1167
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:131

◆ join_search_one_level()

void join_search_one_level ( PlannerInfo root,
int  level 
)

Definition at line 66 of file joinrels.c.

References Assert, bms_overlap(), elog, ERROR, for_each_cell, RelOptInfo::has_eclass_joins, has_join_restriction(), PlannerInfo::hasLateralRTEs, have_join_order_restriction(), have_relevant_joinclause(), PlannerInfo::join_cur_level, PlannerInfo::join_info_list, PlannerInfo::join_rel_level, RelOptInfo::joininfo, lfirst, list_head(), lnext, make_join_rel(), make_rels_by_clause_joins(), make_rels_by_clauseless_joins(), NIL, and RelOptInfo::relids.

Referenced by standard_join_search().

67 {
68  List **joinrels = root->join_rel_level;
69  ListCell *r;
70  int k;
71 
72  Assert(joinrels[level] == NIL);
73 
74  /* Set join_cur_level so that new joinrels are added to proper list */
75  root->join_cur_level = level;
76 
77  /*
78  * First, consider left-sided and right-sided plans, in which rels of
79  * exactly level-1 member relations are joined against initial relations.
80  * We prefer to join using join clauses, but if we find a rel of level-1
81  * members that has no join clauses, we will generate Cartesian-product
82  * joins against all initial rels not already contained in it.
83  */
84  foreach(r, joinrels[level - 1])
85  {
86  RelOptInfo *old_rel = (RelOptInfo *) lfirst(r);
87 
88  if (old_rel->joininfo != NIL || old_rel->has_eclass_joins ||
89  has_join_restriction(root, old_rel))
90  {
91  /*
92  * There are join clauses or join order restrictions relevant to
93  * this rel, so consider joins between this rel and (only) those
94  * initial rels it is linked to by a clause or restriction.
95  *
96  * At level 2 this condition is symmetric, so there is no need to
97  * look at initial rels before this one in the list; we already
98  * considered such joins when we were at the earlier rel. (The
99  * mirror-image joins are handled automatically by make_join_rel.)
100  * In later passes (level > 2), we join rels of the previous level
101  * to each initial rel they don't already include but have a join
102  * clause or restriction with.
103  */
104  ListCell *other_rels;
105 
106  if (level == 2) /* consider remaining initial rels */
107  other_rels = lnext(r);
108  else /* consider all initial rels */
109  other_rels = list_head(joinrels[1]);
110 
112  old_rel,
113  other_rels);
114  }
115  else
116  {
117  /*
118  * Oops, we have a relation that is not joined to any other
119  * relation, either directly or by join-order restrictions.
120  * Cartesian product time.
121  *
122  * We consider a cartesian product with each not-already-included
123  * initial rel, whether it has other join clauses or not. At
124  * level 2, if there are two or more clauseless initial rels, we
125  * will redundantly consider joining them in both directions; but
126  * such cases aren't common enough to justify adding complexity to
127  * avoid the duplicated effort.
128  */
130  old_rel,
131  list_head(joinrels[1]));
132  }
133  }
134 
135  /*
136  * Now, consider "bushy plans" in which relations of k initial rels are
137  * joined to relations of level-k initial rels, for 2 <= k <= level-2.
138  *
139  * We only consider bushy-plan joins for pairs of rels where there is a
140  * suitable join clause (or join order restriction), in order to avoid
141  * unreasonable growth of planning time.
142  */
143  for (k = 2;; k++)
144  {
145  int other_level = level - k;
146 
147  /*
148  * Since make_join_rel(x, y) handles both x,y and y,x cases, we only
149  * need to go as far as the halfway point.
150  */
151  if (k > other_level)
152  break;
153 
154  foreach(r, joinrels[k])
155  {
156  RelOptInfo *old_rel = (RelOptInfo *) lfirst(r);
157  ListCell *other_rels;
158  ListCell *r2;
159 
160  /*
161  * We can ignore relations without join clauses here, unless they
162  * participate in join-order restrictions --- then we might have
163  * to force a bushy join plan.
164  */
165  if (old_rel->joininfo == NIL && !old_rel->has_eclass_joins &&
166  !has_join_restriction(root, old_rel))
167  continue;
168 
169  if (k == other_level)
170  other_rels = lnext(r); /* only consider remaining rels */
171  else
172  other_rels = list_head(joinrels[other_level]);
173 
174  for_each_cell(r2, other_rels)
175  {
176  RelOptInfo *new_rel = (RelOptInfo *) lfirst(r2);
177 
178  if (!bms_overlap(old_rel->relids, new_rel->relids))
179  {
180  /*
181  * OK, we can build a rel of the right level from this
182  * pair of rels. Do so if there is at least one relevant
183  * join clause or join order restriction.
184  */
185  if (have_relevant_joinclause(root, old_rel, new_rel) ||
186  have_join_order_restriction(root, old_rel, new_rel))
187  {
188  (void) make_join_rel(root, old_rel, new_rel);
189  }
190  }
191  }
192  }
193  }
194 
195  /*----------
196  * Last-ditch effort: if we failed to find any usable joins so far, force
197  * a set of cartesian-product joins to be generated. This handles the
198  * special case where all the available rels have join clauses but we
199  * cannot use any of those clauses yet. This can only happen when we are
200  * considering a join sub-problem (a sub-joinlist) and all the rels in the
201  * sub-problem have only join clauses with rels outside the sub-problem.
202  * An example is
203  *
204  * SELECT ... FROM a INNER JOIN b ON TRUE, c, d, ...
205  * WHERE a.w = c.x and b.y = d.z;
206  *
207  * If the "a INNER JOIN b" sub-problem does not get flattened into the
208  * upper level, we must be willing to make a cartesian join of a and b;
209  * but the code above will not have done so, because it thought that both
210  * a and b have joinclauses. We consider only left-sided and right-sided
211  * cartesian joins in this case (no bushy).
212  *----------
213  */
214  if (joinrels[level] == NIL)
215  {
216  /*
217  * This loop is just like the first one, except we always call
218  * make_rels_by_clauseless_joins().
219  */
220  foreach(r, joinrels[level - 1])
221  {
222  RelOptInfo *old_rel = (RelOptInfo *) lfirst(r);
223 
225  old_rel,
226  list_head(joinrels[1]));
227  }
228 
229  /*----------
230  * When special joins are involved, there may be no legal way
231  * to make an N-way join for some values of N. For example consider
232  *
233  * SELECT ... FROM t1 WHERE
234  * x IN (SELECT ... FROM t2,t3 WHERE ...) AND
235  * y IN (SELECT ... FROM t4,t5 WHERE ...)
236  *
237  * We will flatten this query to a 5-way join problem, but there are
238  * no 4-way joins that join_is_legal() will consider legal. We have
239  * to accept failure at level 4 and go on to discover a workable
240  * bushy plan at level 5.
241  *
242  * However, if there are no special joins and no lateral references
243  * then join_is_legal() should never fail, and so the following sanity
244  * check is useful.
245  *----------
246  */
247  if (joinrels[level] == NIL &&
248  root->join_info_list == NIL &&
249  !root->hasLateralRTEs)
250  elog(ERROR, "failed to build any %d-way joins", level);
251  }
252 }
bool has_eclass_joins
Definition: relation.h:651
#define NIL
Definition: pg_list.h:69
int join_cur_level
Definition: relation.h:226
List * join_info_list
Definition: relation.h:250
static void make_rels_by_clauseless_joins(PlannerInfo *root, RelOptInfo *old_rel, ListCell *other_rels)
Definition: joinrels.c:309
bool have_join_order_restriction(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
Definition: joinrels.c:934
static void make_rels_by_clause_joins(PlannerInfo *root, RelOptInfo *old_rel, ListCell *other_rels)
Definition: joinrels.c:275
#define ERROR
Definition: elog.h:43
static bool has_join_restriction(PlannerInfo *root, RelOptInfo *rel)
Definition: joinrels.c:1047
bool hasLateralRTEs
Definition: relation.h:303
List * joininfo
Definition: relation.h:649
static ListCell * list_head(const List *l)
Definition: pg_list.h:77
Relids relids
Definition: relation.h:585
#define lnext(lc)
Definition: pg_list.h:105
RelOptInfo * make_join_rel(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
Definition: joinrels.c:669
#define Assert(condition)
Definition: c.h:670
#define lfirst(lc)
Definition: pg_list.h:106
List ** join_rel_level
Definition: relation.h:225
#define for_each_cell(cell, initcell)
Definition: pg_list.h:169
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:443
bool have_relevant_joinclause(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
Definition: joininfo.c:36
#define elog
Definition: elog.h:219
Definition: pg_list.h:45

◆ make_join_rel()

RelOptInfo* make_join_rel ( PlannerInfo root,
RelOptInfo rel1,
RelOptInfo rel2 
)

Definition at line 669 of file joinrels.c.

References Assert, bms_free(), bms_overlap(), bms_union(), build_join_rel(), SpecialJoinInfo::delay_upper_joins, is_dummy_rel(), JOIN_INNER, join_is_legal(), SpecialJoinInfo::jointype, SpecialJoinInfo::lhs_strict, SpecialJoinInfo::min_lefthand, SpecialJoinInfo::min_righthand, NIL, populate_joinrel_with_paths(), RelOptInfo::relids, SpecialJoinInfo::semi_can_btree, SpecialJoinInfo::semi_can_hash, SpecialJoinInfo::semi_operators, SpecialJoinInfo::semi_rhs_exprs, SpecialJoinInfo::syn_lefthand, SpecialJoinInfo::syn_righthand, T_SpecialJoinInfo, and SpecialJoinInfo::type.

Referenced by join_search_one_level(), make_rels_by_clause_joins(), make_rels_by_clauseless_joins(), and merge_clump().

670 {
671  Relids joinrelids;
672  SpecialJoinInfo *sjinfo;
673  bool reversed;
674  SpecialJoinInfo sjinfo_data;
675  RelOptInfo *joinrel;
676  List *restrictlist;
677 
678  /* We should never try to join two overlapping sets of rels. */
679  Assert(!bms_overlap(rel1->relids, rel2->relids));
680 
681  /* Construct Relids set that identifies the joinrel. */
682  joinrelids = bms_union(rel1->relids, rel2->relids);
683 
684  /* Check validity and determine join type. */
685  if (!join_is_legal(root, rel1, rel2, joinrelids,
686  &sjinfo, &reversed))
687  {
688  /* invalid join path */
689  bms_free(joinrelids);
690  return NULL;
691  }
692 
693  /* Swap rels if needed to match the join info. */
694  if (reversed)
695  {
696  RelOptInfo *trel = rel1;
697 
698  rel1 = rel2;
699  rel2 = trel;
700  }
701 
702  /*
703  * If it's a plain inner join, then we won't have found anything in
704  * join_info_list. Make up a SpecialJoinInfo so that selectivity
705  * estimation functions will know what's being joined.
706  */
707  if (sjinfo == NULL)
708  {
709  sjinfo = &sjinfo_data;
710  sjinfo->type = T_SpecialJoinInfo;
711  sjinfo->min_lefthand = rel1->relids;
712  sjinfo->min_righthand = rel2->relids;
713  sjinfo->syn_lefthand = rel1->relids;
714  sjinfo->syn_righthand = rel2->relids;
715  sjinfo->jointype = JOIN_INNER;
716  /* we don't bother trying to make the remaining fields valid */
717  sjinfo->lhs_strict = false;
718  sjinfo->delay_upper_joins = false;
719  sjinfo->semi_can_btree = false;
720  sjinfo->semi_can_hash = false;
721  sjinfo->semi_operators = NIL;
722  sjinfo->semi_rhs_exprs = NIL;
723  }
724 
725  /*
726  * Find or build the join RelOptInfo, and compute the restrictlist that
727  * goes with this particular joining.
728  */
729  joinrel = build_join_rel(root, joinrelids, rel1, rel2, sjinfo,
730  &restrictlist);
731 
732  /*
733  * If we've already proven this join is empty, we needn't consider any
734  * more paths for it.
735  */
736  if (is_dummy_rel(joinrel))
737  {
738  bms_free(joinrelids);
739  return joinrel;
740  }
741 
742  /* Add paths to the join relation. */
743  populate_joinrel_with_paths(root, rel1, rel2, joinrel, sjinfo,
744  restrictlist);
745 
746  bms_free(joinrelids);
747 
748  return joinrel;
749 }
#define NIL
Definition: pg_list.h:69
static bool is_dummy_rel(RelOptInfo *rel)
Definition: joinrels.c:1195
bool semi_can_btree
Definition: relation.h:2015
static void populate_joinrel_with_paths(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2, RelOptInfo *joinrel, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: joinrels.c:759
Relids min_righthand
Definition: relation.h:2008
NodeTag type
Definition: relation.h:2006
Relids syn_lefthand
Definition: relation.h:2009
Relids syn_righthand
Definition: relation.h:2010
List * semi_rhs_exprs
Definition: relation.h:2018
bool semi_can_hash
Definition: relation.h:2016
static bool join_is_legal(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2, Relids joinrelids, SpecialJoinInfo **sjinfo_p, bool *reversed_p)
Definition: joinrels.c:342
Relids relids
Definition: relation.h:585
bool delay_upper_joins
Definition: relation.h:2013
RelOptInfo * build_join_rel(PlannerInfo *root, Relids joinrelids, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List **restrictlist_ptr)
Definition: relnode.c:480
void bms_free(Bitmapset *a)
Definition: bitmapset.c:201
#define Assert(condition)
Definition: c.h:670
JoinType jointype
Definition: relation.h:2011
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:218
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:443
List * semi_operators
Definition: relation.h:2017
Definition: pg_list.h:45
Relids min_lefthand
Definition: relation.h:2007

◆ make_rels_by_clause_joins()

static void make_rels_by_clause_joins ( PlannerInfo root,
RelOptInfo old_rel,
ListCell other_rels 
)
static

Definition at line 275 of file joinrels.c.

References bms_overlap(), for_each_cell, have_join_order_restriction(), have_relevant_joinclause(), lfirst, make_join_rel(), and RelOptInfo::relids.

Referenced by join_search_one_level().

278 {
279  ListCell *l;
280 
281  for_each_cell(l, other_rels)
282  {
283  RelOptInfo *other_rel = (RelOptInfo *) lfirst(l);
284 
285  if (!bms_overlap(old_rel->relids, other_rel->relids) &&
286  (have_relevant_joinclause(root, old_rel, other_rel) ||
287  have_join_order_restriction(root, old_rel, other_rel)))
288  {
289  (void) make_join_rel(root, old_rel, other_rel);
290  }
291  }
292 }
bool have_join_order_restriction(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
Definition: joinrels.c:934
Relids relids
Definition: relation.h:585
RelOptInfo * make_join_rel(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
Definition: joinrels.c:669
#define lfirst(lc)
Definition: pg_list.h:106
#define for_each_cell(cell, initcell)
Definition: pg_list.h:169
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:443
bool have_relevant_joinclause(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
Definition: joininfo.c:36

◆ make_rels_by_clauseless_joins()

static void make_rels_by_clauseless_joins ( PlannerInfo root,
RelOptInfo old_rel,
ListCell other_rels 
)
static

Definition at line 309 of file joinrels.c.

References bms_overlap(), for_each_cell, lfirst, make_join_rel(), and RelOptInfo::relids.

Referenced by join_search_one_level().

312 {
313  ListCell *l;
314 
315  for_each_cell(l, other_rels)
316  {
317  RelOptInfo *other_rel = (RelOptInfo *) lfirst(l);
318 
319  if (!bms_overlap(other_rel->relids, old_rel->relids))
320  {
321  (void) make_join_rel(root, old_rel, other_rel);
322  }
323  }
324 }
Relids relids
Definition: relation.h:585
RelOptInfo * make_join_rel(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
Definition: joinrels.c:669
#define lfirst(lc)
Definition: pg_list.h:106
#define for_each_cell(cell, initcell)
Definition: pg_list.h:169
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:443

◆ mark_dummy_rel()

void mark_dummy_rel ( RelOptInfo rel)

Definition at line 1216 of file joinrels.c.

References add_path(), create_append_path(), GetMemoryChunkContext(), is_dummy_rel(), MemoryContextSwitchTo(), NIL, RelOptInfo::partial_pathlist, RelOptInfo::pathlist, RelOptInfo::rows, and set_cheapest().

Referenced by generate_partition_wise_join_paths(), and populate_joinrel_with_paths().

1217 {
1218  MemoryContext oldcontext;
1219 
1220  /* Already marked? */
1221  if (is_dummy_rel(rel))
1222  return;
1223 
1224  /* No, so choose correct context to make the dummy path in */
1225  oldcontext = MemoryContextSwitchTo(GetMemoryChunkContext(rel));
1226 
1227  /* Set dummy size estimate */
1228  rel->rows = 0;
1229 
1230  /* Evict any previously chosen paths */
1231  rel->pathlist = NIL;
1232  rel->partial_pathlist = NIL;
1233 
1234  /* Set up the dummy path */
1235  add_path(rel, (Path *) create_append_path(rel, NIL, NULL, 0, NIL));
1236 
1237  /* Set or update cheapest_total_path and related fields */
1238  set_cheapest(rel);
1239 
1240  MemoryContextSwitchTo(oldcontext);
1241 }
#define NIL
Definition: pg_list.h:69
static bool is_dummy_rel(RelOptInfo *rel)
Definition: joinrels.c:1195
void add_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:420
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
List * partial_pathlist
Definition: relation.h:601
AppendPath * create_append_path(RelOptInfo *rel, List *subpaths, Relids required_outer, int parallel_workers, List *partitioned_rels)
Definition: pathnode.c:1211
void set_cheapest(RelOptInfo *parent_rel)
Definition: pathnode.c:242
double rows
Definition: relation.h:588
List * pathlist
Definition: relation.h:599
static MemoryContext GetMemoryChunkContext(void *pointer)
Definition: memutils.h:107

◆ match_expr_to_partition_keys()

static int match_expr_to_partition_keys ( Expr expr,
RelOptInfo rel,
bool  strict_op 
)
static

Definition at line 1547 of file joinrels.c.

References arg, Assert, castNode, equal(), IsA, lfirst, RelOptInfo::nullable_partexprs, RelOptInfo::part_scheme, RelOptInfo::partexprs, and PartitionSchemeData::partnatts.

Referenced by have_partkey_equi_join().

1548 {
1549  int cnt;
1550 
1551  /* This function should be called only for partitioned relations. */
1552  Assert(rel->part_scheme);
1553 
1554  /* Remove any relabel decorations. */
1555  while (IsA(expr, RelabelType))
1556  expr = (Expr *) (castNode(RelabelType, expr))->arg;
1557 
1558  for (cnt = 0; cnt < rel->part_scheme->partnatts; cnt++)
1559  {
1560  ListCell *lc;
1561 
1562  Assert(rel->partexprs);
1563  foreach(lc, rel->partexprs[cnt])
1564  {
1565  if (equal(lfirst(lc), expr))
1566  return cnt;
1567  }
1568 
1569  if (!strict_op)
1570  continue;
1571 
1572  /*
1573  * If it's a strict equi-join a NULL partition key on one side will
1574  * not join a NULL partition key on the other side. So, rows with NULL
1575  * partition key from a partition on one side can not join with those
1576  * from a non-matching partition on the other side. So, search the
1577  * nullable partition keys as well.
1578  */
1579  Assert(rel->nullable_partexprs);
1580  foreach(lc, rel->nullable_partexprs[cnt])
1581  {
1582  if (equal(lfirst(lc), expr))
1583  return cnt;
1584  }
1585  }
1586 
1587  return -1;
1588 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:561
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:2974
#define castNode(_type_, nodeptr)
Definition: nodes.h:579
List ** nullable_partexprs
Definition: relation.h:663
List ** partexprs
Definition: relation.h:662
#define Assert(condition)
Definition: c.h:670
#define lfirst(lc)
Definition: pg_list.h:106
void * arg
PartitionScheme part_scheme
Definition: relation.h:657

◆ populate_joinrel_with_paths()

static void populate_joinrel_with_paths ( PlannerInfo root,
RelOptInfo rel1,
RelOptInfo rel2,
RelOptInfo joinrel,
SpecialJoinInfo sjinfo,
List restrictlist 
)
static

Definition at line 759 of file joinrels.c.

References add_paths_to_joinrel(), bms_equal(), bms_is_subset(), RelOptInfo::cheapest_total_path, create_unique_path(), elog, ereport, errcode(), errmsg(), ERROR, is_dummy_rel(), JOIN_ANTI, JOIN_FULL, JOIN_INNER, JOIN_LEFT, JOIN_RIGHT, JOIN_SEMI, JOIN_UNIQUE_INNER, JOIN_UNIQUE_OUTER, SpecialJoinInfo::jointype, mark_dummy_rel(), SpecialJoinInfo::min_lefthand, SpecialJoinInfo::min_righthand, NIL, RelOptInfo::pathlist, RelOptInfo::relids, restriction_is_constant_false(), SpecialJoinInfo::syn_righthand, and try_partition_wise_join().

Referenced by make_join_rel(), and try_partition_wise_join().

762 {
763  /*
764  * Consider paths using each rel as both outer and inner. Depending on
765  * the join type, a provably empty outer or inner rel might mean the join
766  * is provably empty too; in which case throw away any previously computed
767  * paths and mark the join as dummy. (We do it this way since it's
768  * conceivable that dummy-ness of a multi-element join might only be
769  * noticeable for certain construction paths.)
770  *
771  * Also, a provably constant-false join restriction typically means that
772  * we can skip evaluating one or both sides of the join. We do this by
773  * marking the appropriate rel as dummy. For outer joins, a
774  * constant-false restriction that is pushed down still means the whole
775  * join is dummy, while a non-pushed-down one means that no inner rows
776  * will join so we can treat the inner rel as dummy.
777  *
778  * We need only consider the jointypes that appear in join_info_list, plus
779  * JOIN_INNER.
780  */
781  switch (sjinfo->jointype)
782  {
783  case JOIN_INNER:
784  if (is_dummy_rel(rel1) || is_dummy_rel(rel2) ||
785  restriction_is_constant_false(restrictlist, false))
786  {
787  mark_dummy_rel(joinrel);
788  break;
789  }
790  add_paths_to_joinrel(root, joinrel, rel1, rel2,
791  JOIN_INNER, sjinfo,
792  restrictlist);
793  add_paths_to_joinrel(root, joinrel, rel2, rel1,
794  JOIN_INNER, sjinfo,
795  restrictlist);
796  break;
797  case JOIN_LEFT:
798  if (is_dummy_rel(rel1) ||
799  restriction_is_constant_false(restrictlist, true))
800  {
801  mark_dummy_rel(joinrel);
802  break;
803  }
804  if (restriction_is_constant_false(restrictlist, false) &&
805  bms_is_subset(rel2->relids, sjinfo->syn_righthand))
806  mark_dummy_rel(rel2);
807  add_paths_to_joinrel(root, joinrel, rel1, rel2,
808  JOIN_LEFT, sjinfo,
809  restrictlist);
810  add_paths_to_joinrel(root, joinrel, rel2, rel1,
811  JOIN_RIGHT, sjinfo,
812  restrictlist);
813  break;
814  case JOIN_FULL:
815  if ((is_dummy_rel(rel1) && is_dummy_rel(rel2)) ||
816  restriction_is_constant_false(restrictlist, true))
817  {
818  mark_dummy_rel(joinrel);
819  break;
820  }
821  add_paths_to_joinrel(root, joinrel, rel1, rel2,
822  JOIN_FULL, sjinfo,
823  restrictlist);
824  add_paths_to_joinrel(root, joinrel, rel2, rel1,
825  JOIN_FULL, sjinfo,
826  restrictlist);
827 
828  /*
829  * If there are join quals that aren't mergeable or hashable, we
830  * may not be able to build any valid plan. Complain here so that
831  * we can give a somewhat-useful error message. (Since we have no
832  * flexibility of planning for a full join, there's no chance of
833  * succeeding later with another pair of input rels.)
834  */
835  if (joinrel->pathlist == NIL)
836  ereport(ERROR,
837  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
838  errmsg("FULL JOIN is only supported with merge-joinable or hash-joinable join conditions")));
839  break;
840  case JOIN_SEMI:
841 
842  /*
843  * We might have a normal semijoin, or a case where we don't have
844  * enough rels to do the semijoin but can unique-ify the RHS and
845  * then do an innerjoin (see comments in join_is_legal). In the
846  * latter case we can't apply JOIN_SEMI joining.
847  */
848  if (bms_is_subset(sjinfo->min_lefthand, rel1->relids) &&
849  bms_is_subset(sjinfo->min_righthand, rel2->relids))
850  {
851  if (is_dummy_rel(rel1) || is_dummy_rel(rel2) ||
852  restriction_is_constant_false(restrictlist, false))
853  {
854  mark_dummy_rel(joinrel);
855  break;
856  }
857  add_paths_to_joinrel(root, joinrel, rel1, rel2,
858  JOIN_SEMI, sjinfo,
859  restrictlist);
860  }
861 
862  /*
863  * If we know how to unique-ify the RHS and one input rel is
864  * exactly the RHS (not a superset) we can consider unique-ifying
865  * it and then doing a regular join. (The create_unique_path
866  * check here is probably redundant with what join_is_legal did,
867  * but if so the check is cheap because it's cached. So test
868  * anyway to be sure.)
869  */
870  if (bms_equal(sjinfo->syn_righthand, rel2->relids) &&
871  create_unique_path(root, rel2, rel2->cheapest_total_path,
872  sjinfo) != NULL)
873  {
874  if (is_dummy_rel(rel1) || is_dummy_rel(rel2) ||
875  restriction_is_constant_false(restrictlist, false))
876  {
877  mark_dummy_rel(joinrel);
878  break;
879  }
880  add_paths_to_joinrel(root, joinrel, rel1, rel2,
881  JOIN_UNIQUE_INNER, sjinfo,
882  restrictlist);
883  add_paths_to_joinrel(root, joinrel, rel2, rel1,
884  JOIN_UNIQUE_OUTER, sjinfo,
885  restrictlist);
886  }
887  break;
888  case JOIN_ANTI:
889  if (is_dummy_rel(rel1) ||
890  restriction_is_constant_false(restrictlist, true))
891  {
892  mark_dummy_rel(joinrel);
893  break;
894  }
895  if (restriction_is_constant_false(restrictlist, false) &&
896  bms_is_subset(rel2->relids, sjinfo->syn_righthand))
897  mark_dummy_rel(rel2);
898  add_paths_to_joinrel(root, joinrel, rel1, rel2,
899  JOIN_ANTI, sjinfo,
900  restrictlist);
901  break;
902  default:
903  /* other values not expected here */
904  elog(ERROR, "unrecognized join type: %d", (int) sjinfo->jointype);
905  break;
906  }
907 
908  /* Apply partition-wise join technique, if possible. */
909  try_partition_wise_join(root, rel1, rel2, joinrel, sjinfo, restrictlist);
910 }
#define NIL
Definition: pg_list.h:69
static bool is_dummy_rel(RelOptInfo *rel)
Definition: joinrels.c:1195
static bool restriction_is_constant_false(List *restrictlist, bool only_pushed_down)
Definition: joinrels.c:1256
Relids min_righthand
Definition: relation.h:2008
int errcode(int sqlerrcode)
Definition: elog.c:575
UniquePath * create_unique_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, SpecialJoinInfo *sjinfo)
Definition: pathnode.c:1440
Relids syn_righthand
Definition: relation.h:2010
#define ERROR
Definition: elog.h:43
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:308
struct Path * cheapest_total_path
Definition: relation.h:603
static void try_partition_wise_join(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2, RelOptInfo *joinrel, SpecialJoinInfo *parent_sjinfo, List *parent_restrictlist)
Definition: joinrels.c:1308
Relids relids
Definition: relation.h:585
#define ereport(elevel, rest)
Definition: elog.h:122
void mark_dummy_rel(RelOptInfo *rel)
Definition: joinrels.c:1216
JoinType jointype
Definition: relation.h:2011
int errmsg(const char *fmt,...)
Definition: elog.c:797
void add_paths_to_joinrel(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: joinpath.c:117
List * pathlist
Definition: relation.h:599
#define elog
Definition: elog.h:219
Relids min_lefthand
Definition: relation.h:2007
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:131

◆ restriction_is_constant_false()

static bool restriction_is_constant_false ( List restrictlist,
bool  only_pushed_down 
)
static

Definition at line 1256 of file joinrels.c.

References RestrictInfo::clause, Const::constisnull, Const::constvalue, DatumGetBool, RestrictInfo::is_pushed_down, IsA, and lfirst_node.

Referenced by populate_joinrel_with_paths().

1257 {
1258  ListCell *lc;
1259 
1260  /*
1261  * Despite the above comment, the restriction list we see here might
1262  * possibly have other members besides the FALSE constant, since other
1263  * quals could get "pushed down" to the outer join level. So we check
1264  * each member of the list.
1265  */
1266  foreach(lc, restrictlist)
1267  {
1268  RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc);
1269 
1270  if (only_pushed_down && !rinfo->is_pushed_down)
1271  continue;
1272 
1273  if (rinfo->clause && IsA(rinfo->clause, Const))
1274  {
1275  Const *con = (Const *) rinfo->clause;
1276 
1277  /* constant NULL is as good as constant FALSE for our purposes */
1278  if (con->constisnull)
1279  return true;
1280  if (!DatumGetBool(con->constvalue))
1281  return true;
1282  }
1283  }
1284  return false;
1285 }
Datum constvalue
Definition: primnodes.h:196
#define IsA(nodeptr, _type_)
Definition: nodes.h:561
#define lfirst_node(type, lc)
Definition: pg_list.h:109
#define DatumGetBool(X)
Definition: postgres.h:399
Expr * clause
Definition: relation.h:1835
bool is_pushed_down
Definition: relation.h:1837
bool constisnull
Definition: primnodes.h:197

◆ try_partition_wise_join()

static void try_partition_wise_join ( PlannerInfo root,
RelOptInfo rel1,
RelOptInfo rel2,
RelOptInfo joinrel,
SpecialJoinInfo parent_sjinfo,
List parent_restrictlist 
)
static

Definition at line 1308 of file joinrels.c.

References adjust_appendrel_attrs(), Assert, bms_equal(), bms_overlap(), bms_union(), RelOptInfo::boundinfo, build_child_join_rel(), build_child_join_sjinfo(), check_stack_depth(), find_appinfos_by_relids(), IS_DUMMY_REL, IS_PARTITIONED_REL, SpecialJoinInfo::jointype, RelOptInfo::nparts, palloc0(), RelOptInfo::part_rels, RelOptInfo::part_scheme, partition_bounds_equal(), PartitionSchemeData::partnatts, PartitionSchemeData::parttypbyval, PartitionSchemeData::parttyplen, pfree(), populate_joinrel_with_paths(), REL_HAS_ALL_PART_PROPS, and RelOptInfo::relids.

Referenced by populate_joinrel_with_paths().

1311 {
1312  int nparts;
1313  int cnt_parts;
1314 
1315  /* Guard against stack overflow due to overly deep partition hierarchy. */
1317 
1318  /* Nothing to do, if the join relation is not partitioned. */
1319  if (!IS_PARTITIONED_REL(joinrel))
1320  return;
1321 
1322  /*
1323  * set_rel_pathlist() may not create paths in children of an empty
1324  * partitioned table and so we can not add paths to child-joins. So, deem
1325  * such a join as unpartitioned. When a partitioned relation is deemed
1326  * empty because all its children are empty, dummy path will be set in
1327  * each of the children. In such a case we could still consider the join
1328  * as partitioned, but it might not help much.
1329  */
1330  if (IS_DUMMY_REL(rel1) || IS_DUMMY_REL(rel2))
1331  return;
1332 
1333  /*
1334  * Since this join relation is partitioned, all the base relations
1335  * participating in this join must be partitioned and so are all the
1336  * intermediate join relations.
1337  */
1340 
1341  /*
1342  * The partition scheme of the join relation should match that of the
1343  * joining relations.
1344  */
1345  Assert(joinrel->part_scheme == rel1->part_scheme &&
1346  joinrel->part_scheme == rel2->part_scheme);
1347 
1348  /*
1349  * Since we allow partition-wise join only when the partition bounds of
1350  * the joining relations exactly match, the partition bounds of the join
1351  * should match those of the joining relations.
1352  */
1354  joinrel->part_scheme->parttyplen,
1355  joinrel->part_scheme->parttypbyval,
1356  joinrel->boundinfo, rel1->boundinfo));
1358  joinrel->part_scheme->parttyplen,
1359  joinrel->part_scheme->parttypbyval,
1360  joinrel->boundinfo, rel2->boundinfo));
1361 
1362  nparts = joinrel->nparts;
1363 
1364  /* Allocate space to hold child-joins RelOptInfos, if not already done. */
1365  if (!joinrel->part_rels)
1366  joinrel->part_rels =
1367  (RelOptInfo **) palloc0(sizeof(RelOptInfo *) * nparts);
1368 
1369  /*
1370  * Create child-join relations for this partitioned join, if those don't
1371  * exist. Add paths to child-joins for a pair of child relations
1372  * corresponding to the given pair of parent relations.
1373  */
1374  for (cnt_parts = 0; cnt_parts < nparts; cnt_parts++)
1375  {
1376  RelOptInfo *child_rel1 = rel1->part_rels[cnt_parts];
1377  RelOptInfo *child_rel2 = rel2->part_rels[cnt_parts];
1378  SpecialJoinInfo *child_sjinfo;
1379  List *child_restrictlist;
1380  RelOptInfo *child_joinrel;
1381  Relids child_joinrelids;
1382  AppendRelInfo **appinfos;
1383  int nappinfos;
1384 
1385  /* We should never try to join two overlapping sets of rels. */
1386  Assert(!bms_overlap(child_rel1->relids, child_rel2->relids));
1387  child_joinrelids = bms_union(child_rel1->relids, child_rel2->relids);
1388  appinfos = find_appinfos_by_relids(root, child_joinrelids, &nappinfos);
1389 
1390  /*
1391  * Construct SpecialJoinInfo from parent join relations's
1392  * SpecialJoinInfo.
1393  */
1394  child_sjinfo = build_child_join_sjinfo(root, parent_sjinfo,
1395  child_rel1->relids,
1396  child_rel2->relids);
1397 
1398  /*
1399  * Construct restrictions applicable to the child join from those
1400  * applicable to the parent join.
1401  */
1402  child_restrictlist =
1403  (List *) adjust_appendrel_attrs(root,
1404  (Node *) parent_restrictlist,
1405  nappinfos, appinfos);
1406  pfree(appinfos);
1407 
1408  child_joinrel = joinrel->part_rels[cnt_parts];
1409  if (!child_joinrel)
1410  {
1411  child_joinrel = build_child_join_rel(root, child_rel1, child_rel2,
1412  joinrel, child_restrictlist,
1413  child_sjinfo,
1414  child_sjinfo->jointype);
1415  joinrel->part_rels[cnt_parts] = child_joinrel;
1416  }
1417 
1418  Assert(bms_equal(child_joinrel->relids, child_joinrelids));
1419 
1420  populate_joinrel_with_paths(root, child_rel1, child_rel2,
1421  child_joinrel, child_sjinfo,
1422  child_restrictlist);
1423  }
1424 }
SpecialJoinInfo * build_child_join_sjinfo(PlannerInfo *root, SpecialJoinInfo *parent_sjinfo, Relids left_relids, Relids right_relids)
Definition: prepunion.c:2472
static void populate_joinrel_with_paths(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2, RelOptInfo *joinrel, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: joinrels.c:759
#define IS_PARTITIONED_REL(rel)
Definition: relation.h:674
Definition: nodes.h:510
bool partition_bounds_equal(int partnatts, int16 *parttyplen, bool *parttypbyval, PartitionBoundInfo b1, PartitionBoundInfo b2)
Definition: partition.c:734
void pfree(void *pointer)
Definition: mcxt.c:949
#define IS_DUMMY_REL(r)
Definition: relation.h:1275
RelOptInfo * build_child_join_rel(PlannerInfo *root, RelOptInfo *outer_rel, RelOptInfo *inner_rel, RelOptInfo *parent_joinrel, List *restrictlist, SpecialJoinInfo *sjinfo, JoinType jointype)
Definition: relnode.c:682
int16 * parttyplen
Definition: relation.h:355
void check_stack_depth(void)
Definition: postgres.c:3150
int nparts
Definition: relation.h:658
#define REL_HAS_ALL_PART_PROPS(rel)
Definition: relation.h:681
Relids relids
Definition: relation.h:585
Node * adjust_appendrel_attrs(PlannerInfo *root, Node *node, int nappinfos, AppendRelInfo **appinfos)
Definition: prepunion.c:1945
void * palloc0(Size size)
Definition: mcxt.c:877
struct PartitionBoundInfoData * boundinfo
Definition: relation.h:659
AppendRelInfo ** find_appinfos_by_relids(PlannerInfo *root, Relids relids, int *nappinfos)
Definition: prepunion.c:2516
#define Assert(condition)
Definition: c.h:670
JoinType jointype
Definition: relation.h:2011
struct RelOptInfo ** part_rels
Definition: relation.h:660
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:218
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:443
PartitionScheme part_scheme
Definition: relation.h:657
Definition: pg_list.h:45
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:131