PostgreSQL Source Code  git master
joinpath.c File Reference
#include "postgres.h"
#include <math.h>
#include "executor/executor.h"
#include "foreign/fdwapi.h"
#include "optimizer/cost.h"
#include "optimizer/pathnode.h"
#include "optimizer/paths.h"
#include "optimizer/planmain.h"
Include dependency graph for joinpath.c:

Go to the source code of this file.

Macros

#define PATH_PARAM_BY_PARENT(path, rel)
 
#define PATH_PARAM_BY_REL_SELF(path, rel)   ((path)->param_info && bms_overlap(PATH_REQ_OUTER(path), (rel)->relids))
 
#define PATH_PARAM_BY_REL(path, rel)   (PATH_PARAM_BY_REL_SELF(path, rel) || PATH_PARAM_BY_PARENT(path, rel))
 

Functions

static void try_partial_mergejoin_path (PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, List *pathkeys, List *mergeclauses, List *outersortkeys, List *innersortkeys, JoinType jointype, JoinPathExtraData *extra)
 
static void sort_inner_and_outer (PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, JoinPathExtraData *extra)
 
static void match_unsorted_outer (PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, JoinPathExtraData *extra)
 
static void consider_parallel_nestloop (PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, JoinPathExtraData *extra)
 
static void consider_parallel_mergejoin (PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, JoinPathExtraData *extra, Path *inner_cheapest_total)
 
static void hash_inner_and_outer (PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, JoinPathExtraData *extra)
 
static Listselect_mergejoin_clauses (PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, List *restrictlist, JoinType jointype, bool *mergejoin_allowed)
 
static void generate_mergejoin_paths (PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *innerrel, Path *outerpath, JoinType jointype, JoinPathExtraData *extra, bool useallclauses, Path *inner_cheapest_total, List *merge_pathkeys, bool is_partial)
 
void add_paths_to_joinrel (PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, SpecialJoinInfo *sjinfo, List *restrictlist)
 
static bool allow_star_schema_join (PlannerInfo *root, Relids outerrelids, Relids inner_paramrels)
 
static void try_nestloop_path (PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, List *pathkeys, JoinType jointype, JoinPathExtraData *extra)
 
static void try_partial_nestloop_path (PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, List *pathkeys, JoinType jointype, JoinPathExtraData *extra)
 
static void try_mergejoin_path (PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, List *pathkeys, List *mergeclauses, List *outersortkeys, List *innersortkeys, JoinType jointype, JoinPathExtraData *extra, bool is_partial)
 
static void try_hashjoin_path (PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, List *hashclauses, JoinType jointype, JoinPathExtraData *extra)
 
static void try_partial_hashjoin_path (PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, List *hashclauses, JoinType jointype, JoinPathExtraData *extra, bool parallel_hash)
 
static bool clause_sides_match_join (RestrictInfo *rinfo, RelOptInfo *outerrel, RelOptInfo *innerrel)
 

Variables

set_join_pathlist_hook_type set_join_pathlist_hook = NULL
 

Macro Definition Documentation

◆ PATH_PARAM_BY_PARENT

#define PATH_PARAM_BY_PARENT (   path,
  rel 
)
Value:
((path)->param_info && bms_overlap(PATH_REQ_OUTER(path), \
(rel)->top_parent_relids))
#define PATH_REQ_OUTER(path)
Definition: relation.h:1061
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:487

Definition at line 33 of file joinpath.c.

Referenced by try_nestloop_path(), and try_partial_nestloop_path().

◆ PATH_PARAM_BY_REL

#define PATH_PARAM_BY_REL (   path,
  rel 
)    (PATH_PARAM_BY_REL_SELF(path, rel) || PATH_PARAM_BY_PARENT(path, rel))

Definition at line 39 of file joinpath.c.

Referenced by hash_inner_and_outer(), match_unsorted_outer(), and sort_inner_and_outer().

◆ PATH_PARAM_BY_REL_SELF

#define PATH_PARAM_BY_REL_SELF (   path,
  rel 
)    ((path)->param_info && bms_overlap(PATH_REQ_OUTER(path), (rel)->relids))

Definition at line 36 of file joinpath.c.

Function Documentation

◆ add_paths_to_joinrel()

void add_paths_to_joinrel ( PlannerInfo root,
RelOptInfo joinrel,
RelOptInfo outerrel,
RelOptInfo innerrel,
JoinType  jointype,
SpecialJoinInfo sjinfo,
List restrictlist 
)

Definition at line 117 of file joinpath.c.

References PlannerInfo::all_baserels, bms_add_members(), bms_difference(), bms_is_subset(), bms_join(), bms_overlap(), compute_semi_anti_join_factors(), enable_hashjoin, enable_mergejoin, RelOptInfo::fdwroutine, FdwRoutine::GetForeignJoinPaths, hash_inner_and_outer(), JoinPathExtraData::inner_unique, innerrel_is_unique(), JOIN_ANTI, JOIN_FULL, PlannerInfo::join_info_list, JOIN_INNER, JOIN_SEMI, JOIN_UNIQUE_INNER, JOIN_UNIQUE_OUTER, SpecialJoinInfo::jointype, RelOptInfo::lateral_relids, lfirst, match_unsorted_outer(), JoinPathExtraData::mergeclause_list, SpecialJoinInfo::min_lefthand, SpecialJoinInfo::min_righthand, NIL, JoinPathExtraData::param_source_rels, RelOptInfo::relids, RELOPT_OTHER_JOINREL, RelOptInfo::reloptkind, JoinPathExtraData::restrictlist, select_mergejoin_clauses(), JoinPathExtraData::semifactors, set_join_pathlist_hook, JoinPathExtraData::sjinfo, sort_inner_and_outer(), and RelOptInfo::top_parent_relids.

Referenced by populate_joinrel_with_paths().

