PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pathnode.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * pathnode.c
4  * Routines to manipulate pathlists and create path nodes
5  *
6  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  * src/backend/optimizer/util/pathnode.c
12  *
13  *-------------------------------------------------------------------------
14  */
15 #include "postgres.h"
16 
17 #include <math.h>
18 
19 #include "miscadmin.h"
20 #include "nodes/nodeFuncs.h"
21 #include "optimizer/clauses.h"
22 #include "optimizer/cost.h"
23 #include "optimizer/pathnode.h"
24 #include "optimizer/paths.h"
25 #include "optimizer/planmain.h"
26 #include "optimizer/restrictinfo.h"
27 #include "optimizer/var.h"
28 #include "parser/parsetree.h"
29 #include "utils/lsyscache.h"
30 #include "utils/selfuncs.h"
31 
32 
33 typedef enum
34 {
35  COSTS_EQUAL, /* path costs are fuzzily equal */
36  COSTS_BETTER1, /* first path is cheaper than second */
37  COSTS_BETTER2, /* second path is cheaper than first */
38  COSTS_DIFFERENT /* neither path dominates the other on cost */
40 
41 /*
42  * STD_FUZZ_FACTOR is the normal fuzz factor for compare_path_costs_fuzzily.
43  * XXX is it worth making this user-controllable? It provides a tradeoff
44  * between planner runtime and the accuracy of path cost comparisons.
45  */
46 #define STD_FUZZ_FACTOR 1.01
47 
48 static List *translate_sub_tlist(List *tlist, int relid);
49 
50 
51 /*****************************************************************************
52  * MISC. PATH UTILITIES
53  *****************************************************************************/
54 
55 /*
56  * compare_path_costs
57  * Return -1, 0, or +1 according as path1 is cheaper, the same cost,
58  * or more expensive than path2 for the specified criterion.
59  */
60 int
61 compare_path_costs(Path *path1, Path *path2, CostSelector criterion)
62 {
63  if (criterion == STARTUP_COST)
64  {
65  if (path1->startup_cost < path2->startup_cost)
66  return -1;
67  if (path1->startup_cost > path2->startup_cost)
68  return +1;
69 
70  /*
71  * If paths have the same startup cost (not at all unlikely), order
72  * them by total cost.
73  */
74  if (path1->total_cost < path2->total_cost)
75  return -1;
76  if (path1->total_cost > path2->total_cost)
77  return +1;
78  }
79  else
80  {
81  if (path1->total_cost < path2->total_cost)
82  return -1;
83  if (path1->total_cost > path2->total_cost)
84  return +1;
85 
86  /*
87  * If paths have the same total cost, order them by startup cost.
88  */
89  if (path1->startup_cost < path2->startup_cost)
90  return -1;
91  if (path1->startup_cost > path2->startup_cost)
92  return +1;
93  }
94  return 0;
95 }
96 
97 /*
98  * compare_path_fractional_costs
99  * Return -1, 0, or +1 according as path1 is cheaper, the same cost,
100  * or more expensive than path2 for fetching the specified fraction
101  * of the total tuples.
102  *
103  * If fraction is <= 0 or > 1, we interpret it as 1, ie, we select the
104  * path with the cheaper total_cost.
105  */
106 int
108  double fraction)
109 {
110  Cost cost1,
111  cost2;
112 
113  if (fraction <= 0.0 || fraction >= 1.0)
114  return compare_path_costs(path1, path2, TOTAL_COST);
115  cost1 = path1->startup_cost +
116  fraction * (path1->total_cost - path1->startup_cost);
117  cost2 = path2->startup_cost +
118  fraction * (path2->total_cost - path2->startup_cost);
119  if (cost1 < cost2)
120  return -1;
121  if (cost1 > cost2)
122  return +1;
123  return 0;
124 }
125 
126 /*
127  * compare_path_costs_fuzzily
128  * Compare the costs of two paths to see if either can be said to
129  * dominate the other.
130  *
131  * We use fuzzy comparisons so that add_path() can avoid keeping both of
132  * a pair of paths that really have insignificantly different cost.
133  *
134  * The fuzz_factor argument must be 1.0 plus delta, where delta is the
135  * fraction of the smaller cost that is considered to be a significant
136  * difference. For example, fuzz_factor = 1.01 makes the fuzziness limit
137  * be 1% of the smaller cost.
138  *
139  * The two paths are said to have "equal" costs if both startup and total
140  * costs are fuzzily the same. Path1 is said to be better than path2 if
141  * it has fuzzily better startup cost and fuzzily no worse total cost,
142  * or if it has fuzzily better total cost and fuzzily no worse startup cost.
143  * Path2 is better than path1 if the reverse holds. Finally, if one path
144  * is fuzzily better than the other on startup cost and fuzzily worse on
145  * total cost, we just say that their costs are "different", since neither
146  * dominates the other across the whole performance spectrum.
147  *
148  * This function also enforces a policy rule that paths for which the relevant
149  * one of parent->consider_startup and parent->consider_param_startup is false
150  * cannot survive comparisons solely on the grounds of good startup cost, so
151  * we never return COSTS_DIFFERENT when that is true for the total-cost loser.
152  * (But if total costs are fuzzily equal, we compare startup costs anyway,
153  * in hopes of eliminating one path or the other.)
154  */
155 static PathCostComparison
156 compare_path_costs_fuzzily(Path *path1, Path *path2, double fuzz_factor)
157 {
158 #define CONSIDER_PATH_STARTUP_COST(p) \
159  ((p)->param_info == NULL ? (p)->parent->consider_startup : (p)->parent->consider_param_startup)
160 
161  /*
162  * Check total cost first since it's more likely to be different; many
163  * paths have zero startup cost.
164  */
165  if (path1->total_cost > path2->total_cost * fuzz_factor)
166  {
167  /* path1 fuzzily worse on total cost */
168  if (CONSIDER_PATH_STARTUP_COST(path1) &&
169  path2->startup_cost > path1->startup_cost * fuzz_factor)
170  {
171  /* ... but path2 fuzzily worse on startup, so DIFFERENT */
172  return COSTS_DIFFERENT;
173  }
174  /* else path2 dominates */
175  return COSTS_BETTER2;
176  }
177  if (path2->total_cost > path1->total_cost * fuzz_factor)
178  {
179  /* path2 fuzzily worse on total cost */
180  if (CONSIDER_PATH_STARTUP_COST(path2) &&
181  path1->startup_cost > path2->startup_cost * fuzz_factor)
182  {
183  /* ... but path1 fuzzily worse on startup, so DIFFERENT */
184  return COSTS_DIFFERENT;
185  }
186  /* else path1 dominates */
187  return COSTS_BETTER1;
188  }
189  /* fuzzily the same on total cost ... */
190  if (path1->startup_cost > path2->startup_cost * fuzz_factor)
191  {
192  /* ... but path1 fuzzily worse on startup, so path2 wins */
193  return COSTS_BETTER2;
194  }
195  if (path2->startup_cost > path1->startup_cost * fuzz_factor)
196  {
197  /* ... but path2 fuzzily worse on startup, so path1 wins */
198  return COSTS_BETTER1;
199  }
200  /* fuzzily the same on both costs */
201  return COSTS_EQUAL;
202 
203 #undef CONSIDER_PATH_STARTUP_COST
204 }
205 
206 /*
207  * set_cheapest
208  * Find the minimum-cost paths from among a relation's paths,
209  * and save them in the rel's cheapest-path fields.
210  *
211  * cheapest_total_path is normally the cheapest-total-cost unparameterized
212  * path; but if there are no unparameterized paths, we assign it to be the
213  * best (cheapest least-parameterized) parameterized path. However, only
214  * unparameterized paths are considered candidates for cheapest_startup_path,
215  * so that will be NULL if there are no unparameterized paths.
216  *
217  * The cheapest_parameterized_paths list collects all parameterized paths
218  * that have survived the add_path() tournament for this relation. (Since
219  * add_path ignores pathkeys for a parameterized path, these will be paths
220  * that have best cost or best row count for their parameterization. We
221  * may also have both a parallel-safe and a non-parallel-safe path in some
222  * cases for the same parameterization in some cases, but this should be
223  * relatively rare since, most typically, all paths for the same relation
224  * will be parallel-safe or none of them will.)
225  *
226  * cheapest_parameterized_paths always includes the cheapest-total
227  * unparameterized path, too, if there is one; the users of that list find
228  * it more convenient if that's included.
229  *
230  * This is normally called only after we've finished constructing the path
231  * list for the rel node.
232  */
233 void
235 {
236  Path *cheapest_startup_path;
237  Path *cheapest_total_path;
238  Path *best_param_path;
239  List *parameterized_paths;
240  ListCell *p;
241 
242  Assert(IsA(parent_rel, RelOptInfo));
243 
244  if (parent_rel->pathlist == NIL)
245  elog(ERROR, "could not devise a query plan for the given query");
246 
247  cheapest_startup_path = cheapest_total_path = best_param_path = NULL;
248  parameterized_paths = NIL;
249 
250  foreach(p, parent_rel->pathlist)
251  {
252  Path *path = (Path *) lfirst(p);
253  int cmp;
254 
255  if (path->param_info)
256  {
257  /* Parameterized path, so add it to parameterized_paths */
258  parameterized_paths = lappend(parameterized_paths, path);
259 
260  /*
261  * If we have an unparameterized cheapest-total, we no longer care
262  * about finding the best parameterized path, so move on.
263  */
264  if (cheapest_total_path)
265  continue;
266 
267  /*
268  * Otherwise, track the best parameterized path, which is the one
269  * with least total cost among those of the minimum
270  * parameterization.
271  */
272  if (best_param_path == NULL)
273  best_param_path = path;
274  else
275  {
276  switch (bms_subset_compare(PATH_REQ_OUTER(path),
277  PATH_REQ_OUTER(best_param_path)))
278  {
279  case BMS_EQUAL:
280  /* keep the cheaper one */
281  if (compare_path_costs(path, best_param_path,
282  TOTAL_COST) < 0)
283  best_param_path = path;
284  break;
285  case BMS_SUBSET1:
286  /* new path is less-parameterized */
287  best_param_path = path;
288  break;
289  case BMS_SUBSET2:
290  /* old path is less-parameterized, keep it */
291  break;
292  case BMS_DIFFERENT:
293 
294  /*
295  * This means that neither path has the least possible
296  * parameterization for the rel. We'll sit on the old
297  * path until something better comes along.
298  */
299  break;
300  }
301  }
302  }
303  else
304  {
305  /* Unparameterized path, so consider it for cheapest slots */
306  if (cheapest_total_path == NULL)
307  {
308  cheapest_startup_path = cheapest_total_path = path;
309  continue;
310  }
311 
312  /*
313  * If we find two paths of identical costs, try to keep the
314  * better-sorted one. The paths might have unrelated sort
315  * orderings, in which case we can only guess which might be
316  * better to keep, but if one is superior then we definitely
317  * should keep that one.
318  */
319  cmp = compare_path_costs(cheapest_startup_path, path, STARTUP_COST);
320  if (cmp > 0 ||
321  (cmp == 0 &&
322  compare_pathkeys(cheapest_startup_path->pathkeys,
323  path->pathkeys) == PATHKEYS_BETTER2))
324  cheapest_startup_path = path;
325 
326  cmp = compare_path_costs(cheapest_total_path, path, TOTAL_COST);
327  if (cmp > 0 ||
328  (cmp == 0 &&
329  compare_pathkeys(cheapest_total_path->pathkeys,
330  path->pathkeys) == PATHKEYS_BETTER2))
331  cheapest_total_path = path;
332  }
333  }
334 
335  /* Add cheapest unparameterized path, if any, to parameterized_paths */
336  if (cheapest_total_path)
337  parameterized_paths = lcons(cheapest_total_path, parameterized_paths);
338 
339  /*
340  * If there is no unparameterized path, use the best parameterized path as
341  * cheapest_total_path (but not as cheapest_startup_path).
342  */
343  if (cheapest_total_path == NULL)
344  cheapest_total_path = best_param_path;
345  Assert(cheapest_total_path != NULL);
346 
347  parent_rel->cheapest_startup_path = cheapest_startup_path;
348  parent_rel->cheapest_total_path = cheapest_total_path;
349  parent_rel->cheapest_unique_path = NULL; /* computed only if needed */
350  parent_rel->cheapest_parameterized_paths = parameterized_paths;
351 }
352 
353 /*
354  * add_path
355  * Consider a potential implementation path for the specified parent rel,
356  * and add it to the rel's pathlist if it is worthy of consideration.
357  * A path is worthy if it has a better sort order (better pathkeys) or
358  * cheaper cost (on either dimension), or generates fewer rows, than any
359  * existing path that has the same or superset parameterization rels.
360  * We also consider parallel-safe paths more worthy than others.
361  *
362  * We also remove from the rel's pathlist any old paths that are dominated
363  * by new_path --- that is, new_path is cheaper, at least as well ordered,
364  * generates no more rows, requires no outer rels not required by the old
365  * path, and is no less parallel-safe.
366  *
367  * In most cases, a path with a superset parameterization will generate
368  * fewer rows (since it has more join clauses to apply), so that those two
369  * figures of merit move in opposite directions; this means that a path of
370  * one parameterization can seldom dominate a path of another. But such
371  * cases do arise, so we make the full set of checks anyway.
372  *
373  * There are two policy decisions embedded in this function, along with
374  * its sibling add_path_precheck. First, we treat all parameterized paths
375  * as having NIL pathkeys, so that they cannot win comparisons on the
376  * basis of sort order. This is to reduce the number of parameterized
377  * paths that are kept; see discussion in src/backend/optimizer/README.
378  *
379  * Second, we only consider cheap startup cost to be interesting if
380  * parent_rel->consider_startup is true for an unparameterized path, or
381  * parent_rel->consider_param_startup is true for a parameterized one.
382  * Again, this allows discarding useless paths sooner.
383  *
384  * The pathlist is kept sorted by total_cost, with cheaper paths
385  * at the front. Within this routine, that's simply a speed hack:
386  * doing it that way makes it more likely that we will reject an inferior
387  * path after a few comparisons, rather than many comparisons.
388  * However, add_path_precheck relies on this ordering to exit early
389  * when possible.
390  *
391  * NOTE: discarded Path objects are immediately pfree'd to reduce planner
392  * memory consumption. We dare not try to free the substructure of a Path,
393  * since much of it may be shared with other Paths or the query tree itself;
394  * but just recycling discarded Path nodes is a very useful savings in
395  * a large join tree. We can recycle the List nodes of pathlist, too.
396  *
397  * As noted in optimizer/README, deleting a previously-accepted Path is
398  * safe because we know that Paths of this rel cannot yet be referenced
399  * from any other rel, such as a higher-level join. However, in some cases
400  * it is possible that a Path is referenced by another Path for its own
401  * rel; we must not delete such a Path, even if it is dominated by the new
402  * Path. Currently this occurs only for IndexPath objects, which may be
403  * referenced as children of BitmapHeapPaths as well as being paths in
404  * their own right. Hence, we don't pfree IndexPaths when rejecting them.
405  *
406  * 'parent_rel' is the relation entry to which the path corresponds.
407  * 'new_path' is a potential path for parent_rel.
408  *
409  * Returns nothing, but modifies parent_rel->pathlist.
410  */
411 void
412 add_path(RelOptInfo *parent_rel, Path *new_path)
413 {
414  bool accept_new = true; /* unless we find a superior old path */
415  ListCell *insert_after = NULL; /* where to insert new item */
416  List *new_path_pathkeys;
417  ListCell *p1;
418  ListCell *p1_prev;
419  ListCell *p1_next;
420 
421  /*
422  * This is a convenient place to check for query cancel --- no part of the
423  * planner goes very long without calling add_path().
424  */
426 
427  /* Pretend parameterized paths have no pathkeys, per comment above */
428  new_path_pathkeys = new_path->param_info ? NIL : new_path->pathkeys;
429 
430  /*
431  * Loop to check proposed new path against old paths. Note it is possible
432  * for more than one old path to be tossed out because new_path dominates
433  * it.
434  *
435  * We can't use foreach here because the loop body may delete the current
436  * list cell.
437  */
438  p1_prev = NULL;
439  for (p1 = list_head(parent_rel->pathlist); p1 != NULL; p1 = p1_next)
440  {
441  Path *old_path = (Path *) lfirst(p1);
442  bool remove_old = false; /* unless new proves superior */
443  PathCostComparison costcmp;
444  PathKeysComparison keyscmp;
445  BMS_Comparison outercmp;
446 
447  p1_next = lnext(p1);
448 
449  /*
450  * Do a fuzzy cost comparison with standard fuzziness limit.
451  */
452  costcmp = compare_path_costs_fuzzily(new_path, old_path,
454 
455  /*
456  * If the two paths compare differently for startup and total cost,
457  * then we want to keep both, and we can skip comparing pathkeys and
458  * required_outer rels. If they compare the same, proceed with the
459  * other comparisons. Row count is checked last. (We make the tests
460  * in this order because the cost comparison is most likely to turn
461  * out "different", and the pathkeys comparison next most likely. As
462  * explained above, row count very seldom makes a difference, so even
463  * though it's cheap to compare there's not much point in checking it
464  * earlier.)
465  */
466  if (costcmp != COSTS_DIFFERENT)
467  {
468  /* Similarly check to see if either dominates on pathkeys */
469  List *old_path_pathkeys;
470 
471  old_path_pathkeys = old_path->param_info ? NIL : old_path->pathkeys;
472  keyscmp = compare_pathkeys(new_path_pathkeys,
473  old_path_pathkeys);
474  if (keyscmp != PATHKEYS_DIFFERENT)
475  {
476  switch (costcmp)
477  {
478  case COSTS_EQUAL:
479  outercmp = bms_subset_compare(PATH_REQ_OUTER(new_path),
480  PATH_REQ_OUTER(old_path));
481  if (keyscmp == PATHKEYS_BETTER1)
482  {
483  if ((outercmp == BMS_EQUAL ||
484  outercmp == BMS_SUBSET1) &&
485  new_path->rows <= old_path->rows &&
486  new_path->parallel_safe >= old_path->parallel_safe)
487  remove_old = true; /* new dominates old */
488  }
489  else if (keyscmp == PATHKEYS_BETTER2)
490  {
491  if ((outercmp == BMS_EQUAL ||
492  outercmp == BMS_SUBSET2) &&
493  new_path->rows >= old_path->rows &&
494  new_path->parallel_safe <= old_path->parallel_safe)
495  accept_new = false; /* old dominates new */
496  }
497  else /* keyscmp == PATHKEYS_EQUAL */
498  {
499  if (outercmp == BMS_EQUAL)
500  {
501  /*
502  * Same pathkeys and outer rels, and fuzzily
503  * the same cost, so keep just one; to decide
504  * which, first check parallel-safety, then
505  * rows, then do a fuzzy cost comparison with
506  * very small fuzz limit. (We used to do an
507  * exact cost comparison, but that results in
508  * annoying platform-specific plan variations
509  * due to roundoff in the cost estimates.) If
510  * things are still tied, arbitrarily keep
511  * only the old path. Notice that we will
512  * keep only the old path even if the
513  * less-fuzzy comparison decides the startup
514  * and total costs compare differently.
515  */
516  if (new_path->parallel_safe >
517  old_path->parallel_safe)
518  remove_old = true; /* new dominates old */
519  else if (new_path->parallel_safe <
520  old_path->parallel_safe)
521  accept_new = false; /* old dominates new */
522  else if (new_path->rows < old_path->rows)
523  remove_old = true; /* new dominates old */
524  else if (new_path->rows > old_path->rows)
525  accept_new = false; /* old dominates new */
526  else if (compare_path_costs_fuzzily(new_path,
527  old_path,
528  1.0000000001) == COSTS_BETTER1)
529  remove_old = true; /* new dominates old */
530  else
531  accept_new = false; /* old equals or
532  * dominates new */
533  }
534  else if (outercmp == BMS_SUBSET1 &&
535  new_path->rows <= old_path->rows &&
536  new_path->parallel_safe >= old_path->parallel_safe)
537  remove_old = true; /* new dominates old */
538  else if (outercmp == BMS_SUBSET2 &&
539  new_path->rows >= old_path->rows &&
540  new_path->parallel_safe <= old_path->parallel_safe)
541  accept_new = false; /* old dominates new */
542  /* else different parameterizations, keep both */
543  }
544  break;
545  case COSTS_BETTER1:
546  if (keyscmp != PATHKEYS_BETTER2)
547  {
548  outercmp = bms_subset_compare(PATH_REQ_OUTER(new_path),
549  PATH_REQ_OUTER(old_path));
550  if ((outercmp == BMS_EQUAL ||
551  outercmp == BMS_SUBSET1) &&
552  new_path->rows <= old_path->rows &&
553  new_path->parallel_safe >= old_path->parallel_safe)
554  remove_old = true; /* new dominates old */
555  }
556  break;
557  case COSTS_BETTER2:
558  if (keyscmp != PATHKEYS_BETTER1)
559  {
560  outercmp = bms_subset_compare(PATH_REQ_OUTER(new_path),
561  PATH_REQ_OUTER(old_path));
562  if ((outercmp == BMS_EQUAL ||
563  outercmp == BMS_SUBSET2) &&
564  new_path->rows >= old_path->rows &&
565  new_path->parallel_safe <= old_path->parallel_safe)
566  accept_new = false; /* old dominates new */
567  }
568  break;
569  case COSTS_DIFFERENT:
570 
571  /*
572  * can't get here, but keep this case to keep compiler
573  * quiet
574  */
575  break;
576  }
577  }
578  }
579 
580  /*
581  * Remove current element from pathlist if dominated by new.
582  */
583  if (remove_old)
584  {
585  parent_rel->pathlist = list_delete_cell(parent_rel->pathlist,
586  p1, p1_prev);
587 
588  /*
589  * Delete the data pointed-to by the deleted cell, if possible
590  */
591  if (!IsA(old_path, IndexPath))
592  pfree(old_path);
593  /* p1_prev does not advance */
594  }
595  else
596  {
597  /* new belongs after this old path if it has cost >= old's */
598  if (new_path->total_cost >= old_path->total_cost)
599  insert_after = p1;
600  /* p1_prev advances */
601  p1_prev = p1;
602  }
603 
604  /*
605  * If we found an old path that dominates new_path, we can quit
606  * scanning the pathlist; we will not add new_path, and we assume
607  * new_path cannot dominate any other elements of the pathlist.
608  */
609  if (!accept_new)
610  break;
611  }
612 
613  if (accept_new)
614  {
615  /* Accept the new path: insert it at proper place in pathlist */
616  if (insert_after)
617  lappend_cell(parent_rel->pathlist, insert_after, new_path);
618  else
619  parent_rel->pathlist = lcons(new_path, parent_rel->pathlist);
620  }
621  else
622  {
623  /* Reject and recycle the new path */
624  if (!IsA(new_path, IndexPath))
625  pfree(new_path);
626  }
627 }
628 
629 /*
630  * add_path_precheck
631  * Check whether a proposed new path could possibly get accepted.
632  * We assume we know the path's pathkeys and parameterization accurately,
633  * and have lower bounds for its costs.
634  *
635  * Note that we do not know the path's rowcount, since getting an estimate for
636  * that is too expensive to do before prechecking. We assume here that paths
637  * of a superset parameterization will generate fewer rows; if that holds,
638  * then paths with different parameterizations cannot dominate each other
639  * and so we can simply ignore existing paths of another parameterization.
640  * (In the infrequent cases where that rule of thumb fails, add_path will
641  * get rid of the inferior path.)
642  *
643  * At the time this is called, we haven't actually built a Path structure,
644  * so the required information has to be passed piecemeal.
645  */
646 bool
648  Cost startup_cost, Cost total_cost,
649  List *pathkeys, Relids required_outer)
650 {
651  List *new_path_pathkeys;
652  bool consider_startup;
653  ListCell *p1;
654 
655  /* Pretend parameterized paths have no pathkeys, per add_path policy */
656  new_path_pathkeys = required_outer ? NIL : pathkeys;
657 
658  /* Decide whether new path's startup cost is interesting */
659  consider_startup = required_outer ? parent_rel->consider_param_startup : parent_rel->consider_startup;
660 
661  foreach(p1, parent_rel->pathlist)
662  {
663  Path *old_path = (Path *) lfirst(p1);
664  PathKeysComparison keyscmp;
665 
666  /*
667  * We are looking for an old_path with the same parameterization (and
668  * by assumption the same rowcount) that dominates the new path on
669  * pathkeys as well as both cost metrics. If we find one, we can
670  * reject the new path.
671  *
672  * Cost comparisons here should match compare_path_costs_fuzzily.
673  */
674  if (total_cost > old_path->total_cost * STD_FUZZ_FACTOR)
675  {
676  /* new path can win on startup cost only if consider_startup */
677  if (startup_cost > old_path->startup_cost * STD_FUZZ_FACTOR ||
678  !consider_startup)
679  {
680  /* new path loses on cost, so check pathkeys... */
681  List *old_path_pathkeys;
682 
683  old_path_pathkeys = old_path->param_info ? NIL : old_path->pathkeys;
684  keyscmp = compare_pathkeys(new_path_pathkeys,
685  old_path_pathkeys);
686  if (keyscmp == PATHKEYS_EQUAL ||
687  keyscmp == PATHKEYS_BETTER2)
688  {
689  /* new path does not win on pathkeys... */
690  if (bms_equal(required_outer, PATH_REQ_OUTER(old_path)))
691  {
692  /* Found an old path that dominates the new one */
693  return false;
694  }
695  }
696  }
697  }
698  else
699  {
700  /*
701  * Since the pathlist is sorted by total_cost, we can stop looking
702  * once we reach a path with a total_cost larger than the new
703  * path's.
704  */
705  break;
706  }
707  }
708 
709  return true;
710 }
711 
712 /*
713  * add_partial_path
714  * Like add_path, our goal here is to consider whether a path is worthy
715  * of being kept around, but the considerations here are a bit different.
716  * A partial path is one which can be executed in any number of workers in
717  * parallel such that each worker will generate a subset of the path's
718  * overall result.
719  *
720  * As in add_path, the partial_pathlist is kept sorted with the cheapest
721  * total path in front. This is depended on by multiple places, which
722  * just take the front entry as the cheapest path without searching.
723  *
724  * We don't generate parameterized partial paths for several reasons. Most
725  * importantly, they're not safe to execute, because there's nothing to
726  * make sure that a parallel scan within the parameterized portion of the
727  * plan is running with the same value in every worker at the same time.
728  * Fortunately, it seems unlikely to be worthwhile anyway, because having
729  * each worker scan the entire outer relation and a subset of the inner
730  * relation will generally be a terrible plan. The inner (parameterized)
731  * side of the plan will be small anyway. There could be rare cases where
732  * this wins big - e.g. if join order constraints put a 1-row relation on
733  * the outer side of the topmost join with a parameterized plan on the inner
734  * side - but we'll have to be content not to handle such cases until
735  * somebody builds an executor infrastructure that can cope with them.
736  *
737  * Because we don't consider parameterized paths here, we also don't
738  * need to consider the row counts as a measure of quality: every path will
739  * produce the same number of rows. Neither do we need to consider startup
740  * costs: parallelism is only used for plans that will be run to completion.
741  * Therefore, this routine is much simpler than add_path: it needs to
742  * consider only pathkeys and total cost.
743  *
744  * As with add_path, we pfree paths that are found to be dominated by
745  * another partial path; this requires that there be no other references to
746  * such paths yet. Hence, GatherPaths must not be created for a rel until
747  * we're done creating all partial paths for it. Unlike add_path, we don't
748  * take an exception for IndexPaths as partial index paths won't be
749  * referenced by partial BitmapHeapPaths.
750  */
751 void
752 add_partial_path(RelOptInfo *parent_rel, Path *new_path)
753 {
754  bool accept_new = true; /* unless we find a superior old path */
755  ListCell *insert_after = NULL; /* where to insert new item */
756  ListCell *p1;
757  ListCell *p1_prev;
758  ListCell *p1_next;
759 
760  /* Check for query cancel. */
762 
763  /*
764  * As in add_path, throw out any paths which are dominated by the new
765  * path, but throw out the new path if some existing path dominates it.
766  */
767  p1_prev = NULL;
768  for (p1 = list_head(parent_rel->partial_pathlist); p1 != NULL;
769  p1 = p1_next)
770  {
771  Path *old_path = (Path *) lfirst(p1);
772  bool remove_old = false; /* unless new proves superior */
773  PathKeysComparison keyscmp;
774 
775  p1_next = lnext(p1);
776 
777  /* Compare pathkeys. */
778  keyscmp = compare_pathkeys(new_path->pathkeys, old_path->pathkeys);
779 
780  /* Unless pathkeys are incompable, keep just one of the two paths. */
781  if (keyscmp != PATHKEYS_DIFFERENT)
782  {
783  if (new_path->total_cost > old_path->total_cost * STD_FUZZ_FACTOR)
784  {
785  /* New path costs more; keep it only if pathkeys are better. */
786  if (keyscmp != PATHKEYS_BETTER1)
787  accept_new = false;
788  }
789  else if (old_path->total_cost > new_path->total_cost
790  * STD_FUZZ_FACTOR)
791  {
792  /* Old path costs more; keep it only if pathkeys are better. */
793  if (keyscmp != PATHKEYS_BETTER2)
794  remove_old = true;
795  }
796  else if (keyscmp == PATHKEYS_BETTER1)
797  {
798  /* Costs are about the same, new path has better pathkeys. */
799  remove_old = true;
800  }
801  else if (keyscmp == PATHKEYS_BETTER2)
802  {
803  /* Costs are about the same, old path has better pathkeys. */
804  accept_new = false;
805  }
806  else if (old_path->total_cost > new_path->total_cost * 1.0000000001)
807  {
808  /* Pathkeys are the same, and the old path costs more. */
809  remove_old = true;
810  }
811  else
812  {
813  /*
814  * Pathkeys are the same, and new path isn't materially
815  * cheaper.
816  */
817  accept_new = false;
818  }
819  }
820 
821  /*
822  * Remove current element from partial_pathlist if dominated by new.
823  */
824  if (remove_old)
825  {
826  parent_rel->partial_pathlist =
827  list_delete_cell(parent_rel->partial_pathlist, p1, p1_prev);
828  pfree(old_path);
829  /* p1_prev does not advance */
830  }
831  else
832  {
833  /* new belongs after this old path if it has cost >= old's */
834  if (new_path->total_cost >= old_path->total_cost)
835  insert_after = p1;
836  /* p1_prev advances */
837  p1_prev = p1;
838  }
839 
840  /*
841  * If we found an old path that dominates new_path, we can quit
842  * scanning the partial_pathlist; we will not add new_path, and we
843  * assume new_path cannot dominate any later path.
844  */
845  if (!accept_new)
846  break;
847  }
848 
849  if (accept_new)
850  {
851  /* Accept the new path: insert it at proper place */
852  if (insert_after)
853  lappend_cell(parent_rel->partial_pathlist, insert_after, new_path);
854  else
855  parent_rel->partial_pathlist =
856  lcons(new_path, parent_rel->partial_pathlist);
857  }
858  else
859  {
860  /* Reject and recycle the new path */
861  pfree(new_path);
862  }
863 }
864 
865 /*
866  * add_partial_path_precheck
867  * Check whether a proposed new partial path could possibly get accepted.
868  *
869  * Unlike add_path_precheck, we can ignore startup cost and parameterization,
870  * since they don't matter for partial paths (see add_partial_path). But
871  * we do want to make sure we don't add a partial path if there's already
872  * a complete path that dominates it, since in that case the proposed path
873  * is surely a loser.
874  */
875 bool
876 add_partial_path_precheck(RelOptInfo *parent_rel, Cost total_cost,
877  List *pathkeys)
878 {
879  ListCell *p1;
880 
881  /*
882  * Our goal here is twofold. First, we want to find out whether this path
883  * is clearly inferior to some existing partial path. If so, we want to
884  * reject it immediately. Second, we want to find out whether this path
885  * is clearly superior to some existing partial path -- at least, modulo
886  * final cost computations. If so, we definitely want to consider it.
887  *
888  * Unlike add_path(), we always compare pathkeys here. This is because we
889  * expect partial_pathlist to be very short, and getting a definitive
890  * answer at this stage avoids the need to call add_path_precheck.
891  */
892  foreach(p1, parent_rel->partial_pathlist)
893  {
894  Path *old_path = (Path *) lfirst(p1);
895  PathKeysComparison keyscmp;
896 
897  keyscmp = compare_pathkeys(pathkeys, old_path->pathkeys);
898  if (keyscmp != PATHKEYS_DIFFERENT)
899  {
900  if (total_cost > old_path->total_cost * STD_FUZZ_FACTOR &&
901  keyscmp != PATHKEYS_BETTER1)
902  return false;
903  if (old_path->total_cost > total_cost * STD_FUZZ_FACTOR &&
904  keyscmp != PATHKEYS_BETTER2)
905  return true;
906  }
907  }
908 
909  /*
910  * This path is neither clearly inferior to an existing partial path nor
911  * clearly good enough that it might replace one. Compare it to
912  * non-parallel plans. If it loses even before accounting for the cost of
913  * the Gather node, we should definitely reject it.
914  *
915  * Note that we pass the total_cost to add_path_precheck twice. This is
916  * because it's never advantageous to consider the startup cost of a
917  * partial path; the resulting plans, if run in parallel, will be run to
918  * completion.
919  */
920  if (!add_path_precheck(parent_rel, total_cost, total_cost, pathkeys,
921  NULL))
922  return false;
923 
924  return true;
925 }
926 
927 
928 /*****************************************************************************
929  * PATH NODE CREATION ROUTINES
930  *****************************************************************************/
931 
932 /*
933  * create_seqscan_path
934  * Creates a path corresponding to a sequential scan, returning the
935  * pathnode.
936  */
937 Path *
939  Relids required_outer, int parallel_workers)
940 {
941  Path *pathnode = makeNode(Path);
942 
943  pathnode->pathtype = T_SeqScan;
944  pathnode->parent = rel;
945  pathnode->pathtarget = rel->reltarget;
946  pathnode->param_info = get_baserel_parampathinfo(root, rel,
947  required_outer);
948  pathnode->parallel_aware = parallel_workers > 0 ? true : false;
949  pathnode->parallel_safe = rel->consider_parallel;
950  pathnode->parallel_workers = parallel_workers;
951  pathnode->pathkeys = NIL; /* seqscan has unordered result */
952 
953  cost_seqscan(pathnode, root, rel, pathnode->param_info);
954 
955  return pathnode;
956 }
957 
958 /*
959  * create_samplescan_path
960  * Creates a path node for a sampled table scan.
961  */
962 Path *
964 {
965  Path *pathnode = makeNode(Path);
966 
967  pathnode->pathtype = T_SampleScan;
968  pathnode->parent = rel;
969  pathnode->pathtarget = rel->reltarget;
970  pathnode->param_info = get_baserel_parampathinfo(root, rel,
971  required_outer);
972  pathnode->parallel_aware = false;
973  pathnode->parallel_safe = rel->consider_parallel;
974  pathnode->parallel_workers = 0;
975  pathnode->pathkeys = NIL; /* samplescan has unordered result */
976 
977  cost_samplescan(pathnode, root, rel, pathnode->param_info);
978 
979  return pathnode;
980 }
981 
982 /*
983  * create_index_path
984  * Creates a path node for an index scan.
985  *
986  * 'index' is a usable index.
987  * 'indexclauses' is a list of RestrictInfo nodes representing clauses
988  * to be used as index qual conditions in the scan.
989  * 'indexclausecols' is an integer list of index column numbers (zero based)
990  * the indexclauses can be used with.
991  * 'indexorderbys' is a list of bare expressions (no RestrictInfos)
992  * to be used as index ordering operators in the scan.
993  * 'indexorderbycols' is an integer list of index column numbers (zero based)
994  * the ordering operators can be used with.
995  * 'pathkeys' describes the ordering of the path.
996  * 'indexscandir' is ForwardScanDirection or BackwardScanDirection
997  * for an ordered index, or NoMovementScanDirection for
998  * an unordered index.
999  * 'indexonly' is true if an index-only scan is wanted.
1000  * 'required_outer' is the set of outer relids for a parameterized path.
1001  * 'loop_count' is the number of repetitions of the indexscan to factor into
1002  * estimates of caching behavior.
1003  * 'partial_path' is true if constructing a parallel index scan path.
1004  *
1005  * Returns the new path node.
1006  */
1007 IndexPath *
1010  List *indexclauses,
1011  List *indexclausecols,
1012  List *indexorderbys,
1013  List *indexorderbycols,
1014  List *pathkeys,
1015  ScanDirection indexscandir,
1016  bool indexonly,
1017  Relids required_outer,
1018  double loop_count,
1019  bool partial_path)
1020 {
1021  IndexPath *pathnode = makeNode(IndexPath);
1022  RelOptInfo *rel = index->rel;
1023  List *indexquals,
1024  *indexqualcols;
1025 
1026  pathnode->path.pathtype = indexonly ? T_IndexOnlyScan : T_IndexScan;
1027  pathnode->path.parent = rel;
1028  pathnode->path.pathtarget = rel->reltarget;
1029  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1030  required_outer);
1031  pathnode->path.parallel_aware = false;
1032  pathnode->path.parallel_safe = rel->consider_parallel;
1033  pathnode->path.parallel_workers = 0;
1034  pathnode->path.pathkeys = pathkeys;
1035 
1036  /* Convert clauses to indexquals the executor can handle */
1037  expand_indexqual_conditions(index, indexclauses, indexclausecols,
1038  &indexquals, &indexqualcols);
1039 
1040  /* Fill in the pathnode */
1041  pathnode->indexinfo = index;
1042  pathnode->indexclauses = indexclauses;
1043  pathnode->indexquals = indexquals;
1044  pathnode->indexqualcols = indexqualcols;
1045  pathnode->indexorderbys = indexorderbys;
1046  pathnode->indexorderbycols = indexorderbycols;
1047  pathnode->indexscandir = indexscandir;
1048 
1049  cost_index(pathnode, root, loop_count, partial_path);
1050 
1051  return pathnode;
1052 }
1053 
1054 /*
1055  * create_bitmap_heap_path
1056  * Creates a path node for a bitmap scan.
1057  *
1058  * 'bitmapqual' is a tree of IndexPath, BitmapAndPath, and BitmapOrPath nodes.
1059  * 'required_outer' is the set of outer relids for a parameterized path.
1060  * 'loop_count' is the number of repetitions of the indexscan to factor into
1061  * estimates of caching behavior.
1062  *
1063  * loop_count should match the value used when creating the component
1064  * IndexPaths.
1065  */
1068  RelOptInfo *rel,
1069  Path *bitmapqual,
1070  Relids required_outer,
1071  double loop_count)
1072 {
1073  BitmapHeapPath *pathnode = makeNode(BitmapHeapPath);
1074 
1075  pathnode->path.pathtype = T_BitmapHeapScan;
1076  pathnode->path.parent = rel;
1077  pathnode->path.pathtarget = rel->reltarget;
1078  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1079  required_outer);
1080  pathnode->path.parallel_aware = false;
1081  pathnode->path.parallel_safe = rel->consider_parallel;
1082  pathnode->path.parallel_workers = 0;
1083  pathnode->path.pathkeys = NIL; /* always unordered */
1084 
1085  pathnode->bitmapqual = bitmapqual;
1086 
1087  cost_bitmap_heap_scan(&pathnode->path, root, rel,
1088  pathnode->path.param_info,
1089  bitmapqual, loop_count);
1090 
1091  return pathnode;
1092 }
1093 
1094 /*
1095  * create_bitmap_and_path
1096  * Creates a path node representing a BitmapAnd.
1097  */
1098 BitmapAndPath *
1100  RelOptInfo *rel,
1101  List *bitmapquals)
1102 {
1103  BitmapAndPath *pathnode = makeNode(BitmapAndPath);
1104 
1105  pathnode->path.pathtype = T_BitmapAnd;
1106  pathnode->path.parent = rel;
1107  pathnode->path.pathtarget = rel->reltarget;
1108  pathnode->path.param_info = NULL; /* not used in bitmap trees */
1109 
1110  /*
1111  * Currently, a BitmapHeapPath, BitmapAndPath, or BitmapOrPath will be
1112  * parallel-safe if and only if rel->consider_parallel is set. So, we can
1113  * set the flag for this path based only on the relation-level flag,
1114  * without actually iterating over the list of children.
1115  */
1116  pathnode->path.parallel_aware = false;
1117  pathnode->path.parallel_safe = rel->consider_parallel;
1118  pathnode->path.parallel_workers = 0;
1119 
1120  pathnode->path.pathkeys = NIL; /* always unordered */
1121 
1122  pathnode->bitmapquals = bitmapquals;
1123 
1124  /* this sets bitmapselectivity as well as the regular cost fields: */
1125  cost_bitmap_and_node(pathnode, root);
1126 
1127  return pathnode;
1128 }
1129 
1130 /*
1131  * create_bitmap_or_path
1132  * Creates a path node representing a BitmapOr.
1133  */
1134 BitmapOrPath *
1136  RelOptInfo *rel,
1137  List *bitmapquals)
1138 {
1139  BitmapOrPath *pathnode = makeNode(BitmapOrPath);
1140 
1141  pathnode->path.pathtype = T_BitmapOr;
1142  pathnode->path.parent = rel;
1143  pathnode->path.pathtarget = rel->reltarget;
1144  pathnode->path.param_info = NULL; /* not used in bitmap trees */
1145 
1146  /*
1147  * Currently, a BitmapHeapPath, BitmapAndPath, or BitmapOrPath will be
1148  * parallel-safe if and only if rel->consider_parallel is set. So, we can
1149  * set the flag for this path based only on the relation-level flag,
1150  * without actually iterating over the list of children.
1151  */
1152  pathnode->path.parallel_aware = false;
1153  pathnode->path.parallel_safe = rel->consider_parallel;
1154  pathnode->path.parallel_workers = 0;
1155 
1156  pathnode->path.pathkeys = NIL; /* always unordered */
1157 
1158  pathnode->bitmapquals = bitmapquals;
1159 
1160  /* this sets bitmapselectivity as well as the regular cost fields: */
1161  cost_bitmap_or_node(pathnode, root);
1162 
1163  return pathnode;
1164 }
1165 
1166 /*
1167  * create_tidscan_path
1168  * Creates a path corresponding to a scan by TID, returning the pathnode.
1169  */
1170 TidPath *
1172  Relids required_outer)
1173 {
1174  TidPath *pathnode = makeNode(TidPath);
1175 
1176  pathnode->path.pathtype = T_TidScan;
1177  pathnode->path.parent = rel;
1178  pathnode->path.pathtarget = rel->reltarget;
1179  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1180  required_outer);
1181  pathnode->path.parallel_aware = false;
1182  pathnode->path.parallel_safe = rel->consider_parallel;
1183  pathnode->path.parallel_workers = 0;
1184  pathnode->path.pathkeys = NIL; /* always unordered */
1185 
1186  pathnode->tidquals = tidquals;
1187 
1188  cost_tidscan(&pathnode->path, root, rel, tidquals,
1189  pathnode->path.param_info);
1190 
1191  return pathnode;
1192 }
1193 
1194 /*
1195  * create_append_path
1196  * Creates a path corresponding to an Append plan, returning the
1197  * pathnode.
1198  *
1199  * Note that we must handle subpaths = NIL, representing a dummy access path.
1200  */
1201 AppendPath *
1202 create_append_path(RelOptInfo *rel, List *subpaths, Relids required_outer,
1203  int parallel_workers)
1204 {
1205  AppendPath *pathnode = makeNode(AppendPath);
1206  ListCell *l;
1207 
1208  pathnode->path.pathtype = T_Append;
1209  pathnode->path.parent = rel;
1210  pathnode->path.pathtarget = rel->reltarget;
1212  required_outer);
1213  pathnode->path.parallel_aware = false;
1214  pathnode->path.parallel_safe = rel->consider_parallel;
1215  pathnode->path.parallel_workers = parallel_workers;
1216  pathnode->path.pathkeys = NIL; /* result is always considered
1217  * unsorted */
1218  pathnode->subpaths = subpaths;
1219 
1220  /*
1221  * We don't bother with inventing a cost_append(), but just do it here.
1222  *
1223  * Compute rows and costs as sums of subplan rows and costs. We charge
1224  * nothing extra for the Append itself, which perhaps is too optimistic,
1225  * but since it doesn't do any selection or projection, it is a pretty
1226  * cheap node.
1227  */
1228  pathnode->path.rows = 0;
1229  pathnode->path.startup_cost = 0;
1230  pathnode->path.total_cost = 0;
1231  foreach(l, subpaths)
1232  {
1233  Path *subpath = (Path *) lfirst(l);
1234 
1235  pathnode->path.rows += subpath->rows;
1236 
1237  if (l == list_head(subpaths)) /* first node? */
1238  pathnode->path.startup_cost = subpath->startup_cost;
1239  pathnode->path.total_cost += subpath->total_cost;
1240  pathnode->path.parallel_safe = pathnode->path.parallel_safe &&
1241  subpath->parallel_safe;
1242 
1243  /* All child paths must have same parameterization */
1244  Assert(bms_equal(PATH_REQ_OUTER(subpath), required_outer));
1245  }
1246 
1247  return pathnode;
1248 }
1249 
1250 /*
1251  * create_merge_append_path
1252  * Creates a path corresponding to a MergeAppend plan, returning the
1253  * pathnode.
1254  */
1257  RelOptInfo *rel,
1258  List *subpaths,
1259  List *pathkeys,
1260  Relids required_outer)
1261 {
1263  Cost input_startup_cost;
1264  Cost input_total_cost;
1265  ListCell *l;
1266 
1267  pathnode->path.pathtype = T_MergeAppend;
1268  pathnode->path.parent = rel;
1269  pathnode->path.pathtarget = rel->reltarget;
1271  required_outer);
1272  pathnode->path.parallel_aware = false;
1273  pathnode->path.parallel_safe = rel->consider_parallel;
1274  pathnode->path.parallel_workers = 0;
1275  pathnode->path.pathkeys = pathkeys;
1276  pathnode->subpaths = subpaths;
1277 
1278  /*
1279  * Apply query-wide LIMIT if known and path is for sole base relation.
1280  * (Handling this at this low level is a bit klugy.)
1281  */
1282  if (bms_equal(rel->relids, root->all_baserels))
1283  pathnode->limit_tuples = root->limit_tuples;
1284  else
1285  pathnode->limit_tuples = -1.0;
1286 
1287  /*
1288  * Add up the sizes and costs of the input paths.
1289  */
1290  pathnode->path.rows = 0;
1291  input_startup_cost = 0;
1292  input_total_cost = 0;
1293  foreach(l, subpaths)
1294  {
1295  Path *subpath = (Path *) lfirst(l);
1296 
1297  pathnode->path.rows += subpath->rows;
1298  pathnode->path.parallel_safe = pathnode->path.parallel_safe &&
1299  subpath->parallel_safe;
1300 
1301  if (pathkeys_contained_in(pathkeys, subpath->pathkeys))
1302  {
1303  /* Subpath is adequately ordered, we won't need to sort it */
1304  input_startup_cost += subpath->startup_cost;
1305  input_total_cost += subpath->total_cost;
1306  }
1307  else
1308  {
1309  /* We'll need to insert a Sort node, so include cost for that */
1310  Path sort_path; /* dummy for result of cost_sort */
1311 
1312  cost_sort(&sort_path,
1313  root,
1314  pathkeys,
1315  subpath->total_cost,
1316  subpath->parent->tuples,
1317  subpath->pathtarget->width,
1318  0.0,
1319  work_mem,
1320  pathnode->limit_tuples);
1321  input_startup_cost += sort_path.startup_cost;
1322  input_total_cost += sort_path.total_cost;
1323  }
1324 
1325  /* All child paths must have same parameterization */
1326  Assert(bms_equal(PATH_REQ_OUTER(subpath), required_outer));
1327  }
1328 
1329  /* Now we can compute total costs of the MergeAppend */
1330  cost_merge_append(&pathnode->path, root,
1331  pathkeys, list_length(subpaths),
1332  input_startup_cost, input_total_cost,
1333  pathnode->path.rows);
1334 
1335  return pathnode;
1336 }
1337 
1338 /*
1339  * create_result_path
1340  * Creates a path representing a Result-and-nothing-else plan.
1341  *
1342  * This is only used for degenerate cases, such as a query with an empty
1343  * jointree.
1344  */
1345 ResultPath *
1347  PathTarget *target, List *resconstantqual)
1348 {
1349  ResultPath *pathnode = makeNode(ResultPath);
1350 
1351  pathnode->path.pathtype = T_Result;
1352  pathnode->path.parent = rel;
1353  pathnode->path.pathtarget = target;
1354  pathnode->path.param_info = NULL; /* there are no other rels... */
1355  pathnode->path.parallel_aware = false;
1356  pathnode->path.parallel_safe = rel->consider_parallel;
1357  pathnode->path.parallel_workers = 0;
1358  pathnode->path.pathkeys = NIL;
1359  pathnode->quals = resconstantqual;
1360 
1361  /* Hardly worth defining a cost_result() function ... just do it */
1362  pathnode->path.rows = 1;
1363  pathnode->path.startup_cost = target->cost.startup;
1364  pathnode->path.total_cost = target->cost.startup +
1365  cpu_tuple_cost + target->cost.per_tuple;
1366  if (resconstantqual)
1367  {
1368  QualCost qual_cost;
1369 
1370  cost_qual_eval(&qual_cost, resconstantqual, root);
1371  /* resconstantqual is evaluated once at startup */
1372  pathnode->path.startup_cost += qual_cost.startup + qual_cost.per_tuple;
1373  pathnode->path.total_cost += qual_cost.startup + qual_cost.per_tuple;
1374  }
1375 
1376  return pathnode;
1377 }
1378 
1379 /*
1380  * create_material_path
1381  * Creates a path corresponding to a Material plan, returning the
1382  * pathnode.
1383  */
1384 MaterialPath *
1386 {
1387  MaterialPath *pathnode = makeNode(MaterialPath);
1388 
1389  Assert(subpath->parent == rel);
1390 
1391  pathnode->path.pathtype = T_Material;
1392  pathnode->path.parent = rel;
1393  pathnode->path.pathtarget = rel->reltarget;
1394  pathnode->path.param_info = subpath->param_info;
1395  pathnode->path.parallel_aware = false;
1396  pathnode->path.parallel_safe = rel->consider_parallel &&
1397  subpath->parallel_safe;
1398  pathnode->path.parallel_workers = subpath->parallel_workers;
1399  pathnode->path.pathkeys = subpath->pathkeys;
1400 
1401  pathnode->subpath = subpath;
1402 
1403  cost_material(&pathnode->path,
1404  subpath->startup_cost,
1405  subpath->total_cost,
1406  subpath->rows,
1407  subpath->pathtarget->width);
1408 
1409  return pathnode;
1410 }
1411 
1412 /*
1413  * create_unique_path
1414  * Creates a path representing elimination of distinct rows from the
1415  * input data. Distinct-ness is defined according to the needs of the
1416  * semijoin represented by sjinfo. If it is not possible to identify
1417  * how to make the data unique, NULL is returned.
1418  *
1419  * If used at all, this is likely to be called repeatedly on the same rel;
1420  * and the input subpath should always be the same (the cheapest_total path
1421  * for the rel). So we cache the result.
1422  */
1423 UniquePath *
1425  SpecialJoinInfo *sjinfo)
1426 {
1427  UniquePath *pathnode;
1428  Path sort_path; /* dummy for result of cost_sort */
1429  Path agg_path; /* dummy for result of cost_agg */
1430  MemoryContext oldcontext;
1431  int numCols;
1432 
1433  /* Caller made a mistake if subpath isn't cheapest_total ... */
1434  Assert(subpath == rel->cheapest_total_path);
1435  Assert(subpath->parent == rel);
1436  /* ... or if SpecialJoinInfo is the wrong one */
1437  Assert(sjinfo->jointype == JOIN_SEMI);
1438  Assert(bms_equal(rel->relids, sjinfo->syn_righthand));
1439 
1440  /* If result already cached, return it */
1441  if (rel->cheapest_unique_path)
1442  return (UniquePath *) rel->cheapest_unique_path;
1443 
1444  /* If it's not possible to unique-ify, return NULL */
1445  if (!(sjinfo->semi_can_btree || sjinfo->semi_can_hash))
1446  return NULL;
1447 
1448  /*
1449  * We must ensure path struct and subsidiary data are allocated in main
1450  * planning context; otherwise GEQO memory management causes trouble.
1451  */
1452  oldcontext = MemoryContextSwitchTo(root->planner_cxt);
1453 
1454  pathnode = makeNode(UniquePath);
1455 
1456  pathnode->path.pathtype = T_Unique;
1457  pathnode->path.parent = rel;
1458  pathnode->path.pathtarget = rel->reltarget;
1459  pathnode->path.param_info = subpath->param_info;
1460  pathnode->path.parallel_aware = false;
1461  pathnode->path.parallel_safe = rel->consider_parallel &&
1462  subpath->parallel_safe;
1463  pathnode->path.parallel_workers = subpath->parallel_workers;
1464 
1465  /*
1466  * Assume the output is unsorted, since we don't necessarily have pathkeys
1467  * to represent it. (This might get overridden below.)
1468  */
1469  pathnode->path.pathkeys = NIL;
1470 
1471  pathnode->subpath = subpath;
1472  pathnode->in_operators = sjinfo->semi_operators;
1473  pathnode->uniq_exprs = sjinfo->semi_rhs_exprs;
1474 
1475  /*
1476  * If the input is a relation and it has a unique index that proves the
1477  * semi_rhs_exprs are unique, then we don't need to do anything. Note
1478  * that relation_has_unique_index_for automatically considers restriction
1479  * clauses for the rel, as well.
1480  */
1481  if (rel->rtekind == RTE_RELATION && sjinfo->semi_can_btree &&
1483  sjinfo->semi_rhs_exprs,
1484  sjinfo->semi_operators))
1485  {
1486  pathnode->umethod = UNIQUE_PATH_NOOP;
1487  pathnode->path.rows = rel->rows;
1488  pathnode->path.startup_cost = subpath->startup_cost;
1489  pathnode->path.total_cost = subpath->total_cost;
1490  pathnode->path.pathkeys = subpath->pathkeys;
1491 
1492  rel->cheapest_unique_path = (Path *) pathnode;
1493 
1494  MemoryContextSwitchTo(oldcontext);
1495 
1496  return pathnode;
1497  }
1498 
1499  /*
1500  * If the input is a subquery whose output must be unique already, then we
1501  * don't need to do anything. The test for uniqueness has to consider
1502  * exactly which columns we are extracting; for example "SELECT DISTINCT
1503  * x,y" doesn't guarantee that x alone is distinct. So we cannot check for
1504  * this optimization unless semi_rhs_exprs consists only of simple Vars
1505  * referencing subquery outputs. (Possibly we could do something with
1506  * expressions in the subquery outputs, too, but for now keep it simple.)
1507  */
1508  if (rel->rtekind == RTE_SUBQUERY)
1509  {
1510  RangeTblEntry *rte = planner_rt_fetch(rel->relid, root);
1511 
1513  {
1514  List *sub_tlist_colnos;
1515 
1516  sub_tlist_colnos = translate_sub_tlist(sjinfo->semi_rhs_exprs,
1517  rel->relid);
1518 
1519  if (sub_tlist_colnos &&
1521  sub_tlist_colnos,
1522  sjinfo->semi_operators))
1523  {
1524  pathnode->umethod = UNIQUE_PATH_NOOP;
1525  pathnode->path.rows = rel->rows;
1526  pathnode->path.startup_cost = subpath->startup_cost;
1527  pathnode->path.total_cost = subpath->total_cost;
1528  pathnode->path.pathkeys = subpath->pathkeys;
1529 
1530  rel->cheapest_unique_path = (Path *) pathnode;
1531 
1532  MemoryContextSwitchTo(oldcontext);
1533 
1534  return pathnode;
1535  }
1536  }
1537  }
1538 
1539  /* Estimate number of output rows */
1540  pathnode->path.rows = estimate_num_groups(root,
1541  sjinfo->semi_rhs_exprs,
1542  rel->rows,
1543  NULL);
1544  numCols = list_length(sjinfo->semi_rhs_exprs);
1545 
1546  if (sjinfo->semi_can_btree)
1547  {
1548  /*
1549  * Estimate cost for sort+unique implementation
1550  */
1551  cost_sort(&sort_path, root, NIL,
1552  subpath->total_cost,
1553  rel->rows,
1554  subpath->pathtarget->width,
1555  0.0,
1556  work_mem,
1557  -1.0);
1558 
1559  /*
1560  * Charge one cpu_operator_cost per comparison per input tuple. We
1561  * assume all columns get compared at most of the tuples. (XXX
1562  * probably this is an overestimate.) This should agree with
1563  * create_upper_unique_path.
1564  */
1565  sort_path.total_cost += cpu_operator_cost * rel->rows * numCols;
1566  }
1567 
1568  if (sjinfo->semi_can_hash)
1569  {
1570  /*
1571  * Estimate the overhead per hashtable entry at 64 bytes (same as in
1572  * planner.c).
1573  */
1574  int hashentrysize = subpath->pathtarget->width + 64;
1575 
1576  if (hashentrysize * pathnode->path.rows > work_mem * 1024L)
1577  {
1578  /*
1579  * We should not try to hash. Hack the SpecialJoinInfo to
1580  * remember this, in case we come through here again.
1581  */
1582  sjinfo->semi_can_hash = false;
1583  }
1584  else
1585  cost_agg(&agg_path, root,
1586  AGG_HASHED, NULL,
1587  numCols, pathnode->path.rows,
1588  subpath->startup_cost,
1589  subpath->total_cost,
1590  rel->rows);
1591  }
1592 
1593  if (sjinfo->semi_can_btree && sjinfo->semi_can_hash)
1594  {
1595  if (agg_path.total_cost < sort_path.total_cost)
1596  pathnode->umethod = UNIQUE_PATH_HASH;
1597  else
1598  pathnode->umethod = UNIQUE_PATH_SORT;
1599  }
1600  else if (sjinfo->semi_can_btree)
1601  pathnode->umethod = UNIQUE_PATH_SORT;
1602  else if (sjinfo->semi_can_hash)
1603  pathnode->umethod = UNIQUE_PATH_HASH;
1604  else
1605  {
1606  /* we can get here only if we abandoned hashing above */
1607  MemoryContextSwitchTo(oldcontext);
1608  return NULL;
1609  }
1610 
1611  if (pathnode->umethod == UNIQUE_PATH_HASH)
1612  {
1613  pathnode->path.startup_cost = agg_path.startup_cost;
1614  pathnode->path.total_cost = agg_path.total_cost;
1615  }
1616  else
1617  {
1618  pathnode->path.startup_cost = sort_path.startup_cost;
1619  pathnode->path.total_cost = sort_path.total_cost;
1620  }
1621 
1622  rel->cheapest_unique_path = (Path *) pathnode;
1623 
1624  MemoryContextSwitchTo(oldcontext);
1625 
1626  return pathnode;
1627 }
1628 
1629 /*
1630  * translate_sub_tlist - get subquery column numbers represented by tlist
1631  *
1632  * The given targetlist usually contains only Vars referencing the given relid.
1633  * Extract their varattnos (ie, the column numbers of the subquery) and return
1634  * as an integer List.
1635  *
1636  * If any of the tlist items is not a simple Var, we cannot determine whether
1637  * the subquery's uniqueness condition (if any) matches ours, so punt and
1638  * return NIL.
1639  */
1640 static List *
1641 translate_sub_tlist(List *tlist, int relid)
1642 {
1643  List *result = NIL;
1644  ListCell *l;
1645 
1646  foreach(l, tlist)
1647  {
1648  Var *var = (Var *) lfirst(l);
1649 
1650  if (!var || !IsA(var, Var) ||
1651  var->varno != relid)
1652  return NIL; /* punt */
1653 
1654  result = lappend_int(result, var->varattno);
1655  }
1656  return result;
1657 }
1658 
1659 /*
1660  * create_gather_path
1661  * Creates a path corresponding to a gather scan, returning the
1662  * pathnode.
1663  *
1664  * 'rows' may optionally be set to override row estimates from other sources.
1665  */
1666 GatherPath *
1668  PathTarget *target, Relids required_outer, double *rows)
1669 {
1670  GatherPath *pathnode = makeNode(GatherPath);
1671 
1672  Assert(subpath->parallel_safe);
1673 
1674  pathnode->path.pathtype = T_Gather;
1675  pathnode->path.parent = rel;
1676  pathnode->path.pathtarget = target;
1677  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1678  required_outer);
1679  pathnode->path.parallel_aware = false;
1680  pathnode->path.parallel_safe = false;
1681  pathnode->path.parallel_workers = subpath->parallel_workers;
1682  pathnode->path.pathkeys = NIL; /* Gather has unordered result */
1683 
1684  pathnode->subpath = subpath;
1685  pathnode->single_copy = false;
1686 
1687  if (pathnode->path.parallel_workers == 0)
1688  {
1689  pathnode->path.parallel_workers = 1;
1690  pathnode->path.pathkeys = subpath->pathkeys;
1691  pathnode->single_copy = true;
1692  }
1693 
1694  cost_gather(pathnode, root, rel, pathnode->path.param_info, rows);
1695 
1696  return pathnode;
1697 }
1698 
1699 /*
1700  * create_subqueryscan_path
1701  * Creates a path corresponding to a scan of a subquery,
1702  * returning the pathnode.
1703  */
1706  List *pathkeys, Relids required_outer)
1707 {
1709 
1710  pathnode->path.pathtype = T_SubqueryScan;
1711  pathnode->path.parent = rel;
1712  pathnode->path.pathtarget = rel->reltarget;
1713  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1714  required_outer);
1715  pathnode->path.parallel_aware = false;
1716  pathnode->path.parallel_safe = rel->consider_parallel &&
1717  subpath->parallel_safe;
1718  pathnode->path.parallel_workers = subpath->parallel_workers;
1719  pathnode->path.pathkeys = pathkeys;
1720  pathnode->subpath = subpath;
1721 
1722  cost_subqueryscan(pathnode, root, rel, pathnode->path.param_info);
1723 
1724  return pathnode;
1725 }
1726 
1727 /*
1728  * create_functionscan_path
1729  * Creates a path corresponding to a sequential scan of a function,
1730  * returning the pathnode.
1731  */
1732 Path *
1734  List *pathkeys, Relids required_outer)
1735 {
1736  Path *pathnode = makeNode(Path);
1737 
1738  pathnode->pathtype = T_FunctionScan;
1739  pathnode->parent = rel;
1740  pathnode->pathtarget = rel->reltarget;
1741  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1742  required_outer);
1743  pathnode->parallel_aware = false;
1744  pathnode->parallel_safe = rel->consider_parallel;
1745  pathnode->parallel_workers = 0;
1746  pathnode->pathkeys = pathkeys;
1747 
1748  cost_functionscan(pathnode, root, rel, pathnode->param_info);
1749 
1750  return pathnode;
1751 }
1752 
1753 /*
1754  * create_valuesscan_path
1755  * Creates a path corresponding to a scan of a VALUES list,
1756  * returning the pathnode.
1757  */
1758 Path *
1760  Relids required_outer)
1761 {
1762  Path *pathnode = makeNode(Path);
1763 
1764  pathnode->pathtype = T_ValuesScan;
1765  pathnode->parent = rel;
1766  pathnode->pathtarget = rel->reltarget;
1767  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1768  required_outer);
1769  pathnode->parallel_aware = false;
1770  pathnode->parallel_safe = rel->consider_parallel;
1771  pathnode->parallel_workers = 0;
1772  pathnode->pathkeys = NIL; /* result is always unordered */
1773 
1774  cost_valuesscan(pathnode, root, rel, pathnode->param_info);
1775 
1776  return pathnode;
1777 }
1778 
1779 /*
1780  * create_ctescan_path
1781  * Creates a path corresponding to a scan of a non-self-reference CTE,
1782  * returning the pathnode.
1783  */
1784 Path *
1785 create_ctescan_path(PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
1786 {
1787  Path *pathnode = makeNode(Path);
1788 
1789  pathnode->pathtype = T_CteScan;
1790  pathnode->parent = rel;
1791  pathnode->pathtarget = rel->reltarget;
1792  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1793  required_outer);
1794  pathnode->parallel_aware = false;
1795  pathnode->parallel_safe = rel->consider_parallel;
1796  pathnode->parallel_workers = 0;
1797  pathnode->pathkeys = NIL; /* XXX for now, result is always unordered */
1798 
1799  cost_ctescan(pathnode, root, rel, pathnode->param_info);
1800 
1801  return pathnode;
1802 }
1803 
1804 /*
1805  * create_worktablescan_path
1806  * Creates a path corresponding to a scan of a self-reference CTE,
1807  * returning the pathnode.
1808  */
1809 Path *
1811  Relids required_outer)
1812 {
1813  Path *pathnode = makeNode(Path);
1814 
1815  pathnode->pathtype = T_WorkTableScan;
1816  pathnode->parent = rel;
1817  pathnode->pathtarget = rel->reltarget;
1818  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1819  required_outer);
1820  pathnode->parallel_aware = false;
1821  pathnode->parallel_safe = rel->consider_parallel;
1822  pathnode->parallel_workers = 0;
1823  pathnode->pathkeys = NIL; /* result is always unordered */
1824 
1825  /* Cost is the same as for a regular CTE scan */
1826  cost_ctescan(pathnode, root, rel, pathnode->param_info);
1827 
1828  return pathnode;
1829 }
1830 
1831 /*
1832  * create_foreignscan_path
1833  * Creates a path corresponding to a scan of a foreign table, foreign join,
1834  * or foreign upper-relation processing, returning the pathnode.
1835  *
1836  * This function is never called from core Postgres; rather, it's expected
1837  * to be called by the GetForeignPaths, GetForeignJoinPaths, or
1838  * GetForeignUpperPaths function of a foreign data wrapper. We make the FDW
1839  * supply all fields of the path, since we do not have any way to calculate
1840  * them in core. However, there is a usually-sane default for the pathtarget
1841  * (rel->reltarget), so we let a NULL for "target" select that.
1842  */
1843 ForeignPath *
1845  PathTarget *target,
1846  double rows, Cost startup_cost, Cost total_cost,
1847  List *pathkeys,
1848  Relids required_outer,
1849  Path *fdw_outerpath,
1850  List *fdw_private)
1851 {
1852  ForeignPath *pathnode = makeNode(ForeignPath);
1853 
1854  pathnode->path.pathtype = T_ForeignScan;
1855  pathnode->path.parent = rel;
1856  pathnode->path.pathtarget = target ? target : rel->reltarget;
1857  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1858  required_outer);
1859  pathnode->path.parallel_aware = false;
1860  pathnode->path.parallel_safe = rel->consider_parallel;
1861  pathnode->path.parallel_workers = 0;
1862  pathnode->path.rows = rows;
1863  pathnode->path.startup_cost = startup_cost;
1864  pathnode->path.total_cost = total_cost;
1865  pathnode->path.pathkeys = pathkeys;
1866 
1867  pathnode->fdw_outerpath = fdw_outerpath;
1868  pathnode->fdw_private = fdw_private;
1869 
1870  return pathnode;
1871 }
1872 
1873 /*
1874  * calc_nestloop_required_outer
1875  * Compute the required_outer set for a nestloop join path
1876  *
1877  * Note: result must not share storage with either input
1878  */
1879 Relids
1880 calc_nestloop_required_outer(Path *outer_path, Path *inner_path)
1881 {
1882  Relids outer_paramrels = PATH_REQ_OUTER(outer_path);
1883  Relids inner_paramrels = PATH_REQ_OUTER(inner_path);
1884  Relids required_outer;
1885 
1886  /* inner_path can require rels from outer path, but not vice versa */
1887  Assert(!bms_overlap(outer_paramrels, inner_path->parent->relids));
1888  /* easy case if inner path is not parameterized */
1889  if (!inner_paramrels)
1890  return bms_copy(outer_paramrels);
1891  /* else, form the union ... */
1892  required_outer = bms_union(outer_paramrels, inner_paramrels);
1893  /* ... and remove any mention of now-satisfied outer rels */
1894  required_outer = bms_del_members(required_outer,
1895  outer_path->parent->relids);
1896  /* maintain invariant that required_outer is exactly NULL if empty */
1897  if (bms_is_empty(required_outer))
1898  {
1899  bms_free(required_outer);
1900  required_outer = NULL;
1901  }
1902  return required_outer;
1903 }
1904 
1905 /*
1906  * calc_non_nestloop_required_outer
1907  * Compute the required_outer set for a merge or hash join path
1908  *
1909  * Note: result must not share storage with either input
1910  */
1911 Relids
1912 calc_non_nestloop_required_outer(Path *outer_path, Path *inner_path)
1913 {
1914  Relids outer_paramrels = PATH_REQ_OUTER(outer_path);
1915  Relids inner_paramrels = PATH_REQ_OUTER(inner_path);
1916  Relids required_outer;
1917 
1918  /* neither path can require rels from the other */
1919  Assert(!bms_overlap(outer_paramrels, inner_path->parent->relids));
1920  Assert(!bms_overlap(inner_paramrels, outer_path->parent->relids));
1921  /* form the union ... */
1922  required_outer = bms_union(outer_paramrels, inner_paramrels);
1923  /* we do not need an explicit test for empty; bms_union gets it right */
1924  return required_outer;
1925 }
1926 
1927 /*
1928  * create_nestloop_path
1929  * Creates a pathnode corresponding to a nestloop join between two
1930  * relations.
1931  *
1932  * 'joinrel' is the join relation.
1933  * 'jointype' is the type of join required
1934  * 'workspace' is the result from initial_cost_nestloop
1935  * 'sjinfo' is extra info about the join for selectivity estimation
1936  * 'semifactors' contains valid data if jointype is SEMI or ANTI
1937  * 'outer_path' is the outer path
1938  * 'inner_path' is the inner path
1939  * 'restrict_clauses' are the RestrictInfo nodes to apply at the join
1940  * 'pathkeys' are the path keys of the new join path
1941  * 'required_outer' is the set of required outer rels
1942  *
1943  * Returns the resulting path node.
1944  */
1945 NestPath *
1947  RelOptInfo *joinrel,
1948  JoinType jointype,
1949  JoinCostWorkspace *workspace,
1950  SpecialJoinInfo *sjinfo,
1951  SemiAntiJoinFactors *semifactors,
1952  Path *outer_path,
1953  Path *inner_path,
1954  List *restrict_clauses,
1955  List *pathkeys,
1956  Relids required_outer)
1957 {
1958  NestPath *pathnode = makeNode(NestPath);
1959  Relids inner_req_outer = PATH_REQ_OUTER(inner_path);
1960 
1961  /*
1962  * If the inner path is parameterized by the outer, we must drop any
1963  * restrict_clauses that are due to be moved into the inner path. We have
1964  * to do this now, rather than postpone the work till createplan time,
1965  * because the restrict_clauses list can affect the size and cost
1966  * estimates for this path.
1967  */
1968  if (bms_overlap(inner_req_outer, outer_path->parent->relids))
1969  {
1970  Relids inner_and_outer = bms_union(inner_path->parent->relids,
1971  inner_req_outer);
1972  List *jclauses = NIL;
1973  ListCell *lc;
1974 
1975  foreach(lc, restrict_clauses)
1976  {
1977  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
1978 
1979  if (!join_clause_is_movable_into(rinfo,
1980  inner_path->parent->relids,
1981  inner_and_outer))
1982  jclauses = lappend(jclauses, rinfo);
1983  }
1984  restrict_clauses = jclauses;
1985  }
1986 
1987  pathnode->path.pathtype = T_NestLoop;
1988  pathnode->path.parent = joinrel;
1989  pathnode->path.pathtarget = joinrel->reltarget;
1990  pathnode->path.param_info =
1992  joinrel,
1993  outer_path,
1994  inner_path,
1995  sjinfo,
1996  required_outer,
1997  &restrict_clauses);
1998  pathnode->path.parallel_aware = false;
1999  pathnode->path.parallel_safe = joinrel->consider_parallel &&
2000  outer_path->parallel_safe && inner_path->parallel_safe;
2001  /* This is a foolish way to estimate parallel_workers, but for now... */
2002  pathnode->path.parallel_workers = outer_path->parallel_workers;
2003  pathnode->path.pathkeys = pathkeys;
2004  pathnode->jointype = jointype;
2005  pathnode->outerjoinpath = outer_path;
2006  pathnode->innerjoinpath = inner_path;
2007  pathnode->joinrestrictinfo = restrict_clauses;
2008 
2009  final_cost_nestloop(root, pathnode, workspace, sjinfo, semifactors);
2010 
2011  return pathnode;
2012 }
2013 
2014 /*
2015  * create_mergejoin_path
2016  * Creates a pathnode corresponding to a mergejoin join between
2017  * two relations
2018  *
2019  * 'joinrel' is the join relation
2020  * 'jointype' is the type of join required
2021  * 'workspace' is the result from initial_cost_mergejoin
2022  * 'sjinfo' is extra info about the join for selectivity estimation
2023  * 'outer_path' is the outer path
2024  * 'inner_path' is the inner path
2025  * 'restrict_clauses' are the RestrictInfo nodes to apply at the join
2026  * 'pathkeys' are the path keys of the new join path
2027  * 'required_outer' is the set of required outer rels
2028  * 'mergeclauses' are the RestrictInfo nodes to use as merge clauses
2029  * (this should be a subset of the restrict_clauses list)
2030  * 'outersortkeys' are the sort varkeys for the outer relation
2031  * 'innersortkeys' are the sort varkeys for the inner relation
2032  */
2033 MergePath *
2035  RelOptInfo *joinrel,
2036  JoinType jointype,
2037  JoinCostWorkspace *workspace,
2038  SpecialJoinInfo *sjinfo,
2039  Path *outer_path,
2040  Path *inner_path,
2041  List *restrict_clauses,
2042  List *pathkeys,
2043  Relids required_outer,
2044  List *mergeclauses,
2045  List *outersortkeys,
2046  List *innersortkeys)
2047 {
2048  MergePath *pathnode = makeNode(MergePath);
2049 
2050  pathnode->jpath.path.pathtype = T_MergeJoin;
2051  pathnode->jpath.path.parent = joinrel;
2052  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2053  pathnode->jpath.path.param_info =
2055  joinrel,
2056  outer_path,
2057  inner_path,
2058  sjinfo,
2059  required_outer,
2060  &restrict_clauses);
2061  pathnode->jpath.path.parallel_aware = false;
2062  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2063  outer_path->parallel_safe && inner_path->parallel_safe;
2064  /* This is a foolish way to estimate parallel_workers, but for now... */
2065  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2066  pathnode->jpath.path.pathkeys = pathkeys;
2067  pathnode->jpath.jointype = jointype;
2068  pathnode->jpath.outerjoinpath = outer_path;
2069  pathnode->jpath.innerjoinpath = inner_path;
2070  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2071  pathnode->path_mergeclauses = mergeclauses;
2072  pathnode->outersortkeys = outersortkeys;
2073  pathnode->innersortkeys = innersortkeys;
2074  /* pathnode->materialize_inner will be set by final_cost_mergejoin */
2075 
2076  final_cost_mergejoin(root, pathnode, workspace, sjinfo);
2077 
2078  return pathnode;
2079 }
2080 
2081 /*
2082  * create_hashjoin_path
2083  * Creates a pathnode corresponding to a hash join between two relations.
2084  *
2085  * 'joinrel' is the join relation
2086  * 'jointype' is the type of join required
2087  * 'workspace' is the result from initial_cost_hashjoin
2088  * 'sjinfo' is extra info about the join for selectivity estimation
2089  * 'semifactors' contains valid data if jointype is SEMI or ANTI
2090  * 'outer_path' is the cheapest outer path
2091  * 'inner_path' is the cheapest inner path
2092  * 'restrict_clauses' are the RestrictInfo nodes to apply at the join
2093  * 'required_outer' is the set of required outer rels
2094  * 'hashclauses' are the RestrictInfo nodes to use as hash clauses
2095  * (this should be a subset of the restrict_clauses list)
2096  */
2097 HashPath *
2099  RelOptInfo *joinrel,
2100  JoinType jointype,
2101  JoinCostWorkspace *workspace,
2102  SpecialJoinInfo *sjinfo,
2103  SemiAntiJoinFactors *semifactors,
2104  Path *outer_path,
2105  Path *inner_path,
2106  List *restrict_clauses,
2107  Relids required_outer,
2108  List *hashclauses)
2109 {
2110  HashPath *pathnode = makeNode(HashPath);
2111 
2112  pathnode->jpath.path.pathtype = T_HashJoin;
2113  pathnode->jpath.path.parent = joinrel;
2114  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2115  pathnode->jpath.path.param_info =
2117  joinrel,
2118  outer_path,
2119  inner_path,
2120  sjinfo,
2121  required_outer,
2122  &restrict_clauses);
2123  pathnode->jpath.path.parallel_aware = false;
2124  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2125  outer_path->parallel_safe && inner_path->parallel_safe;
2126  /* This is a foolish way to estimate parallel_workers, but for now... */
2127  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2128 
2129  /*
2130  * A hashjoin never has pathkeys, since its output ordering is
2131  * unpredictable due to possible batching. XXX If the inner relation is
2132  * small enough, we could instruct the executor that it must not batch,
2133  * and then we could assume that the output inherits the outer relation's
2134  * ordering, which might save a sort step. However there is considerable
2135  * downside if our estimate of the inner relation size is badly off. For
2136  * the moment we don't risk it. (Note also that if we wanted to take this
2137  * seriously, joinpath.c would have to consider many more paths for the
2138  * outer rel than it does now.)
2139  */
2140  pathnode->jpath.path.pathkeys = NIL;
2141  pathnode->jpath.jointype = jointype;
2142  pathnode->jpath.outerjoinpath = outer_path;
2143  pathnode->jpath.innerjoinpath = inner_path;
2144  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2145  pathnode->path_hashclauses = hashclauses;
2146  /* final_cost_hashjoin will fill in pathnode->num_batches */
2147 
2148  final_cost_hashjoin(root, pathnode, workspace, sjinfo, semifactors);
2149 
2150  return pathnode;
2151 }
2152 
2153 /*
2154  * create_projection_path
2155  * Creates a pathnode that represents performing a projection.
2156  *
2157  * 'rel' is the parent relation associated with the result
2158  * 'subpath' is the path representing the source of data
2159  * 'target' is the PathTarget to be computed
2160  */
2163  RelOptInfo *rel,
2164  Path *subpath,
2165  PathTarget *target)
2166 {
2167  ProjectionPath *pathnode = makeNode(ProjectionPath);
2168  PathTarget *oldtarget = subpath->pathtarget;
2169 
2170  pathnode->path.pathtype = T_Result;
2171  pathnode->path.parent = rel;
2172  pathnode->path.pathtarget = target;
2173  /* For now, assume we are above any joins, so no parameterization */
2174  pathnode->path.param_info = NULL;
2175  pathnode->path.parallel_aware = false;
2176  pathnode->path.parallel_safe = rel->consider_parallel &&
2177  subpath->parallel_safe &&
2178  is_parallel_safe(root, (Node *) target->exprs);
2179  pathnode->path.parallel_workers = subpath->parallel_workers;
2180  /* Projection does not change the sort order */
2181  pathnode->path.pathkeys = subpath->pathkeys;
2182 
2183  pathnode->subpath = subpath;
2184 
2185  /*
2186  * We might not need a separate Result node. If the input plan node type
2187  * can project, we can just tell it to project something else. Or, if it
2188  * can't project but the desired target has the same expression list as
2189  * what the input will produce anyway, we can still give it the desired
2190  * tlist (possibly changing its ressortgroupref labels, but nothing else).
2191  * Note: in the latter case, create_projection_plan has to recheck our
2192  * conclusion; see comments therein.
2193  */
2194  if (is_projection_capable_path(subpath) ||
2195  equal(oldtarget->exprs, target->exprs))
2196  {
2197  /* No separate Result node needed */
2198  pathnode->dummypp = true;
2199 
2200  /*
2201  * Set cost of plan as subpath's cost, adjusted for tlist replacement.
2202  */
2203  pathnode->path.rows = subpath->rows;
2204  pathnode->path.startup_cost = subpath->startup_cost +
2205  (target->cost.startup - oldtarget->cost.startup);
2206  pathnode->path.total_cost = subpath->total_cost +
2207  (target->cost.startup - oldtarget->cost.startup) +
2208  (target->cost.per_tuple - oldtarget->cost.per_tuple) * subpath->rows;
2209  }
2210  else
2211  {
2212  /* We really do need the Result node */
2213  pathnode->dummypp = false;
2214 
2215  /*
2216  * The Result node's cost is cpu_tuple_cost per row, plus the cost of
2217  * evaluating the tlist. There is no qual to worry about.
2218  */
2219  pathnode->path.rows = subpath->rows;
2220  pathnode->path.startup_cost = subpath->startup_cost +
2221  target->cost.startup;
2222  pathnode->path.total_cost = subpath->total_cost +
2223  target->cost.startup +
2224  (cpu_tuple_cost + target->cost.per_tuple) * subpath->rows;
2225  }
2226 
2227  return pathnode;
2228 }
2229 
2230 /*
2231  * apply_projection_to_path
2232  * Add a projection step, or just apply the target directly to given path.
2233  *
2234  * This has the same net effect as create_projection_path(), except that if
2235  * a separate Result plan node isn't needed, we just replace the given path's
2236  * pathtarget with the desired one. This must be used only when the caller
2237  * knows that the given path isn't referenced elsewhere and so can be modified
2238  * in-place.
2239  *
2240  * If the input path is a GatherPath, we try to push the new target down to
2241  * its input as well; this is a yet more invasive modification of the input
2242  * path, which create_projection_path() can't do.
2243  *
2244  * Note that we mustn't change the source path's parent link; so when it is
2245  * add_path'd to "rel" things will be a bit inconsistent. So far that has
2246  * not caused any trouble.
2247  *
2248  * 'rel' is the parent relation associated with the result
2249  * 'path' is the path representing the source of data
2250  * 'target' is the PathTarget to be computed
2251  */
2252 Path *
2254  RelOptInfo *rel,
2255  Path *path,
2256  PathTarget *target)
2257 {
2258  QualCost oldcost;
2259 
2260  /*
2261  * If given path can't project, we might need a Result node, so make a
2262  * separate ProjectionPath.
2263  */
2264  if (!is_projection_capable_path(path))
2265  return (Path *) create_projection_path(root, rel, path, target);
2266 
2267  /*
2268  * We can just jam the desired tlist into the existing path, being sure to
2269  * update its cost estimates appropriately.
2270  */
2271  oldcost = path->pathtarget->cost;
2272  path->pathtarget = target;
2273 
2274  path->startup_cost += target->cost.startup - oldcost.startup;
2275  path->total_cost += target->cost.startup - oldcost.startup +
2276  (target->cost.per_tuple - oldcost.per_tuple) * path->rows;
2277 
2278  /*
2279  * If the path happens to be a Gather path, we'd like to arrange for the
2280  * subpath to return the required target list so that workers can help
2281  * project. But if there is something that is not parallel-safe in the
2282  * target expressions, then we can't.
2283  */
2284  if (IsA(path, GatherPath) &&
2285  is_parallel_safe(root, (Node *) target->exprs))
2286  {
2287  GatherPath *gpath = (GatherPath *) path;
2288 
2289  /*
2290  * We always use create_projection_path here, even if the subpath is
2291  * projection-capable, so as to avoid modifying the subpath in place.
2292  * It seems unlikely at present that there could be any other
2293  * references to the subpath, but better safe than sorry.
2294  *
2295  * Note that we don't change the GatherPath's cost estimates; it might
2296  * be appropriate to do so, to reflect the fact that the bulk of the
2297  * target evaluation will happen in workers.
2298  */
2299  gpath->subpath = (Path *)
2301  gpath->subpath->parent,
2302  gpath->subpath,
2303  target);
2304  }
2305  else if (path->parallel_safe &&
2306  !is_parallel_safe(root, (Node *) target->exprs))
2307  {
2308  /*
2309  * We're inserting a parallel-restricted target list into a path
2310  * currently marked parallel-safe, so we have to mark it as no longer
2311  * safe.
2312  */
2313  path->parallel_safe = false;
2314  }
2315 
2316  return path;
2317 }
2318 
2319 /*
2320  * create_set_projection_path
2321  * Creates a pathnode that represents performing a projection that
2322  * includes set-returning functions.
2323  *
2324  * 'rel' is the parent relation associated with the result
2325  * 'subpath' is the path representing the source of data
2326  * 'target' is the PathTarget to be computed
2327  */
2330  RelOptInfo *rel,
2331  Path *subpath,
2332  PathTarget *target)
2333 {
2334  ProjectSetPath *pathnode = makeNode(ProjectSetPath);
2335  double tlist_rows;
2336  ListCell *lc;
2337 
2338  pathnode->path.pathtype = T_ProjectSet;
2339  pathnode->path.parent = rel;
2340  pathnode->path.pathtarget = target;
2341  /* For now, assume we are above any joins, so no parameterization */
2342  pathnode->path.param_info = NULL;
2343  pathnode->path.parallel_aware = false;
2344  pathnode->path.parallel_safe = rel->consider_parallel &&
2345  subpath->parallel_safe &&
2346  is_parallel_safe(root, (Node *) target->exprs);
2347  pathnode->path.parallel_workers = subpath->parallel_workers;
2348  /* Projection does not change the sort order XXX? */
2349  pathnode->path.pathkeys = subpath->pathkeys;
2350 
2351  pathnode->subpath = subpath;
2352 
2353  /*
2354  * Estimate number of rows produced by SRFs for each row of input; if
2355  * there's more than one in this node, use the maximum.
2356  */
2357  tlist_rows = 1;
2358  foreach(lc, target->exprs)
2359  {
2360  Node *node = (Node *) lfirst(lc);
2361  double itemrows;
2362 
2363  itemrows = expression_returns_set_rows(node);
2364  if (tlist_rows < itemrows)
2365  tlist_rows = itemrows;
2366  }
2367 
2368  /*
2369  * In addition to the cost of evaluating the tlist, charge cpu_tuple_cost
2370  * per input row, and half of cpu_tuple_cost for each added output row.
2371  * This is slightly bizarre maybe, but it's what 9.6 did; we may revisit
2372  * this estimate later.
2373  */
2374  pathnode->path.rows = subpath->rows * tlist_rows;
2375  pathnode->path.startup_cost = subpath->startup_cost +
2376  target->cost.startup;
2377  pathnode->path.total_cost = subpath->total_cost +
2378  target->cost.startup +
2379  (cpu_tuple_cost + target->cost.per_tuple) * subpath->rows +
2380  (pathnode->path.rows - subpath->rows) * cpu_tuple_cost / 2;
2381 
2382  return pathnode;
2383 }
2384 
2385 /*
2386  * create_sort_path
2387  * Creates a pathnode that represents performing an explicit sort.
2388  *
2389  * 'rel' is the parent relation associated with the result
2390  * 'subpath' is the path representing the source of data
2391  * 'pathkeys' represents the desired sort order
2392  * 'limit_tuples' is the estimated bound on the number of output tuples,
2393  * or -1 if no LIMIT or couldn't estimate
2394  */
2395 SortPath *
2397  RelOptInfo *rel,
2398  Path *subpath,
2399  List *pathkeys,
2400  double limit_tuples)
2401 {
2402  SortPath *pathnode = makeNode(SortPath);
2403 
2404  pathnode->path.pathtype = T_Sort;
2405  pathnode->path.parent = rel;
2406  /* Sort doesn't project, so use source path's pathtarget */
2407  pathnode->path.pathtarget = subpath->pathtarget;
2408  /* For now, assume we are above any joins, so no parameterization */
2409  pathnode->path.param_info = NULL;
2410  pathnode->path.parallel_aware = false;
2411  pathnode->path.parallel_safe = rel->consider_parallel &&
2412  subpath->parallel_safe;
2413  pathnode->path.parallel_workers = subpath->parallel_workers;
2414  pathnode->path.pathkeys = pathkeys;
2415 
2416  pathnode->subpath = subpath;
2417 
2418  cost_sort(&pathnode->path, root, pathkeys,
2419  subpath->total_cost,
2420  subpath->rows,
2421  subpath->pathtarget->width,
2422  0.0, /* XXX comparison_cost shouldn't be 0? */
2423  work_mem, limit_tuples);
2424 
2425  return pathnode;
2426 }
2427 
2428 /*
2429  * create_group_path
2430  * Creates a pathnode that represents performing grouping of presorted input
2431  *
2432  * 'rel' is the parent relation associated with the result
2433  * 'subpath' is the path representing the source of data
2434  * 'target' is the PathTarget to be computed
2435  * 'groupClause' is a list of SortGroupClause's representing the grouping
2436  * 'qual' is the HAVING quals if any
2437  * 'numGroups' is the estimated number of groups
2438  */
2439 GroupPath *
2441  RelOptInfo *rel,
2442  Path *subpath,
2443  PathTarget *target,
2444  List *groupClause,
2445  List *qual,
2446  double numGroups)
2447 {
2448  GroupPath *pathnode = makeNode(GroupPath);
2449 
2450  pathnode->path.pathtype = T_Group;
2451  pathnode->path.parent = rel;
2452  pathnode->path.pathtarget = target;
2453  /* For now, assume we are above any joins, so no parameterization */
2454  pathnode->path.param_info = NULL;
2455  pathnode->path.parallel_aware = false;
2456  pathnode->path.parallel_safe = rel->consider_parallel &&
2457  subpath->parallel_safe;
2458  pathnode->path.parallel_workers = subpath->parallel_workers;
2459  /* Group doesn't change sort ordering */
2460  pathnode->path.pathkeys = subpath->pathkeys;
2461 
2462  pathnode->subpath = subpath;
2463 
2464  pathnode->groupClause = groupClause;
2465  pathnode->qual = qual;
2466 
2467  cost_group(&pathnode->path, root,
2468  list_length(groupClause),
2469  numGroups,
2470  subpath->startup_cost, subpath->total_cost,
2471  subpath->rows);
2472 
2473  /* add tlist eval cost for each output row */
2474  pathnode->path.startup_cost += target->cost.startup;
2475  pathnode->path.total_cost += target->cost.startup +
2476  target->cost.per_tuple * pathnode->path.rows;
2477 
2478  return pathnode;
2479 }
2480 
2481 /*
2482  * create_upper_unique_path
2483  * Creates a pathnode that represents performing an explicit Unique step
2484  * on presorted input.
2485  *
2486  * This produces a Unique plan node, but the use-case is so different from
2487  * create_unique_path that it doesn't seem worth trying to merge the two.
2488  *
2489  * 'rel' is the parent relation associated with the result
2490  * 'subpath' is the path representing the source of data
2491  * 'numCols' is the number of grouping columns
2492  * 'numGroups' is the estimated number of groups
2493  *
2494  * The input path must be sorted on the grouping columns, plus possibly
2495  * additional columns; so the first numCols pathkeys are the grouping columns
2496  */
2499  RelOptInfo *rel,
2500  Path *subpath,
2501  int numCols,
2502  double numGroups)
2503 {
2505 
2506  pathnode->path.pathtype = T_Unique;
2507  pathnode->path.parent = rel;
2508  /* Unique doesn't project, so use source path's pathtarget */
2509  pathnode->path.pathtarget = subpath->pathtarget;
2510  /* For now, assume we are above any joins, so no parameterization */
2511  pathnode->path.param_info = NULL;
2512  pathnode->path.parallel_aware = false;
2513  pathnode->path.parallel_safe = rel->consider_parallel &&
2514  subpath->parallel_safe;
2515  pathnode->path.parallel_workers = subpath->parallel_workers;
2516  /* Unique doesn't change the input ordering */
2517  pathnode->path.pathkeys = subpath->pathkeys;
2518 
2519  pathnode->subpath = subpath;
2520  pathnode->numkeys = numCols;
2521 
2522  /*
2523  * Charge one cpu_operator_cost per comparison per input tuple. We assume
2524  * all columns get compared at most of the tuples. (XXX probably this is
2525  * an overestimate.)
2526  */
2527  pathnode->path.startup_cost = subpath->startup_cost;
2528  pathnode->path.total_cost = subpath->total_cost +
2529  cpu_operator_cost * subpath->rows * numCols;
2530  pathnode->path.rows = numGroups;
2531 
2532  return pathnode;
2533 }
2534 
2535 /*
2536  * create_agg_path
2537  * Creates a pathnode that represents performing aggregation/grouping
2538  *
2539  * 'rel' is the parent relation associated with the result
2540  * 'subpath' is the path representing the source of data
2541  * 'target' is the PathTarget to be computed
2542  * 'aggstrategy' is the Agg node's basic implementation strategy
2543  * 'aggsplit' is the Agg node's aggregate-splitting mode
2544  * 'groupClause' is a list of SortGroupClause's representing the grouping
2545  * 'qual' is the HAVING quals if any
2546  * 'aggcosts' contains cost info about the aggregate functions to be computed
2547  * 'numGroups' is the estimated number of groups (1 if not grouping)
2548  */
2549 AggPath *
2551  RelOptInfo *rel,
2552  Path *subpath,
2553  PathTarget *target,
2554  AggStrategy aggstrategy,
2555  AggSplit aggsplit,
2556  List *groupClause,
2557  List *qual,
2558  const AggClauseCosts *aggcosts,
2559  double numGroups)
2560 {
2561  AggPath *pathnode = makeNode(AggPath);
2562 
2563  pathnode->path.pathtype = T_Agg;
2564  pathnode->path.parent = rel;
2565  pathnode->path.pathtarget = target;
2566  /* For now, assume we are above any joins, so no parameterization */
2567  pathnode->path.param_info = NULL;
2568  pathnode->path.parallel_aware = false;
2569  pathnode->path.parallel_safe = rel->consider_parallel &&
2570  subpath->parallel_safe;
2571  pathnode->path.parallel_workers = subpath->parallel_workers;
2572  if (aggstrategy == AGG_SORTED)
2573  pathnode->path.pathkeys = subpath->pathkeys; /* preserves order */
2574  else
2575  pathnode->path.pathkeys = NIL; /* output is unordered */
2576  pathnode->subpath = subpath;
2577 
2578  pathnode->aggstrategy = aggstrategy;
2579  pathnode->aggsplit = aggsplit;
2580  pathnode->numGroups = numGroups;
2581  pathnode->groupClause = groupClause;
2582  pathnode->qual = qual;
2583 
2584  cost_agg(&pathnode->path, root,
2585  aggstrategy, aggcosts,
2586  list_length(groupClause), numGroups,
2587  subpath->startup_cost, subpath->total_cost,
2588  subpath->rows);
2589 
2590  /* add tlist eval cost for each output row */
2591  pathnode->path.startup_cost += target->cost.startup;
2592  pathnode->path.total_cost += target->cost.startup +
2593  target->cost.per_tuple * pathnode->path.rows;
2594 
2595  return pathnode;
2596 }
2597 
2598 /*
2599  * create_groupingsets_path
2600  * Creates a pathnode that represents performing GROUPING SETS aggregation
2601  *
2602  * GroupingSetsPath represents sorted grouping with one or more grouping sets.
2603  * The input path's result must be sorted to match the last entry in
2604  * rollup_groupclauses.
2605  *
2606  * 'rel' is the parent relation associated with the result
2607  * 'subpath' is the path representing the source of data
2608  * 'target' is the PathTarget to be computed
2609  * 'having_qual' is the HAVING quals if any
2610  * 'rollup_lists' is a list of grouping sets
2611  * 'rollup_groupclauses' is a list of grouping clauses for grouping sets
2612  * 'agg_costs' contains cost info about the aggregate functions to be computed
2613  * 'numGroups' is the estimated number of groups
2614  */
2617  RelOptInfo *rel,
2618  Path *subpath,
2619  PathTarget *target,
2620  List *having_qual,
2621  List *rollup_lists,
2622  List *rollup_groupclauses,
2623  const AggClauseCosts *agg_costs,
2624  double numGroups)
2625 {
2627  int numGroupCols;
2628 
2629  /* The topmost generated Plan node will be an Agg */
2630  pathnode->path.pathtype = T_Agg;
2631  pathnode->path.parent = rel;
2632  pathnode->path.pathtarget = target;
2633  pathnode->path.param_info = subpath->param_info;
2634  pathnode->path.parallel_aware = false;
2635  pathnode->path.parallel_safe = rel->consider_parallel &&
2636  subpath->parallel_safe;
2637  pathnode->path.parallel_workers = subpath->parallel_workers;
2638  pathnode->subpath = subpath;
2639 
2640  /*
2641  * Output will be in sorted order by group_pathkeys if, and only if, there
2642  * is a single rollup operation on a non-empty list of grouping
2643  * expressions.
2644  */
2645  if (list_length(rollup_groupclauses) == 1 &&
2646  ((List *) linitial(rollup_groupclauses)) != NIL)
2647  pathnode->path.pathkeys = root->group_pathkeys;
2648  else
2649  pathnode->path.pathkeys = NIL;
2650 
2651  pathnode->rollup_groupclauses = rollup_groupclauses;
2652  pathnode->rollup_lists = rollup_lists;
2653  pathnode->qual = having_qual;
2654 
2655  Assert(rollup_lists != NIL);
2656  Assert(list_length(rollup_lists) == list_length(rollup_groupclauses));
2657 
2658  /* Account for cost of the topmost Agg node */
2659  numGroupCols = list_length((List *) linitial((List *) llast(rollup_lists)));
2660 
2661  cost_agg(&pathnode->path, root,
2662  (numGroupCols > 0) ? AGG_SORTED : AGG_PLAIN,
2663  agg_costs,
2664  numGroupCols,
2665  numGroups,
2666  subpath->startup_cost,
2667  subpath->total_cost,
2668  subpath->rows);
2669 
2670  /*
2671  * Add in the costs and output rows of the additional sorting/aggregation
2672  * steps, if any. Only total costs count, since the extra sorts aren't
2673  * run on startup.
2674  */
2675  if (list_length(rollup_lists) > 1)
2676  {
2677  ListCell *lc;
2678 
2679  foreach(lc, rollup_lists)
2680  {
2681  List *gsets = (List *) lfirst(lc);
2682  Path sort_path; /* dummy for result of cost_sort */
2683  Path agg_path; /* dummy for result of cost_agg */
2684 
2685  /* We must iterate over all but the last rollup_lists element */
2686  if (lnext(lc) == NULL)
2687  break;
2688 
2689  /* Account for cost of sort, but don't charge input cost again */
2690  cost_sort(&sort_path, root, NIL,
2691  0.0,
2692  subpath->rows,
2693  subpath->pathtarget->width,
2694  0.0,
2695  work_mem,
2696  -1.0);
2697 
2698  /* Account for cost of aggregation */
2699  numGroupCols = list_length((List *) linitial(gsets));
2700 
2701  cost_agg(&agg_path, root,
2702  AGG_SORTED,
2703  agg_costs,
2704  numGroupCols,
2705  numGroups, /* XXX surely not right for all steps? */
2706  sort_path.startup_cost,
2707  sort_path.total_cost,
2708  sort_path.rows);
2709 
2710  pathnode->path.total_cost += agg_path.total_cost;
2711  pathnode->path.rows += agg_path.rows;
2712  }
2713  }
2714 
2715  /* add tlist eval cost for each output row */
2716  pathnode->path.startup_cost += target->cost.startup;
2717  pathnode->path.total_cost += target->cost.startup +
2718  target->cost.per_tuple * pathnode->path.rows;
2719 
2720  return pathnode;
2721 }
2722 
2723 /*
2724  * create_minmaxagg_path
2725  * Creates a pathnode that represents computation of MIN/MAX aggregates
2726  *
2727  * 'rel' is the parent relation associated with the result
2728  * 'target' is the PathTarget to be computed
2729  * 'mmaggregates' is a list of MinMaxAggInfo structs
2730  * 'quals' is the HAVING quals if any
2731  */
2732 MinMaxAggPath *
2734  RelOptInfo *rel,
2735  PathTarget *target,
2736  List *mmaggregates,
2737  List *quals)
2738 {
2739  MinMaxAggPath *pathnode = makeNode(MinMaxAggPath);
2740  Cost initplan_cost;
2741  ListCell *lc;
2742 
2743  /* The topmost generated Plan node will be a Result */
2744  pathnode->path.pathtype = T_Result;
2745  pathnode->path.parent = rel;
2746  pathnode->path.pathtarget = target;
2747  /* For now, assume we are above any joins, so no parameterization */
2748  pathnode->path.param_info = NULL;
2749  pathnode->path.parallel_aware = false;
2750  /* A MinMaxAggPath implies use of subplans, so cannot be parallel-safe */
2751  pathnode->path.parallel_safe = false;
2752  pathnode->path.parallel_workers = 0;
2753  /* Result is one unordered row */
2754  pathnode->path.rows = 1;
2755  pathnode->path.pathkeys = NIL;
2756 
2757  pathnode->mmaggregates = mmaggregates;
2758  pathnode->quals = quals;
2759 
2760  /* Calculate cost of all the initplans ... */
2761  initplan_cost = 0;
2762  foreach(lc, mmaggregates)
2763  {
2764  MinMaxAggInfo *mminfo = (MinMaxAggInfo *) lfirst(lc);
2765 
2766  initplan_cost += mminfo->pathcost;
2767  }
2768 
2769  /* add tlist eval cost for each output row, plus cpu_tuple_cost */
2770  pathnode->path.startup_cost = initplan_cost + target->cost.startup;
2771  pathnode->path.total_cost = initplan_cost + target->cost.startup +
2772  target->cost.per_tuple + cpu_tuple_cost;
2773 
2774  return pathnode;
2775 }
2776 
2777 /*
2778  * create_windowagg_path
2779  * Creates a pathnode that represents computation of window functions
2780  *
2781  * 'rel' is the parent relation associated with the result
2782  * 'subpath' is the path representing the source of data
2783  * 'target' is the PathTarget to be computed
2784  * 'windowFuncs' is a list of WindowFunc structs
2785  * 'winclause' is a WindowClause that is common to all the WindowFuncs
2786  * 'winpathkeys' is the pathkeys for the PARTITION keys + ORDER keys
2787  *
2788  * The actual sort order of the input must match winpathkeys, but might
2789  * have additional keys after those.
2790  */
2791 WindowAggPath *
2793  RelOptInfo *rel,
2794  Path *subpath,
2795  PathTarget *target,
2796  List *windowFuncs,
2797  WindowClause *winclause,
2798  List *winpathkeys)
2799 {
2800  WindowAggPath *pathnode = makeNode(WindowAggPath);
2801 
2802  pathnode->path.pathtype = T_WindowAgg;
2803  pathnode->path.parent = rel;
2804  pathnode->path.pathtarget = target;
2805  /* For now, assume we are above any joins, so no parameterization */
2806  pathnode->path.param_info = NULL;
2807  pathnode->path.parallel_aware = false;
2808  pathnode->path.parallel_safe = rel->consider_parallel &&
2809  subpath->parallel_safe;
2810  pathnode->path.parallel_workers = subpath->parallel_workers;
2811  /* WindowAgg preserves the input sort order */
2812  pathnode->path.pathkeys = subpath->pathkeys;
2813 
2814  pathnode->subpath = subpath;
2815  pathnode->winclause = winclause;
2816  pathnode->winpathkeys = winpathkeys;
2817 
2818  /*
2819  * For costing purposes, assume that there are no redundant partitioning
2820  * or ordering columns; it's not worth the trouble to deal with that
2821  * corner case here. So we just pass the unmodified list lengths to
2822  * cost_windowagg.
2823  */
2824  cost_windowagg(&pathnode->path, root,
2825  windowFuncs,
2826  list_length(winclause->partitionClause),
2827  list_length(winclause->orderClause),
2828  subpath->startup_cost,
2829  subpath->total_cost,
2830  subpath->rows);
2831 
2832  /* add tlist eval cost for each output row */
2833  pathnode->path.startup_cost += target->cost.startup;
2834  pathnode->path.total_cost += target->cost.startup +
2835  target->cost.per_tuple * pathnode->path.rows;
2836 
2837  return pathnode;
2838 }
2839 
2840 /*
2841  * create_setop_path
2842  * Creates a pathnode that represents computation of INTERSECT or EXCEPT
2843  *
2844  * 'rel' is the parent relation associated with the result
2845  * 'subpath' is the path representing the source of data
2846  * 'cmd' is the specific semantics (INTERSECT or EXCEPT, with/without ALL)
2847  * 'strategy' is the implementation strategy (sorted or hashed)
2848  * 'distinctList' is a list of SortGroupClause's representing the grouping
2849  * 'flagColIdx' is the column number where the flag column will be, if any
2850  * 'firstFlag' is the flag value for the first input relation when hashing;
2851  * or -1 when sorting
2852  * 'numGroups' is the estimated number of distinct groups
2853  * 'outputRows' is the estimated number of output rows
2854  */
2855 SetOpPath *
2857  RelOptInfo *rel,
2858  Path *subpath,
2859  SetOpCmd cmd,
2860  SetOpStrategy strategy,
2861  List *distinctList,
2862  AttrNumber flagColIdx,
2863  int firstFlag,
2864  double numGroups,
2865  double outputRows)
2866 {
2867  SetOpPath *pathnode = makeNode(SetOpPath);
2868 
2869  pathnode->path.pathtype = T_SetOp;
2870  pathnode->path.parent = rel;
2871  /* SetOp doesn't project, so use source path's pathtarget */
2872  pathnode->path.pathtarget = subpath->pathtarget;
2873  /* For now, assume we are above any joins, so no parameterization */
2874  pathnode->path.param_info = NULL;
2875  pathnode->path.parallel_aware = false;
2876  pathnode->path.parallel_safe = rel->consider_parallel &&
2877  subpath->parallel_safe;
2878  pathnode->path.parallel_workers = subpath->parallel_workers;
2879  /* SetOp preserves the input sort order if in sort mode */
2880  pathnode->path.pathkeys =
2881  (strategy == SETOP_SORTED) ? subpath->pathkeys : NIL;
2882 
2883  pathnode->subpath = subpath;
2884  pathnode->cmd = cmd;
2885  pathnode->strategy = strategy;
2886  pathnode->distinctList = distinctList;
2887  pathnode->flagColIdx = flagColIdx;
2888  pathnode->firstFlag = firstFlag;
2889  pathnode->numGroups = numGroups;
2890 
2891  /*
2892  * Charge one cpu_operator_cost per comparison per input tuple. We assume
2893  * all columns get compared at most of the tuples.
2894  */
2895  pathnode->path.startup_cost = subpath->startup_cost;
2896  pathnode->path.total_cost = subpath->total_cost +
2897  cpu_operator_cost * subpath->rows * list_length(distinctList);
2898  pathnode->path.rows = outputRows;
2899 
2900  return pathnode;
2901 }
2902 
2903 /*
2904  * create_recursiveunion_path
2905  * Creates a pathnode that represents a recursive UNION node
2906  *
2907  * 'rel' is the parent relation associated with the result
2908  * 'leftpath' is the source of data for the non-recursive term
2909  * 'rightpath' is the source of data for the recursive term
2910  * 'target' is the PathTarget to be computed
2911  * 'distinctList' is a list of SortGroupClause's representing the grouping
2912  * 'wtParam' is the ID of Param representing work table
2913  * 'numGroups' is the estimated number of groups
2914  *
2915  * For recursive UNION ALL, distinctList is empty and numGroups is zero
2916  */
2919  RelOptInfo *rel,
2920  Path *leftpath,
2921  Path *rightpath,
2922  PathTarget *target,
2923  List *distinctList,
2924  int wtParam,
2925  double numGroups)
2926 {
2928 
2929  pathnode->path.pathtype = T_RecursiveUnion;
2930  pathnode->path.parent = rel;
2931  pathnode->path.pathtarget = target;
2932  /* For now, assume we are above any joins, so no parameterization */
2933  pathnode->path.param_info = NULL;
2934  pathnode->path.parallel_aware = false;
2935  pathnode->path.parallel_safe = rel->consider_parallel &&
2936  leftpath->parallel_safe && rightpath->parallel_safe;
2937  /* Foolish, but we'll do it like joins for now: */
2938  pathnode->path.parallel_workers = leftpath->parallel_workers;
2939  /* RecursiveUnion result is always unsorted */
2940  pathnode->path.pathkeys = NIL;
2941 
2942  pathnode->leftpath = leftpath;
2943  pathnode->rightpath = rightpath;
2944  pathnode->distinctList = distinctList;
2945  pathnode->wtParam = wtParam;
2946  pathnode->numGroups = numGroups;
2947 
2948  cost_recursive_union(&pathnode->path, leftpath, rightpath);
2949 
2950  return pathnode;
2951 }
2952 
2953 /*
2954  * create_lockrows_path
2955  * Creates a pathnode that represents acquiring row locks
2956  *
2957  * 'rel' is the parent relation associated with the result
2958  * 'subpath' is the path representing the source of data
2959  * 'rowMarks' is a list of PlanRowMark's
2960  * 'epqParam' is the ID of Param for EvalPlanQual re-eval
2961  */
2962 LockRowsPath *
2964  Path *subpath, List *rowMarks, int epqParam)
2965 {
2966  LockRowsPath *pathnode = makeNode(LockRowsPath);
2967 
2968  pathnode->path.pathtype = T_LockRows;
2969  pathnode->path.parent = rel;
2970  /* LockRows doesn't project, so use source path's pathtarget */
2971  pathnode->path.pathtarget = subpath->pathtarget;
2972  /* For now, assume we are above any joins, so no parameterization */
2973  pathnode->path.param_info = NULL;
2974  pathnode->path.parallel_aware = false;
2975  pathnode->path.parallel_safe = false;
2976  pathnode->path.parallel_workers = 0;
2977  pathnode->path.rows = subpath->rows;
2978 
2979  /*
2980  * The result cannot be assumed sorted, since locking might cause the sort
2981  * key columns to be replaced with new values.
2982  */
2983  pathnode->path.pathkeys = NIL;
2984 
2985  pathnode->subpath = subpath;
2986  pathnode->rowMarks = rowMarks;
2987  pathnode->epqParam = epqParam;
2988 
2989  /*
2990  * We should charge something extra for the costs of row locking and
2991  * possible refetches, but it's hard to say how much. For now, use
2992  * cpu_tuple_cost per row.
2993  */
2994  pathnode->path.startup_cost = subpath->startup_cost;
2995  pathnode->path.total_cost = subpath->total_cost +
2996  cpu_tuple_cost * subpath->rows;
2997 
2998  return pathnode;
2999 }
3000 
3001 /*
3002  * create_modifytable_path
3003  * Creates a pathnode that represents performing INSERT/UPDATE/DELETE mods
3004  *
3005  * 'rel' is the parent relation associated with the result
3006  * 'operation' is the operation type
3007  * 'canSetTag' is true if we set the command tag/es_processed
3008  * 'nominalRelation' is the parent RT index for use of EXPLAIN
3009  * 'resultRelations' is an integer list of actual RT indexes of target rel(s)
3010  * 'subpaths' is a list of Path(s) producing source data (one per rel)
3011  * 'subroots' is a list of PlannerInfo structs (one per rel)
3012  * 'withCheckOptionLists' is a list of WCO lists (one per rel)
3013  * 'returningLists' is a list of RETURNING tlists (one per rel)
3014  * 'rowMarks' is a list of PlanRowMarks (non-locking only)
3015  * 'onconflict' is the ON CONFLICT clause, or NULL
3016  * 'epqParam' is the ID of Param for EvalPlanQual re-eval
3017  */
3020  CmdType operation, bool canSetTag,
3021  Index nominalRelation,
3022  List *resultRelations, List *subpaths,
3023  List *subroots,
3024  List *withCheckOptionLists, List *returningLists,
3025  List *rowMarks, OnConflictExpr *onconflict,
3026  int epqParam)
3027 {
3029  double total_size;
3030  ListCell *lc;
3031 
3032  Assert(list_length(resultRelations) == list_length(subpaths));
3033  Assert(list_length(resultRelations) == list_length(subroots));
3034  Assert(withCheckOptionLists == NIL ||
3035  list_length(resultRelations) == list_length(withCheckOptionLists));
3036  Assert(returningLists == NIL ||
3037  list_length(resultRelations) == list_length(returningLists));
3038 
3039  pathnode->path.pathtype = T_ModifyTable;
3040  pathnode->path.parent = rel;
3041  /* pathtarget is not interesting, just make it minimally valid */
3042  pathnode->path.pathtarget = rel->reltarget;
3043  /* For now, assume we are above any joins, so no parameterization */
3044  pathnode->path.param_info = NULL;
3045  pathnode->path.parallel_aware = false;
3046  pathnode->path.parallel_safe = false;
3047  pathnode->path.parallel_workers = 0;
3048  pathnode->path.pathkeys = NIL;
3049 
3050  /*
3051  * Compute cost & rowcount as sum of subpath costs & rowcounts.
3052  *
3053  * Currently, we don't charge anything extra for the actual table
3054  * modification work, nor for the WITH CHECK OPTIONS or RETURNING
3055  * expressions if any. It would only be window dressing, since
3056  * ModifyTable is always a top-level node and there is no way for the
3057  * costs to change any higher-level planning choices. But we might want
3058  * to make it look better sometime.
3059  */
3060  pathnode->path.startup_cost = 0;
3061  pathnode->path.total_cost = 0;
3062  pathnode->path.rows = 0;
3063  total_size = 0;
3064  foreach(lc, subpaths)
3065  {
3066  Path *subpath = (Path *) lfirst(lc);
3067 
3068  if (lc == list_head(subpaths)) /* first node? */
3069  pathnode->path.startup_cost = subpath->startup_cost;
3070  pathnode->path.total_cost += subpath->total_cost;
3071  pathnode->path.rows += subpath->rows;
3072  total_size += subpath->pathtarget->width * subpath->rows;
3073  }
3074 
3075  /*
3076  * Set width to the average width of the subpath outputs. XXX this is
3077  * totally wrong: we should report zero if no RETURNING, else an average
3078  * of the RETURNING tlist widths. But it's what happened historically,
3079  * and improving it is a task for another day.
3080  */
3081  if (pathnode->path.rows > 0)
3082  total_size /= pathnode->path.rows;
3083  pathnode->path.pathtarget->width = rint(total_size);
3084 
3085  pathnode->operation = operation;
3086  pathnode->canSetTag = canSetTag;
3087  pathnode->nominalRelation = nominalRelation;
3088  pathnode->resultRelations = resultRelations;
3089  pathnode->subpaths = subpaths;
3090  pathnode->subroots = subroots;
3091  pathnode->withCheckOptionLists = withCheckOptionLists;
3092  pathnode->returningLists = returningLists;
3093  pathnode->rowMarks = rowMarks;
3094  pathnode->onconflict = onconflict;
3095  pathnode->epqParam = epqParam;
3096 
3097  return pathnode;
3098 }
3099 
3100 /*
3101  * create_limit_path
3102  * Creates a pathnode that represents performing LIMIT/OFFSET
3103  *
3104  * In addition to providing the actual OFFSET and LIMIT expressions,
3105  * the caller must provide estimates of their values for costing purposes.
3106  * The estimates are as computed by preprocess_limit(), ie, 0 represents
3107  * the clause not being present, and -1 means it's present but we could
3108  * not estimate its value.
3109  *
3110  * 'rel' is the parent relation associated with the result
3111  * 'subpath' is the path representing the source of data
3112  * 'limitOffset' is the actual OFFSET expression, or NULL
3113  * 'limitCount' is the actual LIMIT expression, or NULL
3114  * 'offset_est' is the estimated value of the OFFSET expression
3115  * 'count_est' is the estimated value of the LIMIT expression
3116  */
3117 LimitPath *
3119  Path *subpath,
3120  Node *limitOffset, Node *limitCount,
3121  int64 offset_est, int64 count_est)
3122 {
3123  LimitPath *pathnode = makeNode(LimitPath);
3124 
3125  pathnode->path.pathtype = T_Limit;
3126  pathnode->path.parent = rel;
3127  /* Limit doesn't project, so use source path's pathtarget */
3128  pathnode->path.pathtarget = subpath->pathtarget;
3129  /* For now, assume we are above any joins, so no parameterization */
3130  pathnode->path.param_info = NULL;
3131  pathnode->path.parallel_aware = false;
3132  pathnode->path.parallel_safe = rel->consider_parallel &&
3133  subpath->parallel_safe;
3134  pathnode->path.parallel_workers = subpath->parallel_workers;
3135  pathnode->path.rows = subpath->rows;
3136  pathnode->path.startup_cost = subpath->startup_cost;
3137  pathnode->path.total_cost = subpath->total_cost;
3138  pathnode->path.pathkeys = subpath->pathkeys;
3139  pathnode->subpath = subpath;
3140  pathnode->limitOffset = limitOffset;
3141  pathnode->limitCount = limitCount;
3142 
3143  /*
3144  * Adjust the output rows count and costs according to the offset/limit.
3145  * This is only a cosmetic issue if we are at top level, but if we are
3146  * building a subquery then it's important to report correct info to the
3147  * outer planner.
3148  *
3149  * When the offset or count couldn't be estimated, use 10% of the
3150  * estimated number of rows emitted from the subpath.
3151  *
3152  * XXX we don't bother to add eval costs of the offset/limit expressions
3153  * themselves to the path costs. In theory we should, but in most cases
3154  * those expressions are trivial and it's just not worth the trouble.
3155  */
3156  if (offset_est != 0)
3157  {
3158  double offset_rows;
3159 
3160  if (offset_est > 0)
3161  offset_rows = (double) offset_est;
3162  else
3163  offset_rows = clamp_row_est(subpath->rows * 0.10);
3164  if (offset_rows > pathnode->path.rows)
3165  offset_rows = pathnode->path.rows;
3166  if (subpath->rows > 0)
3167  pathnode->path.startup_cost +=
3168  (subpath->total_cost - subpath->startup_cost)
3169  * offset_rows / subpath->rows;
3170  pathnode->path.rows -= offset_rows;
3171  if (pathnode->path.rows < 1)
3172  pathnode->path.rows = 1;
3173  }
3174 
3175  if (count_est != 0)
3176  {
3177  double count_rows;
3178 
3179  if (count_est > 0)
3180  count_rows = (double) count_est;
3181  else
3182  count_rows = clamp_row_est(subpath->rows * 0.10);
3183  if (count_rows > pathnode->path.rows)
3184  count_rows = pathnode->path.rows;
3185  if (subpath->rows > 0)
3186  pathnode->path.total_cost = pathnode->path.startup_cost +
3187  (subpath->total_cost - subpath->startup_cost)
3188  * count_rows / subpath->rows;
3189  pathnode->path.rows = count_rows;
3190  if (pathnode->path.rows < 1)
3191  pathnode->path.rows = 1;
3192  }
3193 
3194  return pathnode;
3195 }
3196 
3197 
3198 /*
3199  * reparameterize_path
3200  * Attempt to modify a Path to have greater parameterization
3201  *
3202  * We use this to attempt to bring all child paths of an appendrel to the
3203  * same parameterization level, ensuring that they all enforce the same set
3204  * of join quals (and thus that that parameterization can be attributed to
3205  * an append path built from such paths). Currently, only a few path types
3206  * are supported here, though more could be added at need. We return NULL
3207  * if we can't reparameterize the given path.
3208  *
3209  * Note: we intentionally do not pass created paths to add_path(); it would
3210  * possibly try to delete them on the grounds of being cost-inferior to the
3211  * paths they were made from, and we don't want that. Paths made here are
3212  * not necessarily of general-purpose usefulness, but they can be useful
3213  * as members of an append path.
3214  */
3215 Path *
3217  Relids required_outer,
3218  double loop_count)
3219 {
3220  RelOptInfo *rel = path->parent;
3221 
3222  /* Can only increase, not decrease, path's parameterization */
3223  if (!bms_is_subset(PATH_REQ_OUTER(path), required_outer))
3224  return NULL;
3225  switch (path->pathtype)
3226  {
3227  case T_SeqScan:
3228  return create_seqscan_path(root, rel, required_outer, 0);
3229  case T_SampleScan:
3230  return (Path *) create_samplescan_path(root, rel, required_outer);
3231  case T_IndexScan:
3232  case T_IndexOnlyScan:
3233  {
3234  IndexPath *ipath = (IndexPath *) path;
3235  IndexPath *newpath = makeNode(IndexPath);
3236 
3237  /*
3238  * We can't use create_index_path directly, and would not want
3239  * to because it would re-compute the indexqual conditions
3240  * which is wasted effort. Instead we hack things a bit:
3241  * flat-copy the path node, revise its param_info, and redo
3242  * the cost estimate.
3243  */
3244  memcpy(newpath, ipath, sizeof(IndexPath));
3245  newpath->path.param_info =
3246  get_baserel_parampathinfo(root, rel, required_outer);
3247  cost_index(newpath, root, loop_count, false);
3248  return (Path *) newpath;
3249  }
3250  case T_BitmapHeapScan:
3251  {
3252  BitmapHeapPath *bpath = (BitmapHeapPath *) path;
3253 
3254  return (Path *) create_bitmap_heap_path(root,
3255  rel,
3256  bpath->bitmapqual,
3257  required_outer,
3258  loop_count);
3259  }
3260  case T_SubqueryScan:
3261  {
3262  SubqueryScanPath *spath = (SubqueryScanPath *) path;
3263 
3264  return (Path *) create_subqueryscan_path(root,
3265  rel,
3266  spath->subpath,
3267  spath->path.pathkeys,
3268  required_outer);
3269  }
3270  default:
3271  break;
3272  }
3273  return NULL;
3274 }
Path * apply_projection_to_path(PlannerInfo *root, RelOptInfo *rel, Path *path, PathTarget *target)
Definition: pathnode.c:2253
void cost_group(Path *path, PlannerInfo *root, int numGroupCols, double numGroups, Cost input_startup_cost, Cost input_total_cost, double input_tuples)
Definition: costsize.c:1856
struct Path * cheapest_unique_path
Definition: relation.h:509
List * indexorderbycols
Definition: relation.h:977
List * group_pathkeys
Definition: relation.h:259
#define NIL
Definition: pg_list.h:69
List * qual
Definition: relation.h:1346
bool semi_can_btree
Definition: relation.h:1815
double estimate_num_groups(PlannerInfo *root, List *groupExprs, double input_rows, List **pgset)
Definition: selfuncs.c:3272
List * path_mergeclauses
Definition: relation.h:1265
List * outersortkeys
Definition: relation.h:1266
List * distinctList
Definition: relation.h:1429
MinMaxAggPath * create_minmaxagg_path(PlannerInfo *root, RelOptInfo *rel, PathTarget *target, List *mmaggregates, List *quals)
Definition: pathnode.c:2733
Definition: nodes.h:75
ModifyTablePath * create_modifytable_path(PlannerInfo *root, RelOptInfo *rel, CmdType operation, bool canSetTag, Index nominalRelation, List *resultRelations, List *subpaths, List *subroots, List *withCheckOptionLists, List *returningLists, List *rowMarks, OnConflictExpr *onconflict, int epqParam)
Definition: pathnode.c:3019
GatherPath * create_gather_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, Relids required_outer, double *rows)
Definition: pathnode.c:1667
#define IsA(nodeptr, _type_)
Definition: nodes.h:559
JoinPath jpath
Definition: relation.h:1282
PathTarget * pathtarget
Definition: relation.h:895
List * returningLists
Definition: relation.h:1476
bool query_is_distinct_for(Query *query, List *colnos, List *opids)
Definition: analyzejoins.c:688
OnConflictExpr * onconflict
Definition: relation.h:1478
void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, Path *bitmapqual, double loop_count)
Definition: costsize.c:854
BitmapHeapPath * create_bitmap_heap_path(PlannerInfo *root, RelOptInfo *rel, Path *bitmapqual, Relids required_outer, double loop_count)
Definition: pathnode.c:1067
Node * limitOffset
Definition: relation.h:1489
Path * subpath
Definition: relation.h:1358
void add_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:412
Path path
Definition: relation.h:971
SubqueryScanPath * create_subqueryscan_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *pathkeys, Relids required_outer)
Definition: pathnode.c:1705
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:110
Path * subpath
Definition: relation.h:1330
IndexOptInfo * indexinfo
Definition: relation.h:972
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1010
Index nominalRelation
Definition: relation.h:1471
Path * fdw_outerpath
Definition: relation.h:1072
void cost_tidscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info)
Definition: costsize.c:1076
void cost_windowagg(Path *path, PlannerInfo *root, List *windowFuncs, int numPartCols, int numOrderCols, Cost input_startup_cost, Cost input_total_cost, double input_tuples)
Definition: costsize.c:1784
Definition: nodes.h:77
SetOpStrategy strategy
Definition: relation.h:1428
AggStrategy aggstrategy
Definition: relation.h:1373
LockRowsPath * create_lockrows_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *rowMarks, int epqParam)
Definition: pathnode.c:2963
AppendPath * create_append_path(RelOptInfo *rel, List *subpaths, Relids required_outer, int parallel_workers)
Definition: pathnode.c:1202
SetOpPath * create_setop_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, SetOpCmd cmd, SetOpStrategy strategy, List *distinctList, AttrNumber flagColIdx, int firstFlag, double numGroups, double outputRows)
Definition: pathnode.c:2856
ParamPathInfo * get_joinrel_parampathinfo(PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, Relids required_outer, List **restrict_clauses)
Definition: relnode.c:1101
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:2870
List * qual
Definition: relation.h:1377
double expression_returns_set_rows(Node *clause)
Definition: clauses.c:801
UpperUniquePath * create_upper_unique_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, int numCols, double numGroups)
Definition: pathnode.c:2498
bool add_partial_path_precheck(RelOptInfo *parent_rel, Cost total_cost, List *pathkeys)
Definition: pathnode.c:876
bool add_path_precheck(RelOptInfo *parent_rel, Cost startup_cost, Cost total_cost, List *pathkeys, Relids required_outer)
Definition: pathnode.c:647
Path * innerjoinpath
Definition: relation.h:1217
struct Path * cheapest_startup_path
Definition: relation.h:507
void final_cost_nestloop(PlannerInfo *root, NestPath *path, JoinCostWorkspace *workspace, SpecialJoinInfo *sjinfo, SemiAntiJoinFactors *semifactors)
Definition: costsize.c:1979
double tuples
Definition: relation.h:529
Path * subpath
Definition: relation.h:1426
List * rowMarks
Definition: relation.h:1477
BitmapOrPath * create_bitmap_or_path(PlannerInfo *root, RelOptInfo *rel, List *bitmapquals)
Definition: pathnode.c:1135
int parallel_workers
Definition: relation.h:901
bool consider_param_startup
Definition: relation.h:497
void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root)
Definition: costsize.c:984
MaterialPath * create_material_path(RelOptInfo *rel, Path *subpath)
Definition: pathnode.c:1385
#define llast(l)
Definition: pg_list.h:126
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
ParamPathInfo * param_info
Definition: relation.h:897
Relids calc_non_nestloop_required_outer(Path *outer_path, Path *inner_path)
Definition: pathnode.c:1912
Definition: nodes.h:508
ProjectionPath * create_projection_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
Definition: pathnode.c:2162
Definition: nodes.h:48
List * partial_pathlist
Definition: relation.h:506
AttrNumber varattno
Definition: primnodes.h:146
void cost_valuesscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1289
IndexPath * create_index_path(PlannerInfo *root, IndexOptInfo *index, List *indexclauses, List *indexclausecols, List *indexorderbys, List *indexorderbycols, List *pathkeys, ScanDirection indexscandir, bool indexonly, Relids required_outer, double loop_count, bool partial_path)
Definition: pathnode.c:1008
void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1339
List * cheapest_parameterized_paths
Definition: relation.h:510
bool single_copy
Definition: relation.h:1203
UniquePathMethod umethod
Definition: relation.h:1189
PathKeysComparison compare_pathkeys(List *keys1, List *keys2)
Definition: pathkeys.c:278
Definition: nodes.h:73
UniquePath * create_unique_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, SpecialJoinInfo *sjinfo)
Definition: pathnode.c:1424
Path * subpath
Definition: relation.h:1163
List * indexclauses
Definition: relation.h:973
AggSplit aggsplit
Definition: relation.h:1374
List * quals
Definition: relation.h:1402
Definition: primnodes.h:141
LimitPath * create_limit_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, Node *limitOffset, Node *limitCount, int64 offset_est, int64 count_est)
Definition: pathnode.c:3118
Path * create_functionscan_path(PlannerInfo *root, RelOptInfo *rel, List *pathkeys, Relids required_outer)
Definition: pathnode.c:1733
double numGroups
Definition: relation.h:1375
double numGroups
Definition: relation.h:1432
SetOpStrategy
Definition: nodes.h:778
List * rowMarks
Definition: relation.h:1455
List * winpathkeys
Definition: relation.h:1417
Cost startup
Definition: relation.h:45
List * bitmapquals
Definition: relation.h:1015
Path path
Definition: relation.h:1118
JoinType
Definition: nodes.h:665
WindowClause * winclause
Definition: relation.h:1416
Path * create_valuesscan_path(PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
Definition: pathnode.c:1759
NestPath * create_nestloop_path(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, JoinCostWorkspace *workspace, SpecialJoinInfo *sjinfo, SemiAntiJoinFactors *semifactors, Path *outer_path, Path *inner_path, List *restrict_clauses, List *pathkeys, Relids required_outer)
Definition: pathnode.c:1946
List * bitmapquals
Definition: relation.h:1028
Definition: type.h:90
NodeTag pathtype
Definition: relation.h:892
Relids syn_righthand
Definition: relation.h:1810
MergePath * create_mergejoin_path(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, JoinCostWorkspace *workspace, SpecialJoinInfo *sjinfo, Path *outer_path, Path *inner_path, List *restrict_clauses, List *pathkeys, Relids required_outer, List *mergeclauses, List *outersortkeys, List *innersortkeys)
Definition: pathnode.c:2034
List * subpaths
Definition: relation.h:1119
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, SpecialJoinInfo *sjinfo)
Definition: costsize.c:2393
SetOpCmd cmd
Definition: relation.h:1427
ListCell * lappend_cell(List *list, ListCell *prev, void *datum)
Definition: list.c:209
bool consider_startup
Definition: relation.h:496
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:1071
void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:196
HashPath * create_hashjoin_path(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, JoinCostWorkspace *workspace, SpecialJoinInfo *sjinfo, SemiAntiJoinFactors *semifactors, Path *outer_path, Path *inner_path, List *restrict_clauses, Relids required_outer, List *hashclauses)
Definition: pathnode.c:2098
Cost per_tuple
Definition: relation.h:46
List * indexquals
Definition: relation.h:974
Path * subpath
Definition: relation.h:1415
void pfree(void *pointer)
Definition: mcxt.c:992
RelOptInfo * rel
Definition: relation.h:590
Path path
Definition: relation.h:1150
#define linitial(l)
Definition: pg_list.h:110
#define planner_rt_fetch(rti, root)
Definition: relation.h:320
Definition: nodes.h:45
Relids all_baserels
Definition: relation.h:193
#define ERROR
Definition: elog.h:43
static List * translate_sub_tlist(List *tlist, int relid)
Definition: pathnode.c:1641
double limit_tuples
Definition: relation.h:287
List * partitionClause
Definition: parsenodes.h:1195
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:3204
void expand_indexqual_conditions(IndexOptInfo *index, List *indexclauses, List *indexclausecols, List **indexquals_p, List **indexqualcols_p)
Definition: indxpath.c:3509
Cost startup_cost
Definition: relation.h:906
RecursiveUnionPath * create_recursiveunion_path(PlannerInfo *root, RelOptInfo *rel, Path *leftpath, Path *rightpath, PathTarget *target, List *distinctList, int wtParam, double numGroups)
Definition: pathnode.c:2918
List * semi_rhs_exprs
Definition: relation.h:1818
void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1179
bool semi_can_hash
Definition: relation.h:1816
Path * subpath
Definition: relation.h:1488
List * joinrestrictinfo
Definition: relation.h:1219
List * subroots
Definition: relation.h:1474
RelOptInfo * parent
Definition: relation.h:894
List * uniq_exprs
Definition: relation.h:1191
Path * bitmapqual
Definition: relation.h:1003
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:307
Definition: nodes.h:74
Path path
Definition: relation.h:1343
List * rollup_lists
Definition: relation.h:1391
int compare_path_costs(Path *path1, Path *path2, CostSelector criterion)
Definition: pathnode.c:61
AggPath * create_agg_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, AggStrategy aggstrategy, AggSplit aggsplit, List *groupClause, List *qual, const AggClauseCosts *aggcosts, double numGroups)
Definition: pathnode.c:2550
struct Path * cheapest_total_path
Definition: relation.h:508
ForeignPath * create_foreignscan_path(PlannerInfo *root, RelOptInfo *rel, PathTarget *target, double rows, Cost startup_cost, Cost total_cost, List *pathkeys, Relids required_outer, Path *fdw_outerpath, List *fdw_private)
Definition: pathnode.c:1844
ProjectSetPath * create_set_projection_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
Definition: pathnode.c:2329
MergeAppendPath * create_merge_append_path(PlannerInfo *root, RelOptInfo *rel, List *subpaths, List *pathkeys, Relids required_outer)
Definition: pathnode.c:1256
static PathCostComparison compare_path_costs_fuzzily(Path *path1, Path *path2, double fuzz_factor)
Definition: pathnode.c:156
ScanDirection
Definition: sdir.h:22
void cost_agg(Path *path, PlannerInfo *root, AggStrategy aggstrategy, const AggClauseCosts *aggcosts, int numGroupCols, double numGroups, Cost input_startup_cost, Cost input_total_cost, double input_tuples)
Definition: costsize.c:1692
GroupPath * create_group_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, List *groupClause, List *qual, double numGroups)
Definition: pathnode.c:2440
List * subpaths
Definition: relation.h:1473
List * groupClause
Definition: relation.h:1376
static ListCell * list_head(const List *l)
Definition: pg_list.h:77
AttrNumber flagColIdx
Definition: relation.h:1430
Relids relids
Definition: relation.h:490
double cpu_operator_cost
Definition: costsize.c:108
Path * subpath
Definition: relation.h:1202
double rint(double x)
Definition: rint.c:22
void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:273
#define lnext(lc)
Definition: pg_list.h:105
bool join_clause_is_movable_into(RestrictInfo *rinfo, Relids currentrelids, Relids current_and_outer)
Definition: restrictinfo.c:514
List * lappend_int(List *list, int datum)
Definition: list.c:146
Index relid
Definition: relation.h:518
Path * create_worktablescan_path(PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
Definition: pathnode.c:1810
List * lappend(List *list, void *datum)
Definition: list.c:128
Path * subpath
Definition: relation.h:1454
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:633
Index varno
Definition: primnodes.h:144
void set_cheapest(RelOptInfo *parent_rel)
Definition: pathnode.c:234
List * exprs
Definition: relation.h:824
BitmapAndPath * create_bitmap_and_path(PlannerInfo *root, RelOptInfo *rel, List *bitmapquals)
Definition: pathnode.c:1099
List * list_delete_cell(List *list, ListCell *cell, ListCell *prev)
Definition: list.c:528
bool pathkeys_contained_in(List *keys1, List *keys2)
Definition: pathkeys.c:317
Path * outerjoinpath
Definition: relation.h:1216
void cost_index(IndexPath *path, PlannerInfo *root, double loop_count, bool partial_path)
Definition: costsize.c:394
List * rollup_groupclauses
Definition: relation.h:1390
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, SpecialJoinInfo *sjinfo, SemiAntiJoinFactors *semifactors)
Definition: costsize.c:2783
List * indexorderbys
Definition: relation.h:976
void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm)
Definition: costsize.c:1383
WindowAggPath * create_windowagg_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, List *windowFuncs, WindowClause *winclause, List *winpathkeys)
Definition: pathnode.c:2792
Path * create_samplescan_path(PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
Definition: pathnode.c:963
List * groupClause
Definition: relation.h:1345
List * mmaggregates
Definition: relation.h:1401
List * tidquals
Definition: relation.h:1042
void cost_sort(Path *path, PlannerInfo *root, List *pathkeys, Cost input_cost, double tuples, int width, Cost comparison_cost, int sort_mem, double limit_tuples)
Definition: costsize.c:1463
GroupingSetsPath * create_groupingsets_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, List *having_qual, List *rollup_lists, List *rollup_groupclauses, const AggClauseCosts *agg_costs, double numGroups)
Definition: pathnode.c:2616
int work_mem
Definition: globals.c:112
Path * subpath
Definition: relation.h:1344
unsigned int Index
Definition: c.h:361
RTEKind rtekind
Definition: relation.h:520
PathCostComparison
Definition: pathnode.c:33
List * in_operators
Definition: relation.h:1190
double rows
Definition: relation.h:493
SortPath * create_sort_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *pathkeys, double limit_tuples)
Definition: pathnode.c:2396
BMS_Comparison bms_subset_compare(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:344
Cost total_cost
Definition: relation.h:907
void cost_material(Path *path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition: costsize.c:1638
int firstFlag
Definition: relation.h:1431
List * lcons(void *datum, List *list)
Definition: list.c:259
List * pathkeys
Definition: relation.h:909
void bms_free(Bitmapset *a)
Definition: bitmapset.c:200
#define makeNode(_type_)
Definition: nodes.h:556
void cost_merge_append(Path *path, PlannerInfo *root, List *pathkeys, int n_streams, Cost input_startup_cost, Cost input_total_cost, double tuples)
Definition: costsize.c:1587
#define CONSIDER_PATH_STARTUP_COST(p)
Path path
Definition: relation.h:1212
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:670
#define lfirst(lc)
Definition: pg_list.h:106
Path * subpath
Definition: relation.h:1316
double rows
Definition: relation.h:905
bool parallel_safe
Definition: relation.h:900
int compare_fractional_path_costs(Path *path1, Path *path2, double fraction)
Definition: pathnode.c:107
List * quals
Definition: relation.h:1151
#define PATH_REQ_OUTER(path)
Definition: relation.h:914
JoinType jointype
Definition: relation.h:1811
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:217
#define STD_FUZZ_FACTOR
Definition: pathnode.c:46
QualCost cost
Definition: relation.h:826
AggSplit
Definition: nodes.h:748
static int list_length(const List *l)
Definition: pg_list.h:89
CostSelector
Definition: relation.h:34
bool consider_parallel
Definition: relation.h:498
List * innersortkeys
Definition: relation.h:1267
double cpu_tuple_cost
Definition: costsize.c:106
Path * subpath
Definition: relation.h:1372
bool query_supports_distinctness(Query *query)
Definition: analyzejoins.c:651
void cost_gather(GatherPath *path, PlannerInfo *root, RelOptInfo *rel, ParamPathInfo *param_info, double *rows)
Definition: costsize.c:348
Path path
Definition: relation.h:1487
Path path
Definition: relation.h:1041
List * withCheckOptionLists
Definition: relation.h:1475
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:787
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:442
List * indexqualcols
Definition: relation.h:975
Definition: nodes.h:80
List * orderClause
Definition: parsenodes.h:1196
PathKeysComparison
Definition: paths.h:173
int width
Definition: relation.h:827
Query * subquery
Definition: parsenodes.h:900
AggStrategy
Definition: nodes.h:727
bool is_projection_capable_path(Path *path)
Definition: createplan.c:6267
TidPath * create_tidscan_path(PlannerInfo *root, RelOptInfo *rel, List *tidquals, Relids required_outer)
Definition: pathnode.c:1171
Path * reparameterize_path(PlannerInfo *root, Path *path, Relids required_outer, double loop_count)
Definition: pathnode.c:3216
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1228
void add_partial_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:752
List * fdw_private
Definition: relation.h:1073
SetOpCmd
Definition: nodes.h:770
JoinType jointype
Definition: relation.h:1214
List * semi_operators
Definition: relation.h:1817
ScanDirection indexscandir
Definition: relation.h:978
CmdType operation
Definition: relation.h:1469
Definition: nodes.h:78
List * resultRelations
Definition: relation.h:1472
void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root)
Definition: costsize.c:1028
JoinPath jpath
Definition: relation.h:1264
ResultPath * create_result_path(PlannerInfo *root, RelOptInfo *rel, PathTarget *target, List *resconstantqual)
Definition: pathnode.c:1346
bool parallel_aware
Definition: relation.h:899
List * path_hashclauses
Definition: relation.h:1283
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:97
List * pathlist
Definition: relation.h:504
List * subpaths
Definition: relation.h:1137
MemoryContext planner_cxt
Definition: relation.h:282
#define elog
Definition: elog.h:219
ParamPathInfo * get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer)
Definition: relnode.c:1309
bool relation_has_unique_index_for(PlannerInfo *root, RelOptInfo *rel, List *restrictlist, List *exprlist, List *oprlist)
Definition: indxpath.c:2943
Path * subpath
Definition: relation.h:1304
Path path
Definition: relation.h:1201
double clamp_row_est(double nrows)
Definition: costsize.c:172
Node * limitCount
Definition: relation.h:1490
Definition: pg_list.h:45
Path path
Definition: relation.h:1329
struct PathTarget * reltarget
Definition: relation.h:501
int16 AttrNumber
Definition: attnum.h:21
Path path
Definition: relation.h:1425
Path path
Definition: relation.h:1187
CmdType
Definition: nodes.h:641
Path * create_seqscan_path(PlannerInfo *root, RelOptInfo *rel, Relids required_outer, int parallel_workers)
Definition: pathnode.c:938
Path path
Definition: relation.h:1371
Definition: relation.h:888
double limit_tuples
Definition: relation.h:1138
BMS_Comparison
Definition: bitmapset.h:40
double Cost
Definition: nodes.h:632
Relids calc_nestloop_required_outer(Path *outer_path, Path *inner_path)
Definition: pathnode.c:1880
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:130
static int cmp(const chr *x, const chr *y, size_t len)
Definition: regc_locale.c:742
Path * subpath
Definition: relation.h:1188
Definition: nodes.h:82
Path * create_ctescan_path(PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
Definition: pathnode.c:1785