124 {
125  JoinPathExtraData extra;
126  bool mergejoin_allowed = true;
127  ListCell *lc;
128  Relids joinrelids;
129 
130  /*
131  * PlannerInfo doesn't contain the SpecialJoinInfos created for joins
132  * between child relations, even if there is a SpecialJoinInfo node for
133  * the join between the topmost parents. So, while calculating Relids set
134  * representing the restriction, consider relids of topmost parent of
135  * partitions.
136  */
137  if (joinrel->reloptkind == RELOPT_OTHER_JOINREL)
138  joinrelids = joinrel->top_parent_relids;
139  else
140  joinrelids = joinrel->relids;
141 
142  extra.restrictlist = restrictlist;
143  extra.mergeclause_list = NIL;
144  extra.sjinfo = sjinfo;
145  extra.param_source_rels = NULL;
146 
147  /*
148  * See if the inner relation is provably unique for this outer rel.
149  *
150  * We have some special cases: for JOIN_SEMI and JOIN_ANTI, it doesn't
151  * matter since the executor can make the equivalent optimization anyway;
152  * we need not expend planner cycles on proofs. For JOIN_UNIQUE_INNER, we
153  * must be considering a semijoin whose inner side is not provably unique
154  * (else reduce_unique_semijoins would've simplified it), so there's no
155  * point in calling innerrel_is_unique. However, if the LHS covers all of
156  * the semijoin's min_lefthand, then it's appropriate to set inner_unique
157  * because the path produced by create_unique_path will be unique relative
158  * to the LHS. (If we have an LHS that's only part of the min_lefthand,
159  * that is *not* true.) For JOIN_UNIQUE_OUTER, pass JOIN_INNER to avoid
160  * letting that value escape this module.
161  */
162  switch (jointype)
163  {
164  case JOIN_SEMI:
165  case JOIN_ANTI:
166  extra.inner_unique = false; /* well, unproven */
167  break;
168  case JOIN_UNIQUE_INNER:
169  extra.inner_unique = bms_is_subset(sjinfo->min_lefthand,
170  outerrel->relids);
171  break;
172  case JOIN_UNIQUE_OUTER:
173  extra.inner_unique = innerrel_is_unique(root,
174  outerrel->relids,
175  innerrel,
176  JOIN_INNER,
177  restrictlist,
178  false);
179  break;
180  default:
181  extra.inner_unique = innerrel_is_unique(root,
182  outerrel->relids,
183  innerrel,
184  jointype,
185  restrictlist,
186  false);
187  break;
188  }
189 
190  /*
191  * Find potential mergejoin clauses. We can skip this if we are not
192  * interested in doing a mergejoin. However, mergejoin may be our only
193  * way of implementing a full outer join, so override enable_mergejoin if
194  * it's a full join.
195  */
196  if (enable_mergejoin || jointype == JOIN_FULL)
198  joinrel,
199  outerrel,
200  innerrel,
201  restrictlist,
202  jointype,
203  &mergejoin_allowed);
204 
205  /*
206  * If it's SEMI, ANTI, or inner_unique join, compute correction factors
207  * for cost estimation. These will be the same for all paths.
208  */
209  if (jointype == JOIN_SEMI || jointype == JOIN_ANTI || extra.inner_unique)
210  compute_semi_anti_join_factors(root, outerrel, innerrel,
211  jointype, sjinfo, restrictlist,
212  &extra.semifactors);
213 
214  /*
215  * Decide whether it's sensible to generate parameterized paths for this
216  * joinrel, and if so, which relations such paths should require. There
217  * is usually no need to create a parameterized result path unless there
218  * is a join order restriction that prevents joining one of our input rels
219  * directly to the parameter source rel instead of joining to the other
220  * input rel. (But see allow_star_schema_join().) This restriction
221  * reduces the number of parameterized paths we have to deal with at
222  * higher join levels, without compromising the quality of the resulting
223  * plan. We express the restriction as a Relids set that must overlap the
224  * parameterization of any proposed join path.
225  */
226  foreach(lc, root->join_info_list)
227  {
228  SpecialJoinInfo *sjinfo2 = (SpecialJoinInfo *) lfirst(lc);
229 
230  /*
231  * SJ is relevant to this join if we have some part of its RHS
232  * (possibly not all of it), and haven't yet joined to its LHS. (This
233  * test is pretty simplistic, but should be sufficient considering the
234  * join has already been proven legal.) If the SJ is relevant, it
235  * presents constraints for joining to anything not in its RHS.
236  */
237  if (bms_overlap(joinrelids, sjinfo2->min_righthand) &&
238  !bms_overlap(joinrelids, sjinfo2->min_lefthand))
241  sjinfo2->min_righthand));
242 
243  /* full joins constrain both sides symmetrically */
244  if (sjinfo2->jointype == JOIN_FULL &&
245  bms_overlap(joinrelids, sjinfo2->min_lefthand) &&
246  !bms_overlap(joinrelids, sjinfo2->min_righthand))
249  sjinfo2->min_lefthand));
250  }
251 
252  /*
253  * However, when a LATERAL subquery is involved, there will simply not be
254  * any paths for the joinrel that aren't parameterized by whatever the
255  * subquery is parameterized by, unless its parameterization is resolved
256  * within the joinrel. So we might as well allow additional dependencies
257  * on whatever residual lateral dependencies the joinrel will have.
258  */
260  joinrel->lateral_relids);
261 
262  /*
263  * 1. Consider mergejoin paths where both relations must be explicitly
264  * sorted. Skip this if we can't mergejoin.
265  */
266  if (mergejoin_allowed)
267  sort_inner_and_outer(root, joinrel, outerrel, innerrel,
268  jointype, &extra);
269 
270  /*
271  * 2. Consider paths where the outer relation need not be explicitly
272  * sorted. This includes both nestloops and mergejoins where the outer
273  * path is already ordered. Again, skip this if we can't mergejoin.
274  * (That's okay because we know that nestloop can't handle right/full
275  * joins at all, so it wouldn't work in the prohibited cases either.)
276  */
277  if (mergejoin_allowed)
278  match_unsorted_outer(root, joinrel, outerrel, innerrel,
279  jointype, &extra);
280 
281 #ifdef NOT_USED
282 
283  /*
284  * 3. Consider paths where the inner relation need not be explicitly
285  * sorted. This includes mergejoins only (nestloops were already built in
286  * match_unsorted_outer).
287  *
288  * Diked out as redundant 2/13/2000 -- tgl. There isn't any really
289  * significant difference between the inner and outer side of a mergejoin,
290  * so match_unsorted_inner creates no paths that aren't equivalent to
291  * those made by match_unsorted_outer when add_paths_to_joinrel() is
292  * invoked with the two rels given in the other order.
293  */
294  if (mergejoin_allowed)
295  match_unsorted_inner(root, joinrel, outerrel, innerrel,
296  jointype, &extra);
297 #endif
298 
299  /*
300  * 4. Consider paths where both outer and inner relations must be hashed
301  * before being joined. As above, disregard enable_hashjoin for full
302  * joins, because there may be no other alternative.
303  */
304  if (enable_hashjoin || jointype == JOIN_FULL)
305  hash_inner_and_outer(root, joinrel, outerrel, innerrel,
306  jointype, &extra);
307 
308  /*
309  * 5. If inner and outer relations are foreign tables (or joins) belonging
310  * to the same server and assigned to the same user to check access
311  * permissions as, give the FDW a chance to push down joins.
312  */
313  if (joinrel->fdwroutine &&
315  joinrel->fdwroutine->GetForeignJoinPaths(root, joinrel,
316  outerrel, innerrel,
317  jointype, &extra);
318 
319  /*
320  * 6. Finally, give extensions a chance to manipulate the path list.
321  */
323  set_join_pathlist_hook(root, joinrel, outerrel, innerrel,
324  jointype, &extra);
325 }
#define NIL
Definition: pg_list.h:69
SemiAntiJoinFactors semifactors
Definition: relation.h:2284
RelOptKind reloptkind
Definition: relation.h:582
List * join_info_list
Definition: relation.h:250
Relids min_righthand
Definition: relation.h:2016
Bitmapset * bms_difference(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:328
static void hash_inner_and_outer(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, JoinPathExtraData *extra)
Definition: joinpath.c:1677
Relids lateral_relids
Definition: relation.h:610
SpecialJoinInfo * sjinfo
Definition: relation.h:2283
static void sort_inner_and_outer(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, JoinPathExtraData *extra)
Definition: joinpath.c:879
Relids all_baserels
Definition: relation.h:196
GetForeignJoinPaths_function GetForeignJoinPaths
Definition: fdwapi.h:194
Relids param_source_rels
Definition: relation.h:2285
Bitmapset * bms_join(Bitmapset *a, Bitmapset *b)
Definition: bitmapset.c:954
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:352
struct FdwRoutine * fdwroutine
Definition: relation.h:636
List * mergeclause_list
Definition: relation.h:2281
Relids relids
Definition: relation.h:585
bool innerrel_is_unique(PlannerInfo *root, Relids outerrelids, RelOptInfo *innerrel, JoinType jointype, List *restrictlist, bool force_cache)
Definition: analyzejoins.c:970
static List * select_mergejoin_clauses(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, List *restrictlist, JoinType jointype, bool *mergejoin_allowed)
Definition: joinpath.c:1929
List * restrictlist
Definition: relation.h:2280
set_join_pathlist_hook_type set_join_pathlist_hook
Definition: joinpath.c:27
bool enable_mergejoin
Definition: costsize.c:127
#define lfirst(lc)
Definition: pg_list.h:106
void compute_semi_anti_join_factors(PlannerInfo *root, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, SpecialJoinInfo *sjinfo, List *restrictlist, SemiAntiJoinFactors *semifactors)
Definition: costsize.c:4021
JoinType jointype
Definition: relation.h:2019
bool enable_hashjoin
Definition: costsize.c:128
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:487
Relids min_lefthand
Definition: relation.h:2015
Bitmapset * bms_add_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:799
Relids top_parent_relids
Definition: relation.h:654
static void match_unsorted_outer(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, JoinPathExtraData *extra)
Definition: joinpath.c:1331

◆ allow_star_schema_join()

static bool allow_star_schema_join ( PlannerInfo root,
Relids  outerrelids,
Relids  inner_paramrels 
)
inlinestatic

Definition at line 343 of file joinpath.c.

References bms_nonempty_difference(), and bms_overlap().

Referenced by try_nestloop_path().

346 {
347  /*
348  * It's a star-schema case if the outer rel provides some but not all of
349  * the inner rel's parameterization.
350  */
351  return (bms_overlap(inner_paramrels, outerrelids) &&
352  bms_nonempty_difference(inner_paramrels, outerrelids));
353 }
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:487
bool bms_nonempty_difference(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:538

◆ clause_sides_match_join()

static bool clause_sides_match_join ( RestrictInfo rinfo,
RelOptInfo outerrel,
RelOptInfo innerrel 
)
inlinestatic

Definition at line 847 of file joinpath.c.

References bms_is_subset(), RestrictInfo::left_relids, RestrictInfo::outer_is_left, RelOptInfo::relids, and RestrictInfo::right_relids.

Referenced by hash_inner_and_outer(), and select_mergejoin_clauses().

849 {
850  if (bms_is_subset(rinfo->left_relids, outerrel->relids) &&
851  bms_is_subset(rinfo->right_relids, innerrel->relids))
852  {
853  /* lefthand side is outer */
854  rinfo->outer_is_left = true;
855  return true;
856  }
857  else if (bms_is_subset(rinfo->left_relids, innerrel->relids) &&
858  bms_is_subset(rinfo->right_relids, outerrel->relids))
859  {
860  /* righthand side is outer */
861  rinfo->outer_is_left = false;
862  return true;
863  }
864  return false; /* no good for these input relations */
865 }
Relids left_relids
Definition: relation.h:1870
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:352
bool outer_is_left
Definition: relation.h:1898
Relids relids
Definition: relation.h:585
Relids right_relids
Definition: relation.h:1871

◆ consider_parallel_mergejoin()

static void consider_parallel_mergejoin ( PlannerInfo root,
RelOptInfo joinrel,
RelOptInfo outerrel,
RelOptInfo innerrel,
JoinType  jointype,
JoinPathExtraData extra,
Path inner_cheapest_total 
)
static

Definition at line 1565 of file joinpath.c.

References build_join_pathkeys(), generate_mergejoin_paths(), lfirst, RelOptInfo::partial_pathlist, and Path::pathkeys.

Referenced by match_unsorted_outer().

1572 {
1573  ListCell *lc1;
1574 
1575  /* generate merge join path for each partial outer path */
1576  foreach(lc1, outerrel->partial_pathlist)
1577  {
1578  Path *outerpath = (Path *) lfirst(lc1);
1579  List *merge_pathkeys;
1580 
1581  /*
1582  * Figure out what useful ordering any paths we create will have.
1583  */
1584  merge_pathkeys = build_join_pathkeys(root, joinrel, jointype,
1585  outerpath->pathkeys);
1586 
1587  generate_mergejoin_paths(root, joinrel, innerrel, outerpath, jointype,
1588  extra, false, inner_cheapest_total,
1589  merge_pathkeys, true);
1590  }
1591 }
List * partial_pathlist
Definition: relation.h:601
List * build_join_pathkeys(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, List *outer_pathkeys)
Definition: pathkeys.c:822
static void generate_mergejoin_paths(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *innerrel, Path *outerpath, JoinType jointype, JoinPathExtraData *extra, bool useallclauses, Path *inner_cheapest_total, List *merge_pathkeys, bool is_partial)
Definition: joinpath.c:1081
List * pathkeys
Definition: relation.h:1056
#define lfirst(lc)
Definition: pg_list.h:106
Definition: pg_list.h:45

◆ consider_parallel_nestloop()

static void consider_parallel_nestloop ( PlannerInfo root,
RelOptInfo joinrel,
RelOptInfo outerrel,
RelOptInfo innerrel,
JoinType  jointype,
JoinPathExtraData extra 
)
static

Definition at line 1605 of file joinpath.c.

References Assert, build_join_pathkeys(), RelOptInfo::cheapest_parameterized_paths, RelOptInfo::cheapest_total_path, create_unique_path(), JOIN_INNER, JOIN_UNIQUE_INNER, lfirst, Path::parallel_safe, RelOptInfo::partial_pathlist, Path::pathkeys, JoinPathExtraData::sjinfo, and try_partial_nestloop_path().

Referenced by match_unsorted_outer().

1611 {
1612  JoinType save_jointype = jointype;
1613  ListCell *lc1;
1614 
1615  if (jointype == JOIN_UNIQUE_INNER)
1616  jointype = JOIN_INNER;
1617 
1618  foreach(lc1, outerrel->partial_pathlist)
1619  {
1620  Path *outerpath = (Path *) lfirst(lc1);
1621  List *pathkeys;
1622  ListCell *lc2;
1623 
1624  /* Figure out what useful ordering any paths we create will have. */
1625  pathkeys = build_join_pathkeys(root, joinrel, jointype,
1626  outerpath->pathkeys);
1627 
1628  /*
1629  * Try the cheapest parameterized paths; only those which will produce
1630  * an unparameterized path when joined to this outerrel will survive
1631  * try_partial_nestloop_path. The cheapest unparameterized path is
1632  * also in this list.
1633  */
1634  foreach(lc2, innerrel->cheapest_parameterized_paths)
1635  {
1636  Path *innerpath = (Path *) lfirst(lc2);
1637 
1638  /* Can't join to an inner path that is not parallel-safe */
1639  if (!innerpath->parallel_safe)
1640  continue;
1641 
1642  /*
1643  * If we're doing JOIN_UNIQUE_INNER, we can only use the inner's
1644  * cheapest_total_path, and we have to unique-ify it. (We might
1645  * be able to relax this to allow other safe, unparameterized
1646  * inner paths, but right now create_unique_path is not on board
1647  * with that.)
1648  */
1649  if (save_jointype == JOIN_UNIQUE_INNER)
1650  {
1651  if (innerpath != innerrel->cheapest_total_path)
1652  continue;
1653  innerpath = (Path *) create_unique_path(root, innerrel,
1654  innerpath,
1655  extra->sjinfo);
1656  Assert(innerpath);
1657  }
1658 
1659  try_partial_nestloop_path(root, joinrel, outerpath, innerpath,
1660  pathkeys, jointype, extra);
1661  }
1662  }
1663 }
List * partial_pathlist
Definition: relation.h:601
List * cheapest_parameterized_paths
Definition: relation.h:605
UniquePath * create_unique_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, SpecialJoinInfo *sjinfo)
Definition: pathnode.c:1498
List * build_join_pathkeys(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, List *outer_pathkeys)
Definition: pathkeys.c:822
JoinType
Definition: nodes.h:676
SpecialJoinInfo * sjinfo
Definition: relation.h:2283
struct Path * cheapest_total_path
Definition: relation.h:603
static void try_partial_nestloop_path(PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, List *pathkeys, JoinType jointype, JoinPathExtraData *extra)
Definition: joinpath.c:473
List * pathkeys
Definition: relation.h:1056
#define Assert(condition)
Definition: c.h:680
#define lfirst(lc)
Definition: pg_list.h:106
bool parallel_safe
Definition: relation.h:1048
Definition: pg_list.h:45

◆ generate_mergejoin_paths()

static void generate_mergejoin_paths ( PlannerInfo root,
RelOptInfo joinrel,
RelOptInfo innerrel,
Path outerpath,
JoinType  jointype,
JoinPathExtraData extra,
bool  useallclauses,
Path inner_cheapest_total,
List merge_pathkeys,
bool  is_partial 
)
static

Definition at line 1081 of file joinpath.c.

References Assert, compare_path_costs(), find_mergeclauses_for_pathkeys(), get_cheapest_path_for_pathkeys(), JOIN_FULL, JOIN_INNER, JOIN_UNIQUE_INNER, JOIN_UNIQUE_OUTER, list_copy(), list_length(), list_truncate(), make_inner_pathkeys_for_merge(), JoinPathExtraData::mergeclause_list, NIL, Path::pathkeys, pathkeys_contained_in(), RelOptInfo::pathlist, STARTUP_COST, TOTAL_COST, and try_mergejoin_path().

Referenced by consider_parallel_mergejoin(), and match_unsorted_outer().

1091 {
1092  List *mergeclauses;
1093  List *innersortkeys;
1094  List *trialsortkeys;
1095  Path *cheapest_startup_inner;
1096  Path *cheapest_total_inner;
1097  JoinType save_jointype = jointype;
1098  int num_sortkeys;
1099  int sortkeycnt;
1100 
1101  if (jointype == JOIN_UNIQUE_OUTER || jointype == JOIN_UNIQUE_INNER)
1102  jointype = JOIN_INNER;
1103 
1104  /* Look for useful mergeclauses (if any) */
1105  mergeclauses = find_mergeclauses_for_pathkeys(root,
1106  outerpath->pathkeys,
1107  true,
1108  extra->mergeclause_list);
1109 
1110  /*
1111  * Done with this outer path if no chance for a mergejoin.
1112  *
1113  * Special corner case: for "x FULL JOIN y ON true", there will be no join
1114  * clauses at all. Ordinarily we'd generate a clauseless nestloop path,
1115  * but since mergejoin is our only join type that supports FULL JOIN
1116  * without any join clauses, it's necessary to generate a clauseless
1117  * mergejoin path instead.
1118  */
1119  if (mergeclauses == NIL)
1120  {
1121  if (jointype == JOIN_FULL)
1122  /* okay to try for mergejoin */ ;
1123  else
1124  return;
1125  }
1126  if (useallclauses &&
1127  list_length(mergeclauses) != list_length(extra->mergeclause_list))
1128  return;
1129 
1130  /* Compute the required ordering of the inner path */
1131  innersortkeys = make_inner_pathkeys_for_merge(root,
1132  mergeclauses,
1133  outerpath->pathkeys);
1134 
1135  /*
1136  * Generate a mergejoin on the basis of sorting the cheapest inner. Since
1137  * a sort will be needed, only cheapest total cost matters. (But
1138  * try_mergejoin_path will do the right thing if inner_cheapest_total is
1139  * already correctly sorted.)
1140  */
1141  try_mergejoin_path(root,
1142  joinrel,
1143  outerpath,
1144  inner_cheapest_total,
1145  merge_pathkeys,
1146  mergeclauses,
1147  NIL,
1148  innersortkeys,
1149  jointype,
1150  extra,
1151  is_partial);
1152 
1153  /* Can't do anything else if inner path needs to be unique'd */
1154  if (save_jointype == JOIN_UNIQUE_INNER)
1155  return;
1156 
1157  /*
1158  * Look for presorted inner paths that satisfy the innersortkey list ---
1159  * or any truncation thereof, if we are allowed to build a mergejoin using
1160  * a subset of the merge clauses. Here, we consider both cheap startup
1161  * cost and cheap total cost.
1162  *
1163  * Currently we do not consider parameterized inner paths here. This
1164  * interacts with decisions elsewhere that also discriminate against
1165  * mergejoins with parameterized inputs; see comments in
1166  * src/backend/optimizer/README.
1167  *
1168  * As we shorten the sortkey list, we should consider only paths that are
1169  * strictly cheaper than (in particular, not the same as) any path found
1170  * in an earlier iteration. Otherwise we'd be intentionally using fewer
1171  * merge keys than a given path allows (treating the rest as plain
1172  * joinquals), which is unlikely to be a good idea. Also, eliminating
1173  * paths here on the basis of compare_path_costs is a lot cheaper than
1174  * building the mergejoin path only to throw it away.
1175  *
1176  * If inner_cheapest_total is well enough sorted to have not required a
1177  * sort in the path made above, we shouldn't make a duplicate path with
1178  * it, either. We handle that case with the same logic that handles the
1179  * previous consideration, by initializing the variables that track
1180  * cheapest-so-far properly. Note that we do NOT reject
1181  * inner_cheapest_total if we find it matches some shorter set of
1182  * pathkeys. That case corresponds to using fewer mergekeys to avoid
1183  * sorting inner_cheapest_total, whereas we did sort it above, so the
1184  * plans being considered are different.
1185  */
1186  if (pathkeys_contained_in(innersortkeys,
1187  inner_cheapest_total->pathkeys))
1188  {
1189  /* inner_cheapest_total didn't require a sort */
1190  cheapest_startup_inner = inner_cheapest_total;
1191  cheapest_total_inner = inner_cheapest_total;
1192  }
1193  else
1194  {
1195  /* it did require a sort, at least for the full set of keys */
1196  cheapest_startup_inner = NULL;
1197  cheapest_total_inner = NULL;
1198  }
1199  num_sortkeys = list_length(innersortkeys);
1200  if (num_sortkeys > 1 && !useallclauses)
1201  trialsortkeys = list_copy(innersortkeys); /* need modifiable copy */
1202  else
1203  trialsortkeys = innersortkeys; /* won't really truncate */
1204 
1205  for (sortkeycnt = num_sortkeys; sortkeycnt > 0; sortkeycnt--)
1206  {
1207  Path *innerpath;
1208  List *newclauses = NIL;
1209 
1210  /*
1211  * Look for an inner path ordered well enough for the first
1212  * 'sortkeycnt' innersortkeys. NB: trialsortkeys list is modified
1213  * destructively, which is why we made a copy...
1214  */
1215  trialsortkeys = list_truncate(trialsortkeys, sortkeycnt);
1216  innerpath = get_cheapest_path_for_pathkeys(innerrel->pathlist,
1217  trialsortkeys,
1218  NULL,
1219  TOTAL_COST,
1220  is_partial);
1221  if (innerpath != NULL &&
1222  (cheapest_total_inner == NULL ||
1223  compare_path_costs(innerpath, cheapest_total_inner,
1224  TOTAL_COST) < 0))
1225  {
1226  /* Found a cheap (or even-cheaper) sorted path */
1227  /* Select the right mergeclauses, if we didn't already */
1228  if (sortkeycnt < num_sortkeys)
1229  {
1230  newclauses =
1232  trialsortkeys,
1233  false,
1234  mergeclauses);
1235  Assert(newclauses != NIL);
1236  }
1237  else
1238  newclauses = mergeclauses;
1239  try_mergejoin_path(root,
1240  joinrel,
1241  outerpath,
1242  innerpath,
1243  merge_pathkeys,
1244  newclauses,
1245  NIL,
1246  NIL,
1247  jointype,
1248  extra,
1249  is_partial);
1250  cheapest_total_inner = innerpath;
1251  }
1252  /* Same on the basis of cheapest startup cost ... */
1253  innerpath = get_cheapest_path_for_pathkeys(innerrel->pathlist,
1254  trialsortkeys,
1255  NULL,
1256  STARTUP_COST,
1257  is_partial);
1258  if (innerpath != NULL &&
1259  (cheapest_startup_inner == NULL ||
1260  compare_path_costs(innerpath, cheapest_startup_inner,
1261  STARTUP_COST) < 0))
1262  {
1263  /* Found a cheap (or even-cheaper) sorted path */
1264  if (innerpath != cheapest_total_inner)
1265  {
1266  /*
1267  * Avoid rebuilding clause list if we already made one; saves
1268  * memory in big join trees...
1269  */
1270  if (newclauses == NIL)
1271  {
1272  if (sortkeycnt < num_sortkeys)
1273  {
1274  newclauses =
1276  trialsortkeys,
1277  false,
1278  mergeclauses);
1279  Assert(newclauses != NIL);
1280  }
1281  else
1282  newclauses = mergeclauses;
1283  }
1284  try_mergejoin_path(root,
1285  joinrel,
1286  outerpath,
1287  innerpath,
1288  merge_pathkeys,
1289  newclauses,
1290  NIL,
1291  NIL,
1292  jointype,
1293  extra,
1294  is_partial);
1295  }
1296  cheapest_startup_inner = innerpath;
1297  }
1298 
1299  /*
1300  * Don't consider truncated sortkeys if we need all clauses.
1301  */
1302  if (useallclauses)
1303  break;
1304  }
1305 }
Path * get_cheapest_path_for_pathkeys(List *paths, List *pathkeys, Relids required_outer, CostSelector cost_criterion, bool require_parallel_safe)
Definition: pathkeys.c:343
static void try_mergejoin_path(PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, List *pathkeys, List *mergeclauses, List *outersortkeys, List *innersortkeys, JoinType jointype, JoinPathExtraData *extra, bool is_partial)
Definition: joinpath.c:555
#define NIL
Definition: pg_list.h:69
List * list_truncate(List *list, int new_size)
Definition: list.c:350
List * list_copy(const List *oldlist)
Definition: list.c:1160
List * make_inner_pathkeys_for_merge(PlannerInfo *root, List *mergeclauses, List *outer_pathkeys)
Definition: pathkeys.c:1292
JoinType
Definition: nodes.h:676
int compare_path_costs(Path *path1, Path *path2, CostSelector criterion)
Definition: pathnode.c:71
List * mergeclause_list
Definition: relation.h:2281
bool pathkeys_contained_in(List *keys1, List *keys2)
Definition: pathkeys.c:317
List * pathkeys
Definition: relation.h:1056
#define Assert(condition)
Definition: c.h:680
static int list_length(const List *l)
Definition: pg_list.h:89
List * find_mergeclauses_for_pathkeys(PlannerInfo *root, List *pathkeys, bool outer_keys, List *restrictinfos)
Definition: pathkeys.c:1003
List * pathlist
Definition: relation.h:599
Definition: pg_list.h:45

◆ hash_inner_and_outer()

static void hash_inner_and_outer ( PlannerInfo root,
RelOptInfo joinrel,
RelOptInfo outerrel,
RelOptInfo innerrel,
JoinType  jointype,
JoinPathExtraData extra 
)
static

Definition at line 1677 of file joinpath.c.

References Assert, bms_is_empty(), RestrictInfo::can_join, RelOptInfo::cheapest_parameterized_paths, RelOptInfo::cheapest_startup_path, RelOptInfo::cheapest_total_path, clause_sides_match_join(), RelOptInfo::consider_parallel, create_unique_path(), enable_parallel_hash, get_cheapest_parallel_safe_total_inner(), RestrictInfo::hashjoinoperator, InvalidOid, IS_OUTER_JOIN, RestrictInfo::is_pushed_down, JOIN_FULL, JOIN_INNER, JOIN_RIGHT, JOIN_UNIQUE_INNER, JOIN_UNIQUE_OUTER, lappend(), RelOptInfo::lateral_relids, lfirst, linitial, NIL, Path::parallel_safe, RelOptInfo::partial_pathlist, PATH_PARAM_BY_REL, RelOptInfo::pathlist, JoinPathExtraData::restrictlist, JoinPathExtraData::sjinfo, try_hashjoin_path(), and try_partial_hashjoin_path().

Referenced by add_paths_to_joinrel().

1683 {
1684  JoinType save_jointype = jointype;
1685  bool isouterjoin = IS_OUTER_JOIN(jointype);
1686  List *hashclauses;
1687  ListCell *l;
1688 
1689  /*
1690  * We need to build only one hashclauses list for any given pair of outer
1691  * and inner relations; all of the hashable clauses will be used as keys.
1692  *
1693  * Scan the join's restrictinfo list to find hashjoinable clauses that are
1694  * usable with this pair of sub-relations.
1695  */
1696  hashclauses = NIL;
1697  foreach(l, extra->restrictlist)
1698  {
1699  RestrictInfo *restrictinfo = (RestrictInfo *) lfirst(l);
1700 
1701  /*
1702  * If processing an outer join, only use its own join clauses for
1703  * hashing. For inner joins we need not be so picky.
1704  */
1705  if (isouterjoin && restrictinfo->is_pushed_down)
1706  continue;
1707 
1708  if (!restrictinfo->can_join ||
1709  restrictinfo->hashjoinoperator == InvalidOid)
1710  continue; /* not hashjoinable */
1711 
1712  /*
1713  * Check if clause has the form "outer op inner" or "inner op outer".
1714  */
1715  if (!clause_sides_match_join(restrictinfo, outerrel, innerrel))
1716  continue; /* no good for these input relations */
1717 
1718  hashclauses = lappend(hashclauses, restrictinfo);
1719  }
1720 
1721  /* If we found any usable hashclauses, make paths */
1722  if (hashclauses)
1723  {
1724  /*
1725  * We consider both the cheapest-total-cost and cheapest-startup-cost
1726  * outer paths. There's no need to consider any but the
1727  * cheapest-total-cost inner path, however.
1728  */
1729  Path *cheapest_startup_outer = outerrel->cheapest_startup_path;
1730  Path *cheapest_total_outer = outerrel->cheapest_total_path;
1731  Path *cheapest_total_inner = innerrel->cheapest_total_path;
1732 
1733  /*
1734  * If either cheapest-total path is parameterized by the other rel, we
1735  * can't use a hashjoin. (There's no use looking for alternative
1736  * input paths, since these should already be the least-parameterized
1737  * available paths.)
1738  */
1739  if (PATH_PARAM_BY_REL(cheapest_total_outer, innerrel) ||
1740  PATH_PARAM_BY_REL(cheapest_total_inner, outerrel))
1741  return;
1742 
1743  /* Unique-ify if need be; we ignore parameterized possibilities */
1744  if (jointype == JOIN_UNIQUE_OUTER)
1745  {
1746  cheapest_total_outer = (Path *)
1747  create_unique_path(root, outerrel,
1748  cheapest_total_outer, extra->sjinfo);
1749  Assert(cheapest_total_outer);
1750  jointype = JOIN_INNER;
1751  try_hashjoin_path(root,
1752  joinrel,
1753  cheapest_total_outer,
1754  cheapest_total_inner,
1755  hashclauses,
1756  jointype,
1757  extra);
1758  /* no possibility of cheap startup here */
1759  }
1760  else if (jointype == JOIN_UNIQUE_INNER)
1761  {
1762  cheapest_total_inner = (Path *)
1763  create_unique_path(root, innerrel,
1764  cheapest_total_inner, extra->sjinfo);
1765  Assert(cheapest_total_inner);
1766  jointype = JOIN_INNER;
1767  try_hashjoin_path(root,
1768  joinrel,
1769  cheapest_total_outer,
1770  cheapest_total_inner,
1771  hashclauses,
1772  jointype,
1773  extra);
1774  if (cheapest_startup_outer != NULL &&
1775  cheapest_startup_outer != cheapest_total_outer)
1776  try_hashjoin_path(root,
1777  joinrel,
1778  cheapest_startup_outer,
1779  cheapest_total_inner,
1780  hashclauses,
1781  jointype,
1782  extra);
1783  }
1784  else
1785  {
1786  /*
1787  * For other jointypes, we consider the cheapest startup outer
1788  * together with the cheapest total inner, and then consider
1789  * pairings of cheapest-total paths including parameterized ones.
1790  * There is no use in generating parameterized paths on the basis
1791  * of possibly cheap startup cost, so this is sufficient.
1792  */
1793  ListCell *lc1;
1794  ListCell *lc2;
1795 
1796  if (cheapest_startup_outer != NULL)
1797  try_hashjoin_path(root,
1798  joinrel,
1799  cheapest_startup_outer,
1800  cheapest_total_inner,
1801  hashclauses,
1802  jointype,
1803  extra);
1804 
1805  foreach(lc1, outerrel->cheapest_parameterized_paths)
1806  {
1807  Path *outerpath = (Path *) lfirst(lc1);
1808 
1809  /*
1810  * We cannot use an outer path that is parameterized by the
1811  * inner rel.
1812  */
1813  if (PATH_PARAM_BY_REL(outerpath, innerrel))
1814  continue;
1815 
1816  foreach(lc2, innerrel->cheapest_parameterized_paths)
1817  {
1818  Path *innerpath = (Path *) lfirst(lc2);
1819 
1820  /*
1821  * We cannot use an inner path that is parameterized by
1822  * the outer rel, either.
1823  */
1824  if (PATH_PARAM_BY_REL(innerpath, outerrel))
1825  continue;
1826 
1827  if (outerpath == cheapest_startup_outer &&
1828  innerpath == cheapest_total_inner)
1829  continue; /* already tried it */
1830 
1831  try_hashjoin_path(root,
1832  joinrel,
1833  outerpath,
1834  innerpath,
1835  hashclauses,
1836  jointype,
1837  extra);
1838  }
1839  }
1840  }
1841 
1842  /*
1843  * If the joinrel is parallel-safe, we may be able to consider a
1844  * partial hash join. However, we can't handle JOIN_UNIQUE_OUTER,
1845  * because the outer path will be partial, and therefore we won't be
1846  * able to properly guarantee uniqueness. Similarly, we can't handle
1847  * JOIN_FULL and JOIN_RIGHT, because they can produce false null
1848  * extended rows. Also, the resulting path must not be parameterized.
1849  * We would be able to support JOIN_FULL and JOIN_RIGHT for Parallel
1850  * Hash, since in that case we're back to a single hash table with a
1851  * single set of match bits for each batch, but that will require
1852  * figuring out a deadlock-free way to wait for the probe to finish.
1853  */
1854  if (joinrel->consider_parallel &&
1855  save_jointype != JOIN_UNIQUE_OUTER &&
1856  save_jointype != JOIN_FULL &&
1857  save_jointype != JOIN_RIGHT &&
1858  outerrel->partial_pathlist != NIL &&
1859  bms_is_empty(joinrel->lateral_relids))
1860  {
1861  Path *cheapest_partial_outer;
1862  Path *cheapest_partial_inner = NULL;
1863  Path *cheapest_safe_inner = NULL;
1864 
1865  cheapest_partial_outer =
1866  (Path *) linitial(outerrel->partial_pathlist);
1867 
1868  /*
1869  * Can we use a partial inner plan too, so that we can build a
1870  * shared hash table in parallel?
1871  */
1872  if (innerrel->partial_pathlist != NIL && enable_parallel_hash)
1873  {
1874  cheapest_partial_inner =
1875  (Path *) linitial(innerrel->partial_pathlist);
1876  try_partial_hashjoin_path(root, joinrel,
1877  cheapest_partial_outer,
1878  cheapest_partial_inner,
1879  hashclauses, jointype, extra,
1880  true /* parallel_hash */ );
1881  }
1882 
1883  /*
1884  * Normally, given that the joinrel is parallel-safe, the cheapest
1885  * total inner path will also be parallel-safe, but if not, we'll
1886  * have to search for the cheapest safe, unparameterized inner
1887  * path. If doing JOIN_UNIQUE_INNER, we can't use any alternative
1888  * inner path.
1889  */
1890  if (cheapest_total_inner->parallel_safe)
1891  cheapest_safe_inner = cheapest_total_inner;
1892  else if (save_jointype != JOIN_UNIQUE_INNER)
1893  cheapest_safe_inner =
1895 
1896  if (cheapest_safe_inner != NULL)
1897  try_partial_hashjoin_path(root, joinrel,
1898  cheapest_partial_outer,
1899  cheapest_safe_inner,
1900  hashclauses, jointype, extra,
1901  false /* parallel_hash */ );
1902  }
1903  }
1904 }
#define NIL
Definition: pg_list.h:69
static void try_hashjoin_path(PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, List *hashclauses, JoinType jointype, JoinPathExtraData *extra)
Definition: joinpath.c:720
static void try_partial_hashjoin_path(PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, List *hashclauses, JoinType jointype, JoinPathExtraData *extra, bool parallel_hash)
Definition: joinpath.c:786
struct Path * cheapest_startup_path
Definition: relation.h:602
#define IS_OUTER_JOIN(jointype)
Definition: nodes.h:725
bool enable_parallel_hash
Definition: costsize.c:132
List * partial_pathlist
Definition: relation.h:601
List * cheapest_parameterized_paths
Definition: relation.h:605
UniquePath * create_unique_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, SpecialJoinInfo *sjinfo)
Definition: pathnode.c:1498
JoinType
Definition: nodes.h:676
Relids lateral_relids
Definition: relation.h:610
SpecialJoinInfo * sjinfo
Definition: relation.h:2283
#define linitial(l)
Definition: pg_list.h:111
bool can_join
Definition: relation.h:1849
struct Path * cheapest_total_path
Definition: relation.h:603
Path * get_cheapest_parallel_safe_total_inner(List *paths)
Definition: pathkeys.c:421
List * lappend(List *list, void *datum)
Definition: list.c:128
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:707
List * restrictlist
Definition: relation.h:2280
#define InvalidOid
Definition: postgres_ext.h:36
bool is_pushed_down
Definition: relation.h:1845
#define PATH_PARAM_BY_REL(path, rel)
Definition: joinpath.c:39
#define Assert(condition)
Definition: c.h:680
#define lfirst(lc)
Definition: pg_list.h:106
bool parallel_safe
Definition: relation.h:1048
static bool clause_sides_match_join(RestrictInfo *rinfo, RelOptInfo *outerrel, RelOptInfo *innerrel)
Definition: joinpath.c:847
Oid hashjoinoperator
Definition: relation.h:1901
bool consider_parallel
Definition: relation.h:593
List * pathlist
Definition: relation.h:599
Definition: pg_list.h:45

◆ match_unsorted_outer()

static void match_unsorted_outer ( PlannerInfo root,
RelOptInfo joinrel,
RelOptInfo outerrel,
RelOptInfo innerrel,
JoinType  jointype,
JoinPathExtraData extra 
)
static

Definition at line 1331 of file joinpath.c.

References Assert, bms_is_empty(), build_join_pathkeys(), RelOptInfo::cheapest_parameterized_paths, RelOptInfo::cheapest_total_path, RelOptInfo::consider_parallel, consider_parallel_mergejoin(), consider_parallel_nestloop(), create_material_path(), create_unique_path(), elog, enable_material, ERROR, ExecMaterializesOutput(), generate_mergejoin_paths(), get_cheapest_parallel_safe_total_inner(), JOIN_ANTI, JOIN_FULL, JOIN_INNER, JOIN_LEFT, JOIN_RIGHT, JOIN_SEMI, JOIN_UNIQUE_INNER, JOIN_UNIQUE_OUTER, RelOptInfo::lateral_relids, lfirst, NIL, Path::parallel_safe, RelOptInfo::partial_pathlist, PATH_PARAM_BY_REL, Path::pathkeys, RelOptInfo::pathlist, Path::pathtype, JoinPathExtraData::sjinfo, and try_nestloop_path().

Referenced by add_paths_to_joinrel().

1337 {
1338  JoinType save_jointype = jointype;
1339  bool nestjoinOK;
1340  bool useallclauses;
1341  Path *inner_cheapest_total = innerrel->cheapest_total_path;
1342  Path *matpath = NULL;
1343  ListCell *lc1;
1344 
1345  /*
1346  * Nestloop only supports inner, left, semi, and anti joins. Also, if we
1347  * are doing a right or full mergejoin, we must use *all* the mergeclauses
1348  * as join clauses, else we will not have a valid plan. (Although these
1349  * two flags are currently inverses, keep them separate for clarity and
1350  * possible future changes.)
1351  */
1352  switch (jointype)
1353  {
1354  case JOIN_INNER:
1355  case JOIN_LEFT:
1356  case JOIN_SEMI:
1357  case JOIN_ANTI:
1358  nestjoinOK = true;
1359  useallclauses = false;
1360  break;
1361  case JOIN_RIGHT:
1362  case JOIN_FULL:
1363  nestjoinOK = false;
1364  useallclauses = true;
1365  break;
1366  case JOIN_UNIQUE_OUTER:
1367  case JOIN_UNIQUE_INNER:
1368  jointype = JOIN_INNER;
1369  nestjoinOK = true;
1370  useallclauses = false;
1371  break;
1372  default:
1373  elog(ERROR, "unrecognized join type: %d",
1374  (int) jointype);
1375  nestjoinOK = false; /* keep compiler quiet */
1376  useallclauses = false;
1377  break;
1378  }
1379 
1380  /*
1381  * If inner_cheapest_total is parameterized by the outer rel, ignore it;
1382  * we will consider it below as a member of cheapest_parameterized_paths,
1383  * but the other possibilities considered in this routine aren't usable.
1384  */
1385  if (PATH_PARAM_BY_REL(inner_cheapest_total, outerrel))
1386  inner_cheapest_total = NULL;
1387 
1388  /*
1389  * If we need to unique-ify the inner path, we will consider only the
1390  * cheapest-total inner.
1391  */
1392  if (save_jointype == JOIN_UNIQUE_INNER)
1393  {
1394  /* No way to do this with an inner path parameterized by outer rel */
1395  if (inner_cheapest_total == NULL)
1396  return;
1397  inner_cheapest_total = (Path *)
1398  create_unique_path(root, innerrel, inner_cheapest_total, extra->sjinfo);
1399  Assert(inner_cheapest_total);
1400  }
1401  else if (nestjoinOK)
1402  {
1403  /*
1404  * Consider materializing the cheapest inner path, unless
1405  * enable_material is off or the path in question materializes its
1406  * output anyway.
1407  */
1408  if (enable_material && inner_cheapest_total != NULL &&
1409  !ExecMaterializesOutput(inner_cheapest_total->pathtype))
1410  matpath = (Path *)
1411  create_material_path(innerrel, inner_cheapest_total);
1412  }
1413 
1414  foreach(lc1, outerrel->pathlist)
1415  {
1416  Path *outerpath = (Path *) lfirst(lc1);
1417  List *merge_pathkeys;
1418 
1419  /*
1420  * We cannot use an outer path that is parameterized by the inner rel.
1421  */
1422  if (PATH_PARAM_BY_REL(outerpath, innerrel))
1423  continue;
1424 
1425  /*
1426  * If we need to unique-ify the outer path, it's pointless to consider
1427  * any but the cheapest outer. (XXX we don't consider parameterized
1428  * outers, nor inners, for unique-ified cases. Should we?)
1429  */
1430  if (save_jointype == JOIN_UNIQUE_OUTER)
1431  {
1432  if (outerpath != outerrel->cheapest_total_path)
1433  continue;
1434  outerpath = (Path *) create_unique_path(root, outerrel,
1435  outerpath, extra->sjinfo);
1436  Assert(outerpath);
1437  }
1438 
1439  /*
1440  * The result will have this sort order (even if it is implemented as
1441  * a nestloop, and even if some of the mergeclauses are implemented by
1442  * qpquals rather than as true mergeclauses):
1443  */
1444  merge_pathkeys = build_join_pathkeys(root, joinrel, jointype,
1445  outerpath->pathkeys);
1446 
1447  if (save_jointype == JOIN_UNIQUE_INNER)
1448  {
1449  /*
1450  * Consider nestloop join, but only with the unique-ified cheapest
1451  * inner path
1452  */
1453  try_nestloop_path(root,
1454  joinrel,
1455  outerpath,
1456  inner_cheapest_total,
1457  merge_pathkeys,
1458  jointype,
1459  extra);
1460  }
1461  else if (nestjoinOK)
1462  {
1463  /*
1464  * Consider nestloop joins using this outer path and various
1465  * available paths for the inner relation. We consider the
1466  * cheapest-total paths for each available parameterization of the
1467  * inner relation, including the unparameterized case.
1468  */
1469  ListCell *lc2;
1470 
1471  foreach(lc2, innerrel->cheapest_parameterized_paths)
1472  {
1473  Path *innerpath = (Path *) lfirst(lc2);
1474 
1475  try_nestloop_path(root,
1476  joinrel,
1477  outerpath,
1478  innerpath,
1479  merge_pathkeys,
1480  jointype,
1481  extra);
1482  }
1483 
1484  /* Also consider materialized form of the cheapest inner path */
1485  if (matpath != NULL)
1486  try_nestloop_path(root,
1487  joinrel,
1488  outerpath,
1489  matpath,
1490  merge_pathkeys,
1491  jointype,
1492  extra);
1493  }
1494 
1495  /* Can't do anything else if outer path needs to be unique'd */
1496  if (save_jointype == JOIN_UNIQUE_OUTER)
1497  continue;
1498 
1499  /* Can't do anything else if inner rel is parameterized by outer */
1500  if (inner_cheapest_total == NULL)
1501  continue;
1502 
1503  /* Generate merge join paths */
1504  generate_mergejoin_paths(root, joinrel, innerrel, outerpath,
1505  save_jointype, extra, useallclauses,
1506  inner_cheapest_total, merge_pathkeys,
1507  false);
1508  }
1509 
1510  /*
1511  * Consider partial nestloop and mergejoin plan if outerrel has any
1512  * partial path and the joinrel is parallel-safe. However, we can't
1513  * handle JOIN_UNIQUE_OUTER, because the outer path will be partial, and
1514  * therefore we won't be able to properly guarantee uniqueness. Nor can
1515  * we handle extra_lateral_rels, since partial paths must not be
1516  * parameterized. Similarly, we can't handle JOIN_FULL and JOIN_RIGHT,
1517  * because they can produce false null extended rows.
1518  */
1519  if (joinrel->consider_parallel &&
1520  save_jointype != JOIN_UNIQUE_OUTER &&
1521  save_jointype != JOIN_FULL &&
1522  save_jointype != JOIN_RIGHT &&
1523  outerrel->partial_pathlist != NIL &&
1524  bms_is_empty(joinrel->lateral_relids))
1525  {
1526  if (nestjoinOK)
1527  consider_parallel_nestloop(root, joinrel, outerrel, innerrel,
1528  save_jointype, extra);
1529 
1530  /*
1531  * If inner_cheapest_total is NULL or non parallel-safe then find the
1532  * cheapest total parallel safe path. If doing JOIN_UNIQUE_INNER, we
1533  * can't use any alternative inner path.
1534  */
1535  if (inner_cheapest_total == NULL ||
1536  !inner_cheapest_total->parallel_safe)
1537  {
1538  if (save_jointype == JOIN_UNIQUE_INNER)
1539  return;
1540 
1541  inner_cheapest_total = get_cheapest_parallel_safe_total_inner(
1542  innerrel->pathlist);
1543  }
1544 
1545  if (inner_cheapest_total)
1546  consider_parallel_mergejoin(root, joinrel, outerrel, innerrel,
1547  save_jointype, extra,
1548  inner_cheapest_total);
1549  }
1550 }
#define NIL
Definition: pg_list.h:69
static void try_nestloop_path(PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, List *pathkeys, JoinType jointype, JoinPathExtraData *extra)
Definition: joinpath.c:361
MaterialPath * create_material_path(RelOptInfo *rel, Path *subpath)
Definition: pathnode.c:1459
List * partial_pathlist
Definition: relation.h:601
List * cheapest_parameterized_paths
Definition: relation.h:605
UniquePath * create_unique_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, SpecialJoinInfo *sjinfo)
Definition: pathnode.c:1498
List * build_join_pathkeys(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, List *outer_pathkeys)
Definition: pathkeys.c:822
JoinType
Definition: nodes.h:676
NodeTag pathtype
Definition: relation.h:1040
Relids lateral_relids
Definition: relation.h:610
SpecialJoinInfo * sjinfo
Definition: relation.h:2283
#define ERROR
Definition: elog.h:43
struct Path * cheapest_total_path
Definition: relation.h:603
static void generate_mergejoin_paths(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *innerrel, Path *outerpath, JoinType jointype, JoinPathExtraData *extra, bool useallclauses, Path *inner_cheapest_total, List *merge_pathkeys, bool is_partial)
Definition: joinpath.c:1081
Path * get_cheapest_parallel_safe_total_inner(List *paths)
Definition: pathkeys.c:421
static void consider_parallel_nestloop(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, JoinPathExtraData *extra)
Definition: joinpath.c:1605
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:707
static void consider_parallel_mergejoin(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, JoinPathExtraData *extra, Path *inner_cheapest_total)
Definition: joinpath.c:1565
#define PATH_PARAM_BY_REL(path, rel)
Definition: joinpath.c:39
List * pathkeys
Definition: relation.h:1056
#define Assert(condition)
Definition: c.h:680
#define lfirst(lc)
Definition: pg_list.h:106
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
bool ExecMaterializesOutput(NodeTag plantype)
Definition: execAmi.c:577
List * pathlist
Definition: relation.h:599
#define elog
Definition: elog.h:219
Definition: pg_list.h:45
bool enable_material
Definition: costsize.c:126

◆ select_mergejoin_clauses()

static List * select_mergejoin_clauses ( PlannerInfo root,
RelOptInfo joinrel,
RelOptInfo outerrel,
RelOptInfo innerrel,
List restrictlist,
JoinType  jointype,
bool mergejoin_allowed 
)
static

Definition at line 1929 of file joinpath.c.

References RestrictInfo::can_join, RestrictInfo::clause, clause_sides_match_join(), EC_MUST_BE_REDUNDANT, IS_OUTER_JOIN, RestrictInfo::is_pushed_down, IsA, JOIN_FULL, JOIN_RIGHT, lappend(), RestrictInfo::left_ec, lfirst, RestrictInfo::mergeopfamilies, NIL, RestrictInfo::right_ec, and update_mergeclause_eclasses().

Referenced by add_paths_to_joinrel().

1936 {
1937  List *result_list = NIL;
1938  bool isouterjoin = IS_OUTER_JOIN(jointype);
1939  bool have_nonmergeable_joinclause = false;
1940  ListCell *l;
1941 
1942  foreach(l, restrictlist)
1943  {
1944  RestrictInfo *restrictinfo = (RestrictInfo *) lfirst(l);
1945 
1946  /*
1947  * If processing an outer join, only use its own join clauses in the
1948  * merge. For inner joins we can use pushed-down clauses too. (Note:
1949  * we don't set have_nonmergeable_joinclause here because pushed-down
1950  * clauses will become otherquals not joinquals.)
1951  */
1952  if (isouterjoin && restrictinfo->is_pushed_down)
1953  continue;
1954 
1955  /* Check that clause is a mergeable operator clause */
1956  if (!restrictinfo->can_join ||
1957  restrictinfo->mergeopfamilies == NIL)
1958  {
1959  /*
1960  * The executor can handle extra joinquals that are constants, but
1961  * not anything else, when doing right/full merge join. (The
1962  * reason to support constants is so we can do FULL JOIN ON
1963  * FALSE.)
1964  */
1965  if (!restrictinfo->clause || !IsA(restrictinfo->clause, Const))
1966  have_nonmergeable_joinclause = true;
1967  continue; /* not mergejoinable */
1968  }
1969 
1970  /*
1971  * Check if clause has the form "outer op inner" or "inner op outer".
1972  */
1973  if (!clause_sides_match_join(restrictinfo, outerrel, innerrel))
1974  {
1975  have_nonmergeable_joinclause = true;
1976  continue; /* no good for these input relations */
1977  }
1978 
1979  /*
1980  * Insist that each side have a non-redundant eclass. This
1981  * restriction is needed because various bits of the planner expect
1982  * that each clause in a merge be associable with some pathkey in a
1983  * canonical pathkey list, but redundant eclasses can't appear in
1984  * canonical sort orderings. (XXX it might be worth relaxing this,
1985  * but not enough time to address it for 8.3.)
1986  *
1987  * Note: it would be bad if this condition failed for an otherwise
1988  * mergejoinable FULL JOIN clause, since that would result in
1989  * undesirable planner failure. I believe that is not possible
1990  * however; a variable involved in a full join could only appear in
1991  * below_outer_join eclasses, which aren't considered redundant.
1992  *
1993  * This case *can* happen for left/right join clauses: the outer-side
1994  * variable could be equated to a constant. Because we will propagate
1995  * that constant across the join clause, the loss of ability to do a
1996  * mergejoin is not really all that big a deal, and so it's not clear
1997  * that improving this is important.
1998  */
1999  update_mergeclause_eclasses(root, restrictinfo);
2000 
2001  if (EC_MUST_BE_REDUNDANT(restrictinfo->left_ec) ||
2002  EC_MUST_BE_REDUNDANT(restrictinfo->right_ec))
2003  {
2004  have_nonmergeable_joinclause = true;
2005  continue; /* can't handle redundant eclasses */
2006  }
2007 
2008  result_list = lappend(result_list, restrictinfo);
2009  }
2010 
2011  /*
2012  * Report whether mergejoin is allowed (see comment at top of function).
2013  */
2014  switch (jointype)
2015  {
2016  case JOIN_RIGHT:
2017  case JOIN_FULL:
2018  *mergejoin_allowed = !have_nonmergeable_joinclause;
2019  break;
2020  default:
2021  *mergejoin_allowed = true;
2022  break;
2023  }
2024 
2025  return result_list;
2026 }
#define NIL
Definition: pg_list.h:69
#define IsA(nodeptr, _type_)
Definition: nodes.h:563
#define IS_OUTER_JOIN(jointype)
Definition: nodes.h:725
EquivalenceClass * right_ec
Definition: relation.h:1892
List * mergeopfamilies
Definition: relation.h:1888
bool can_join
Definition: relation.h:1849
#define EC_MUST_BE_REDUNDANT(eclass)
Definition: relation.h:881
List * lappend(List *list, void *datum)
Definition: list.c:128
Expr * clause
Definition: relation.h:1843
bool is_pushed_down
Definition: relation.h:1845
#define lfirst(lc)
Definition: pg_list.h:106
static bool clause_sides_match_join(RestrictInfo *rinfo, RelOptInfo *outerrel, RelOptInfo *innerrel)
Definition: joinpath.c:847
EquivalenceClass * left_ec
Definition: relation.h:1891
Definition: pg_list.h:45
void update_mergeclause_eclasses(PlannerInfo *root, RestrictInfo *restrictinfo)
Definition: pathkeys.c:968

◆ sort_inner_and_outer()

static void sort_inner_and_outer ( PlannerInfo root,
RelOptInfo joinrel,
RelOptInfo outerrel,
RelOptInfo innerrel,
JoinType  jointype,
JoinPathExtraData extra 
)
static

Definition at line 879 of file joinpath.c.

References Assert, bms_is_empty(), build_join_pathkeys(), RelOptInfo::cheapest_total_path, RelOptInfo::consider_parallel, create_unique_path(), find_mergeclauses_for_pathkeys(), get_cheapest_parallel_safe_total_inner(), JOIN_FULL, JOIN_INNER, JOIN_RIGHT, JOIN_UNIQUE_INNER, JOIN_UNIQUE_OUTER, RelOptInfo::lateral_relids, lcons(), lfirst, linitial, list_copy(), list_delete_ptr(), list_head(), list_length(), make_inner_pathkeys_for_merge(), JoinPathExtraData::mergeclause_list, NIL, Path::parallel_safe, RelOptInfo::partial_pathlist, PATH_PARAM_BY_REL, RelOptInfo::pathlist, select_outer_pathkeys_for_merge(), JoinPathExtraData::sjinfo, try_mergejoin_path(), and try_partial_mergejoin_path().

Referenced by add_paths_to_joinrel().

885 {
886  JoinType save_jointype = jointype;
887  Path *outer_path;
888  Path *inner_path;
889  Path *cheapest_partial_outer = NULL;
890  Path *cheapest_safe_inner = NULL;
891  List *all_pathkeys;
892  ListCell *l;
893 
894  /*
895  * We only consider the cheapest-total-cost input paths, since we are
896  * assuming here that a sort is required. We will consider
897  * cheapest-startup-cost input paths later, and only if they don't need a
898  * sort.
899  *
900  * This function intentionally does not consider parameterized input
901  * paths, except when the cheapest-total is parameterized. If we did so,
902  * we'd have a combinatorial explosion of mergejoin paths of dubious
903  * value. This interacts with decisions elsewhere that also discriminate
904  * against mergejoins with parameterized inputs; see comments in
905  * src/backend/optimizer/README.
906  */
907  outer_path = outerrel->cheapest_total_path;
908  inner_path = innerrel->cheapest_total_path;
909 
910  /*
911  * If either cheapest-total path is parameterized by the other rel, we
912  * can't use a mergejoin. (There's no use looking for alternative input
913  * paths, since these should already be the least-parameterized available
914  * paths.)
915  */
916  if (PATH_PARAM_BY_REL(outer_path, innerrel) ||
917  PATH_PARAM_BY_REL(inner_path, outerrel))
918  return;
919 
920  /*
921  * If unique-ification is requested, do it and then handle as a plain
922  * inner join.
923  */
924  if (jointype == JOIN_UNIQUE_OUTER)
925  {
926  outer_path = (Path *) create_unique_path(root, outerrel,
927  outer_path, extra->sjinfo);
928  Assert(outer_path);
929  jointype = JOIN_INNER;
930  }
931  else if (jointype == JOIN_UNIQUE_INNER)
932  {
933  inner_path = (Path *) create_unique_path(root, innerrel,
934  inner_path, extra->sjinfo);
935  Assert(inner_path);
936  jointype = JOIN_INNER;
937  }
938 
939  /*
940  * If the joinrel is parallel-safe, we may be able to consider a partial
941  * merge join. However, we can't handle JOIN_UNIQUE_OUTER, because the
942  * outer path will be partial, and therefore we won't be able to properly
943  * guarantee uniqueness. Similarly, we can't handle JOIN_FULL and
944  * JOIN_RIGHT, because they can produce false null extended rows. Also,
945  * the resulting path must not be parameterized.
946  */
947  if (joinrel->consider_parallel &&
948  save_jointype != JOIN_UNIQUE_OUTER &&
949  save_jointype != JOIN_FULL &&
950  save_jointype != JOIN_RIGHT &&
951  outerrel->partial_pathlist != NIL &&
952  bms_is_empty(joinrel->lateral_relids))
953  {
954  cheapest_partial_outer = (Path *) linitial(outerrel->partial_pathlist);
955 
956  if (inner_path->parallel_safe)
957  cheapest_safe_inner = inner_path;
958  else if (save_jointype != JOIN_UNIQUE_INNER)
959  cheapest_safe_inner =
961  }
962 
963  /*
964  * Each possible ordering of the available mergejoin clauses will generate
965  * a differently-sorted result path at essentially the same cost. We have
966  * no basis for choosing one over another at this level of joining, but
967  * some sort orders may be more useful than others for higher-level
968  * mergejoins, so it's worth considering multiple orderings.
969  *
970  * Actually, it's not quite true that every mergeclause ordering will
971  * generate a different path order, because some of the clauses may be
972  * partially redundant (refer to the same EquivalenceClasses). Therefore,
973  * what we do is convert the mergeclause list to a list of canonical
974  * pathkeys, and then consider different orderings of the pathkeys.
975  *
976  * Generating a path for *every* permutation of the pathkeys doesn't seem
977  * like a winning strategy; the cost in planning time is too high. For
978  * now, we generate one path for each pathkey, listing that pathkey first
979  * and the rest in random order. This should allow at least a one-clause
980  * mergejoin without re-sorting against any other possible mergejoin
981  * partner path. But if we've not guessed the right ordering of secondary
982  * keys, we may end up evaluating clauses as qpquals when they could have
983  * been done as mergeclauses. (In practice, it's rare that there's more
984  * than two or three mergeclauses, so expending a huge amount of thought
985  * on that is probably not worth it.)
986  *
987  * The pathkey order returned by select_outer_pathkeys_for_merge() has
988  * some heuristics behind it (see that function), so be sure to try it
989  * exactly as-is as well as making variants.
990  */
991  all_pathkeys = select_outer_pathkeys_for_merge(root,
992  extra->mergeclause_list,
993  joinrel);
994 
995  foreach(l, all_pathkeys)
996  {
997  List *front_pathkey = (List *) lfirst(l);
998  List *cur_mergeclauses;
999  List *outerkeys;
1000  List *innerkeys;
1001  List *merge_pathkeys;
1002 
1003  /* Make a pathkey list with this guy first */
1004  if (l != list_head(all_pathkeys))
1005  outerkeys = lcons(front_pathkey,
1006  list_delete_ptr(list_copy(all_pathkeys),
1007  front_pathkey));
1008  else
1009  outerkeys = all_pathkeys; /* no work at first one... */
1010 
1011  /* Sort the mergeclauses into the corresponding ordering */
1012  cur_mergeclauses = find_mergeclauses_for_pathkeys(root,
1013  outerkeys,
1014  true,
1015  extra->mergeclause_list);
1016 
1017  /* Should have used them all... */
1018  Assert(list_length(cur_mergeclauses) == list_length(extra->mergeclause_list));
1019 
1020  /* Build sort pathkeys for the inner side */
1021  innerkeys = make_inner_pathkeys_for_merge(root,
1022  cur_mergeclauses,
1023  outerkeys);
1024 
1025  /* Build pathkeys representing output sort order */
1026  merge_pathkeys = build_join_pathkeys(root, joinrel, jointype,
1027  outerkeys);
1028 
1029  /*
1030  * And now we can make the path.
1031  *
1032  * Note: it's possible that the cheapest paths will already be sorted
1033  * properly. try_mergejoin_path will detect that case and suppress an
1034  * explicit sort step, so we needn't do so here.
1035  */
1036  try_mergejoin_path(root,
1037  joinrel,
1038  outer_path,
1039  inner_path,
1040  merge_pathkeys,
1041  cur_mergeclauses,
1042  outerkeys,
1043  innerkeys,
1044  jointype,
1045  extra,
1046  false);
1047 
1048  /*
1049  * If we have partial outer and parallel safe inner path then try
1050  * partial mergejoin path.
1051  */
1052  if (cheapest_partial_outer && cheapest_safe_inner)
1054  joinrel,
1055  cheapest_partial_outer,
1056  cheapest_safe_inner,
1057  merge_pathkeys,
1058  cur_mergeclauses,
1059  outerkeys,
1060  innerkeys,
1061  jointype,
1062  extra);
1063  }
1064 }
static void try_mergejoin_path(PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, List *pathkeys, List *mergeclauses, List *outersortkeys, List *innersortkeys, JoinType jointype, JoinPathExtraData *extra, bool is_partial)
Definition: joinpath.c:555
#define NIL
Definition: pg_list.h:69
List * list_copy(const List *oldlist)
Definition: list.c:1160
List * make_inner_pathkeys_for_merge(PlannerInfo *root, List *mergeclauses, List *outer_pathkeys)
Definition: pathkeys.c:1292
List * partial_pathlist
Definition: relation.h:601
UniquePath * create_unique_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, SpecialJoinInfo *sjinfo)
Definition: pathnode.c:1498
List * list_delete_ptr(List *list, void *datum)
Definition: list.c:590
List * build_join_pathkeys(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, List *outer_pathkeys)
Definition: pathkeys.c:822
JoinType
Definition: nodes.h:676
Relids lateral_relids
Definition: relation.h:610
SpecialJoinInfo * sjinfo
Definition: relation.h:2283
#define linitial(l)
Definition: pg_list.h:111
struct Path * cheapest_total_path
Definition: relation.h:603
static ListCell * list_head(const List *l)
Definition: pg_list.h:77
List * mergeclause_list
Definition: relation.h:2281
Path * get_cheapest_parallel_safe_total_inner(List *paths)
Definition: pathkeys.c:421
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:707
List * select_outer_pathkeys_for_merge(PlannerInfo *root, List *mergeclauses, RelOptInfo *joinrel)
Definition: pathkeys.c:1120
#define PATH_PARAM_BY_REL(path, rel)
Definition: joinpath.c:39
List * lcons(void *datum, List *list)
Definition: list.c:259
#define Assert(condition)
Definition: c.h:680
#define lfirst(lc)
Definition: pg_list.h:106
bool parallel_safe
Definition: relation.h:1048
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:593
List * find_mergeclauses_for_pathkeys(PlannerInfo *root, List *pathkeys, bool outer_keys, List *restrictinfos)
Definition: pathkeys.c:1003
static void try_partial_mergejoin_path(PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, List *pathkeys, List *mergeclauses, List *outersortkeys, List *innersortkeys, JoinType jointype, JoinPathExtraData *extra)
Definition: joinpath.c:650
List * pathlist
Definition: relation.h:599
Definition: pg_list.h:45

◆ try_hashjoin_path()

static void try_hashjoin_path ( PlannerInfo root,
RelOptInfo joinrel,
Path outer_path,
Path inner_path,
List hashclauses,
JoinType  jointype,
JoinPathExtraData extra 
)
static

Definition at line 720 of file joinpath.c.

References add_path(), add_path_precheck(), bms_free(), bms_overlap(), calc_non_nestloop_required_outer(), create_hashjoin_path(), initial_cost_hashjoin(), NIL, JoinPathExtraData::param_source_rels, JoinPathExtraData::restrictlist, JoinCostWorkspace::startup_cost, and JoinCostWorkspace::total_cost.

Referenced by hash_inner_and_outer().

727 {
728  Relids required_outer;
729  JoinCostWorkspace workspace;
730 
731  /*
732  * Check to see if proposed path is still parameterized, and reject if the
733  * parameterization wouldn't be sensible.
734  */
735  required_outer = calc_non_nestloop_required_outer(outer_path,
736  inner_path);
737  if (required_outer &&
738  !bms_overlap(required_outer, extra->param_source_rels))
739  {
740  /* Waste no memory when we reject a path here */
741  bms_free(required_outer);
742  return;
743  }
744 
745  /*
746  * See comments in try_nestloop_path(). Also note that hashjoin paths
747  * never have any output pathkeys, per comments in create_hashjoin_path.
748  */
749  initial_cost_hashjoin(root, &workspace, jointype, hashclauses,
750  outer_path, inner_path, extra, false);
751 
752  if (add_path_precheck(joinrel,
753  workspace.startup_cost, workspace.total_cost,
754  NIL, required_outer))
755  {
756  add_path(joinrel, (Path *)
758  joinrel,
759  jointype,
760  &workspace,
761  extra,
762  outer_path,
763  inner_path,
764  false, /* parallel_hash */
765  extra->restrictlist,
766  required_outer,
767  hashclauses));
768  }
769  else
770  {
771  /* Waste no memory when we reject a path here */
772  bms_free(required_outer);
773  }
774 }
#define NIL
Definition: pg_list.h:69
void add_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:422
bool add_path_precheck(RelOptInfo *parent_rel, Cost startup_cost, Cost total_cost, List *pathkeys, Relids required_outer)
Definition: pathnode.c:657
Relids calc_non_nestloop_required_outer(Path *outer_path, Path *inner_path)
Definition: pathnode.c:2107
HashPath * create_hashjoin_path(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, JoinCostWorkspace *workspace, JoinPathExtraData *extra, Path *outer_path, Path *inner_path, bool parallel_hash, List *restrict_clauses, Relids required_outer, List *hashclauses)
Definition: pathnode.c:2294
void initial_cost_hashjoin(PlannerInfo *root, JoinCostWorkspace *workspace, JoinType jointype, List *hashclauses, Path *outer_path, Path *inner_path, JoinPathExtraData *extra, bool parallel_hash)
Definition: costsize.c:3138
Relids param_source_rels
Definition: relation.h:2285
List * restrictlist
Definition: relation.h:2280
void bms_free(Bitmapset *a)
Definition: bitmapset.c:245
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:487

◆ try_mergejoin_path()

static void try_mergejoin_path ( PlannerInfo root,
RelOptInfo joinrel,
Path outer_path,
Path inner_path,
List pathkeys,
List mergeclauses,
List outersortkeys,
List innersortkeys,
JoinType  jointype,
JoinPathExtraData extra,
bool  is_partial 
)
static

Definition at line 555 of file joinpath.c.

References add_path(), add_path_precheck(), bms_free(), bms_overlap(), calc_non_nestloop_required_outer(), create_mergejoin_path(), initial_cost_mergejoin(), NIL, JoinPathExtraData::param_source_rels, Path::pathkeys, pathkeys_contained_in(), JoinPathExtraData::restrictlist, JoinCostWorkspace::startup_cost, JoinCostWorkspace::total_cost, and try_partial_mergejoin_path().

Referenced by generate_mergejoin_paths(), and sort_inner_and_outer().

566 {
567  Relids required_outer;
568  JoinCostWorkspace workspace;
569 
570  if (is_partial)
571  {
573  joinrel,
574  outer_path,
575  inner_path,
576  pathkeys,
577  mergeclauses,
578  outersortkeys,
579  innersortkeys,
580  jointype,
581  extra);
582  return;
583  }
584 
585  /*
586  * Check to see if proposed path is still parameterized, and reject if the
587  * parameterization wouldn't be sensible.
588  */
589  required_outer = calc_non_nestloop_required_outer(outer_path,
590  inner_path);
591  if (required_outer &&
592  !bms_overlap(required_outer, extra->param_source_rels))
593  {
594  /* Waste no memory when we reject a path here */
595  bms_free(required_outer);
596  return;
597  }
598 
599  /*
600  * If the given paths are already well enough ordered, we can skip doing
601  * an explicit sort.
602  */
603  if (outersortkeys &&
604  pathkeys_contained_in(outersortkeys, outer_path->pathkeys))
605  outersortkeys = NIL;
606  if (innersortkeys &&
607  pathkeys_contained_in(innersortkeys, inner_path->pathkeys))
608  innersortkeys = NIL;
609 
610  /*
611  * See comments in try_nestloop_path().
612  */
613  initial_cost_mergejoin(root, &workspace, jointype, mergeclauses,
614  outer_path, inner_path,
615  outersortkeys, innersortkeys,
616  extra);
617 
618  if (add_path_precheck(joinrel,
619  workspace.startup_cost, workspace.total_cost,
620  pathkeys, required_outer))
621  {
622  add_path(joinrel, (Path *)
624  joinrel,
625  jointype,
626  &workspace,
627  extra,
628  outer_path,
629  inner_path,
630  extra->restrictlist,
631  pathkeys,
632  required_outer,
633  mergeclauses,
634  outersortkeys,
635  innersortkeys));
636  }
637  else
638  {
639  /* Waste no memory when we reject a path here */
640  bms_free(required_outer);
641  }
642 }
#define NIL
Definition: pg_list.h:69
void add_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:422
bool add_path_precheck(RelOptInfo *parent_rel, Cost startup_cost, Cost total_cost, List *pathkeys, Relids required_outer)
Definition: pathnode.c:657
Relids calc_non_nestloop_required_outer(Path *outer_path, Path *inner_path)
Definition: pathnode.c:2107
MergePath * create_mergejoin_path(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, JoinCostWorkspace *workspace, JoinPathExtraData *extra, Path *outer_path, Path *inner_path, List *restrict_clauses, List *pathkeys, Relids required_outer, List *mergeclauses, List *outersortkeys, List *innersortkeys)
Definition: pathnode.c:2228
void initial_cost_mergejoin(PlannerInfo *root, JoinCostWorkspace *workspace, JoinType jointype, List *mergeclauses, Path *outer_path, Path *inner_path, List *outersortkeys, List *innersortkeys, JoinPathExtraData *extra)
Definition: costsize.c:2587
Relids param_source_rels
Definition: relation.h:2285
bool pathkeys_contained_in(List *keys1, List *keys2)
Definition: pathkeys.c:317
List * restrictlist
Definition: relation.h:2280
List * pathkeys
Definition: relation.h:1056
void bms_free(Bitmapset *a)
Definition: bitmapset.c:245
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:487
static void try_partial_mergejoin_path(PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, List *pathkeys, List *mergeclauses, List *outersortkeys, List *innersortkeys, JoinType jointype, JoinPathExtraData *extra)
Definition: joinpath.c:650

◆ try_nestloop_path()

static void try_nestloop_path ( PlannerInfo root,
RelOptInfo joinrel,
Path outer_path,
Path inner_path,
List pathkeys,
JoinType  jointype,
JoinPathExtraData extra 
)
static

Definition at line 361 of file joinpath.c.

References add_path(), add_path_precheck(), allow_star_schema_join(), bms_free(), bms_overlap(), calc_nestloop_required_outer(), create_nestloop_path(), have_dangerous_phv(), initial_cost_nestloop(), JoinPathExtraData::param_source_rels, Path::parent, PATH_PARAM_BY_PARENT, PATH_REQ_OUTER, RelOptInfo::relids, reparameterize_path_by_child(), JoinPathExtraData::restrictlist, JoinCostWorkspace::startup_cost, RelOptInfo::top_parent_relids, and JoinCostWorkspace::total_cost.

Referenced by match_unsorted_outer().

368 {
369  Relids required_outer;
370  JoinCostWorkspace workspace;
371  RelOptInfo *innerrel = inner_path->parent;
372  RelOptInfo *outerrel = outer_path->parent;
373  Relids innerrelids;
374  Relids outerrelids;
375  Relids inner_paramrels = PATH_REQ_OUTER(inner_path);
376  Relids outer_paramrels = PATH_REQ_OUTER(outer_path);
377 
378  /*
379  * Paths are parameterized by top-level parents, so run parameterization
380  * tests on the parent relids.
381  */
382  if (innerrel->top_parent_relids)
383  innerrelids = innerrel->top_parent_relids;
384  else
385  innerrelids = innerrel->relids;
386 
387  if (outerrel->top_parent_relids)
388  outerrelids = outerrel->top_parent_relids;
389  else
390  outerrelids = outerrel->relids;
391 
392  /*
393  * Check to see if proposed path is still parameterized, and reject if the
394  * parameterization wouldn't be sensible --- unless allow_star_schema_join
395  * says to allow it anyway. Also, we must reject if have_dangerous_phv
396  * doesn't like the look of it, which could only happen if the nestloop is
397  * still parameterized.
398  */
399  required_outer = calc_nestloop_required_outer(outerrelids, outer_paramrels,
400  innerrelids, inner_paramrels);
401  if (required_outer &&
402  ((!bms_overlap(required_outer, extra->param_source_rels) &&
403  !allow_star_schema_join(root, outerrelids, inner_paramrels)) ||
404  have_dangerous_phv(root, outerrelids, inner_paramrels)))
405  {
406  /* Waste no memory when we reject a path here */
407  bms_free(required_outer);
408  return;
409  }
410 
411  /*
412  * Do a precheck to quickly eliminate obviously-inferior paths. We
413  * calculate a cheap lower bound on the path's cost and then use
414  * add_path_precheck() to see if the path is clearly going to be dominated
415  * by some existing path for the joinrel. If not, do the full pushup with
416  * creating a fully valid path structure and submitting it to add_path().
417  * The latter two steps are expensive enough to make this two-phase
418  * methodology worthwhile.
419  */
420  initial_cost_nestloop(root, &workspace, jointype,
421  outer_path, inner_path, extra);
422 
423  if (add_path_precheck(joinrel,
424  workspace.startup_cost, workspace.total_cost,
425  pathkeys, required_outer))
426  {
427  /*
428  * If the inner path is parameterized, it is parameterized by the
429  * topmost parent of the outer rel, not the outer rel itself. Fix
430  * that.
431  */
432  if (PATH_PARAM_BY_PARENT(inner_path, outer_path->parent))
433  {
434  inner_path = reparameterize_path_by_child(root, inner_path,
435  outer_path->parent);
436 
437  /*
438  * If we could not translate the path, we can't create nest loop
439  * path.
440  */
441  if (!inner_path)
442  {
443  bms_free(required_outer);
444  return;
445  }
446  }
447 
448  add_path(joinrel, (Path *)
450  joinrel,
451  jointype,
452  &workspace,
453  extra,
454  outer_path,
455  inner_path,
456  extra->restrictlist,
457  pathkeys,
458  required_outer));
459  }
460  else
461  {
462  /* Waste no memory when we reject a path here */
463  bms_free(required_outer);
464  }
465 }
void add_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:422
bool add_path_precheck(RelOptInfo *parent_rel, Cost startup_cost, Cost total_cost, List *pathkeys, Relids required_outer)
Definition: pathnode.c:657
#define PATH_PARAM_BY_PARENT(path, rel)
Definition: joinpath.c:33
Relids param_source_rels
Definition: relation.h:2285
RelOptInfo * parent
Definition: relation.h:1042
Path * reparameterize_path_by_child(PlannerInfo *root, Path *path, RelOptInfo *child_rel)
Definition: pathnode.c:3568
NestPath * create_nestloop_path(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, JoinCostWorkspace *workspace, JoinPathExtraData *extra, Path *outer_path, Path *inner_path, List *restrict_clauses, List *pathkeys, Relids required_outer)
Definition: pathnode.c:2140
Relids relids
Definition: relation.h:585
List * restrictlist
Definition: relation.h:2280
void bms_free(Bitmapset *a)
Definition: bitmapset.c:245
#define PATH_REQ_OUTER(path)
Definition: relation.h:1061
Relids calc_nestloop_required_outer(Relids outerrelids, Relids outer_paramrels, Relids innerrelids, Relids inner_paramrels)
Definition: pathnode.c:2074
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:487
void initial_cost_nestloop(PlannerInfo *root, JoinCostWorkspace *workspace, JoinType jointype, Path *outer_path, Path *inner_path, JoinPathExtraData *extra)
Definition: costsize.c:2305
static bool allow_star_schema_join(PlannerInfo *root, Relids outerrelids, Relids inner_paramrels)
Definition: joinpath.c:343
bool have_dangerous_phv(PlannerInfo *root, Relids outer_relids, Relids inner_params)
Definition: joinrels.c:1165
Relids top_parent_relids
Definition: relation.h:654

◆ try_partial_hashjoin_path()

static void try_partial_hashjoin_path ( PlannerInfo root,
RelOptInfo joinrel,
Path outer_path,
Path inner_path,
List hashclauses,
JoinType  jointype,
JoinPathExtraData extra,
bool  parallel_hash 
)
static

Definition at line 786 of file joinpath.c.

References add_partial_path(), add_partial_path_precheck(), Assert, bms_is_empty(), create_hashjoin_path(), initial_cost_hashjoin(), RelOptInfo::lateral_relids, NIL, Path::param_info, ParamPathInfo::ppi_req_outer, JoinPathExtraData::restrictlist, and JoinCostWorkspace::total_cost.

Referenced by hash_inner_and_outer().

794 {
795  JoinCostWorkspace workspace;
796 
797  /*
798  * If the inner path is parameterized, the parameterization must be fully
799  * satisfied by the proposed outer path. Parameterized partial paths are
800  * not supported. The caller should already have verified that no
801  * extra_lateral_rels are required here.
802  */
804  if (inner_path->param_info != NULL)
805  {
806  Relids inner_paramrels = inner_path->param_info->ppi_req_outer;
807 
808  if (!bms_is_empty(inner_paramrels))
809  return;
810  }
811 
812  /*
813  * Before creating a path, get a quick lower bound on what it is likely to
814  * cost. Bail out right away if it looks terrible.
815  */
816  initial_cost_hashjoin(root, &workspace, jointype, hashclauses,
817  outer_path, inner_path, extra, true);
818  if (!add_partial_path_precheck(joinrel, workspace.total_cost, NIL))
819  return;
820 
821  /* Might be good enough to be worth trying, so let's try it. */
822  add_partial_path(joinrel, (Path *)
824  joinrel,
825  jointype,
826  &workspace,
827  extra,
828  outer_path,
829  inner_path,
830  parallel_hash,
831  extra->restrictlist,
832  NULL,
833  hashclauses));
834 }
#define NIL
Definition: pg_list.h:69
bool add_partial_path_precheck(RelOptInfo *parent_rel, Cost total_cost, List *pathkeys)
Definition: pathnode.c:886
ParamPathInfo * param_info
Definition: relation.h:1045
HashPath * create_hashjoin_path(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, JoinCostWorkspace *workspace, JoinPathExtraData *extra, Path *outer_path, Path *inner_path, bool parallel_hash, List *restrict_clauses, Relids required_outer, List *hashclauses)
Definition: pathnode.c:2294
void initial_cost_hashjoin(PlannerInfo *root, JoinCostWorkspace *workspace, JoinType jointype, List *hashclauses, Path *outer_path, Path *inner_path, JoinPathExtraData *extra, bool parallel_hash)
Definition: costsize.c:3138
Relids lateral_relids
Definition: relation.h:610
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:707
List * restrictlist
Definition: relation.h:2280
#define Assert(condition)
Definition: c.h:680
void add_partial_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:762
Relids ppi_req_outer
Definition: relation.h:1001

◆ try_partial_mergejoin_path()

static void try_partial_mergejoin_path ( PlannerInfo root,
RelOptInfo joinrel,
Path outer_path,
Path inner_path,
List pathkeys,
List mergeclauses,
List outersortkeys,
List innersortkeys,
JoinType  jointype,
JoinPathExtraData extra 
)
static

Definition at line 650 of file joinpath.c.

References add_partial_path(), add_partial_path_precheck(), Assert, bms_is_empty(), create_mergejoin_path(), initial_cost_mergejoin(), RelOptInfo::lateral_relids, NIL, Path::param_info, Path::pathkeys, pathkeys_contained_in(), ParamPathInfo::ppi_req_outer, JoinPathExtraData::restrictlist, and JoinCostWorkspace::total_cost.

Referenced by sort_inner_and_outer(), and try_mergejoin_path().

660 {
661  JoinCostWorkspace workspace;
662 
663  /*
664  * See comments in try_partial_hashjoin_path().
665  */
667  if (inner_path->param_info != NULL)
668  {
669  Relids inner_paramrels = inner_path->param_info->ppi_req_outer;
670 
671  if (!bms_is_empty(inner_paramrels))
672  return;
673  }
674 
675  /*
676  * If the given paths are already well enough ordered, we can skip doing
677  * an explicit sort.
678  */
679  if (outersortkeys &&
680  pathkeys_contained_in(outersortkeys, outer_path->pathkeys))
681  outersortkeys = NIL;
682  if (innersortkeys &&
683  pathkeys_contained_in(innersortkeys, inner_path->pathkeys))
684  innersortkeys = NIL;
685 
686  /*
687  * See comments in try_partial_nestloop_path().
688  */
689  initial_cost_mergejoin(root, &workspace, jointype, mergeclauses,
690  outer_path, inner_path,
691  outersortkeys, innersortkeys,
692  extra);
693 
694  if (!add_partial_path_precheck(joinrel, workspace.total_cost, pathkeys))
695  return;
696 
697  /* Might be good enough to be worth trying, so let's try it. */
698  add_partial_path(joinrel, (Path *)
700  joinrel,
701  jointype,
702  &workspace,
703  extra,
704  outer_path,
705  inner_path,
706  extra->restrictlist,
707  pathkeys,
708  NULL,
709  mergeclauses,
710  outersortkeys,
711  innersortkeys));
712 }
#define NIL
Definition: pg_list.h:69
bool add_partial_path_precheck(RelOptInfo *parent_rel, Cost total_cost, List *pathkeys)
Definition: pathnode.c:886
ParamPathInfo * param_info
Definition: relation.h:1045
MergePath * create_mergejoin_path(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, JoinCostWorkspace *workspace, JoinPathExtraData *extra, Path *outer_path, Path *inner_path, List *restrict_clauses, List *pathkeys, Relids required_outer, List *mergeclauses, List *outersortkeys, List *innersortkeys)
Definition: pathnode.c:2228
void initial_cost_mergejoin(PlannerInfo *root, JoinCostWorkspace *workspace, JoinType jointype, List *mergeclauses, Path *outer_path, Path *inner_path, List *outersortkeys, List *innersortkeys, JoinPathExtraData *extra)
Definition: costsize.c:2587
Relids lateral_relids
Definition: relation.h:610
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:707
bool pathkeys_contained_in(List *keys1, List *keys2)
Definition: pathkeys.c:317
List * restrictlist
Definition: relation.h:2280
List * pathkeys
Definition: relation.h:1056
#define Assert(condition)
Definition: c.h:680
void add_partial_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:762
Relids ppi_req_outer
Definition: relation.h:1001

◆ try_partial_nestloop_path()

static void try_partial_nestloop_path ( PlannerInfo root,
RelOptInfo joinrel,
Path outer_path,
Path inner_path,
List pathkeys,
JoinType  jointype,
JoinPathExtraData extra 
)
static

Definition at line 473 of file joinpath.c.

References add_partial_path(), add_partial_path_precheck(), Assert, bms_is_empty(), bms_is_subset(), create_nestloop_path(), initial_cost_nestloop(), RelOptInfo::lateral_relids, Path::param_info, Path::parent, PATH_PARAM_BY_PARENT, ParamPathInfo::ppi_req_outer, RelOptInfo::relids, reparameterize_path_by_child(), JoinPathExtraData::restrictlist, RelOptInfo::top_parent_relids, and JoinCostWorkspace::total_cost.

Referenced by consider_parallel_nestloop().

480 {
481  JoinCostWorkspace workspace;
482 
483  /*
484  * If the inner path is parameterized, the parameterization must be fully
485  * satisfied by the proposed outer path. Parameterized partial paths are
486  * not supported. The caller should already have verified that no
487  * extra_lateral_rels are required here.
488  */
490  if (inner_path->param_info != NULL)
491  {
492  Relids inner_paramrels = inner_path->param_info->ppi_req_outer;
493  RelOptInfo *outerrel = outer_path->parent;
494  Relids outerrelids;
495 
496  /*
497  * The inner and outer paths are parameterized, if at all, by the top
498  * level parents, not the child relations, so we must use those relids
499  * for our paramaterization tests.
500  */
501  if (outerrel->top_parent_relids)
502  outerrelids = outerrel->top_parent_relids;
503  else
504  outerrelids = outerrel->relids;
505 
506  if (!bms_is_subset(inner_paramrels, outerrelids))
507  return;
508  }
509 
510  /*
511  * Before creating a path, get a quick lower bound on what it is likely to
512  * cost. Bail out right away if it looks terrible.
513  */
514  initial_cost_nestloop(root, &workspace, jointype,
515  outer_path, inner_path, extra);
516  if (!add_partial_path_precheck(joinrel, workspace.total_cost, pathkeys))
517  return;
518 
519  /*
520  * If the inner path is parameterized, it is parameterized by the topmost
521  * parent of the outer rel, not the outer rel itself. Fix that.
522  */
523  if (PATH_PARAM_BY_PARENT(inner_path, outer_path->parent))
524  {
525  inner_path = reparameterize_path_by_child(root, inner_path,
526  outer_path->parent);
527 
528  /*
529  * If we could not translate the path, we can't create nest loop path.
530  */
531  if (!inner_path)
532  return;
533  }
534 
535  /* Might be good enough to be worth trying, so let's try it. */
536  add_partial_path(joinrel, (Path *)
538  joinrel,
539  jointype,
540  &workspace,
541  extra,
542  outer_path,
543  inner_path,
544  extra->restrictlist,
545  pathkeys,
546  NULL));
547 }
bool add_partial_path_precheck(RelOptInfo *parent_rel, Cost total_cost, List *pathkeys)
Definition: pathnode.c:886
ParamPathInfo * param_info
Definition: relation.h:1045
#define PATH_PARAM_BY_PARENT(path, rel)
Definition: joinpath.c:33
Relids lateral_relids
Definition: relation.h:610
RelOptInfo * parent
Definition: relation.h:1042
Path * reparameterize_path_by_child(PlannerInfo *root, Path *path, RelOptInfo *child_rel)
Definition: pathnode.c:3568
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:352
NestPath * create_nestloop_path(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, JoinCostWorkspace *workspace, JoinPathExtraData *extra, Path *outer_path, Path *inner_path, List *restrict_clauses, List *pathkeys, Relids required_outer)
Definition: pathnode.c:2140
Relids relids
Definition: relation.h:585
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:707
List * restrictlist
Definition: relation.h:2280
#define Assert(condition)
Definition: c.h:680
void add_partial_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:762
void initial_cost_nestloop(PlannerInfo *root, JoinCostWorkspace *workspace, JoinType jointype, Path *outer_path, Path *inner_path, JoinPathExtraData *extra)
Definition: costsize.c:2305
Relids ppi_req_outer
Definition: relation.h:1001
Relids top_parent_relids
Definition: relation.h:654

Variable Documentation

◆ set_join_pathlist_hook

set_join_pathlist_hook_type set_join_pathlist_hook = NULL

Definition at line 27 of file joinpath.c.

Referenced by add_paths_to_joinrel().