1 /*-------------------------------------------------------------------------
4 * Routines to manipulate pathlists and create path nodes
6 * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * $PostgreSQL: pgsql/src/backend/optimizer/util/pathnode.c,v 1.103 2004/03/29 19:58:04 tgl Exp $
13 *-------------------------------------------------------------------------
19 #include "catalog/pg_operator.h"
20 #include "executor/executor.h"
21 #include "miscadmin.h"
22 #include "nodes/plannodes.h"
23 #include "optimizer/clauses.h"
24 #include "optimizer/cost.h"
25 #include "optimizer/pathnode.h"
26 #include "optimizer/paths.h"
27 #include "optimizer/restrictinfo.h"
28 #include "optimizer/tlist.h"
29 #include "parser/parse_expr.h"
30 #include "parser/parse_oper.h"
31 #include "parser/parsetree.h"
32 #include "utils/memutils.h"
33 #include "utils/selfuncs.h"
34 #include "utils/syscache.h"
37 static bool is_distinct_query(Query *query);
38 static bool hash_safe_tlist(List *tlist);
41 /*****************************************************************************
42 * MISC. PATH UTILITIES
43 *****************************************************************************/
47 * Return -1, 0, or +1 according as path1 is cheaper, the same cost,
48 * or more expensive than path2 for the specified criterion.
51 compare_path_costs(Path *path1, Path *path2, CostSelector criterion)
53 if (criterion == STARTUP_COST)
55 if (path1->startup_cost < path2->startup_cost)
57 if (path1->startup_cost > path2->startup_cost)
61 * If paths have the same startup cost (not at all unlikely),
62 * order them by total cost.
64 if (path1->total_cost < path2->total_cost)
66 if (path1->total_cost > path2->total_cost)
71 if (path1->total_cost < path2->total_cost)
73 if (path1->total_cost > path2->total_cost)
77 * If paths have the same total cost, order them by startup cost.
79 if (path1->startup_cost < path2->startup_cost)
81 if (path1->startup_cost > path2->startup_cost)
88 * compare_fuzzy_path_costs
89 * Return -1, 0, or +1 according as path1 is cheaper, the same cost,
90 * or more expensive than path2 for the specified criterion.
92 * This differs from compare_path_costs in that we consider the costs the
93 * same if they agree to within a "fuzz factor". This is used by add_path
94 * to avoid keeping both of a pair of paths that really have insignificantly
98 compare_fuzzy_path_costs(Path *path1, Path *path2, CostSelector criterion)
103 * The fuzz factor is set at one percent of the smaller total_cost, but
104 * not less than 0.01 cost units (just in case total cost is zero).
106 * XXX does this percentage need to be user-configurable?
108 fuzz = Min(path1->total_cost, path2->total_cost) * 0.01;
109 fuzz = Max(fuzz, 0.01);
111 if (criterion == STARTUP_COST)
113 if (Abs(path1->startup_cost - path2->startup_cost) > fuzz)
115 if (path1->startup_cost < path2->startup_cost)
122 * If paths have the same startup cost (not at all unlikely),
123 * order them by total cost.
125 if (Abs(path1->total_cost - path2->total_cost) > fuzz)
127 if (path1->total_cost < path2->total_cost)
135 if (Abs(path1->total_cost - path2->total_cost) > fuzz)
137 if (path1->total_cost < path2->total_cost)
144 * If paths have the same total cost, order them by startup cost.
146 if (Abs(path1->startup_cost - path2->startup_cost) > fuzz)
148 if (path1->startup_cost < path2->startup_cost)
158 * compare_path_fractional_costs
159 * Return -1, 0, or +1 according as path1 is cheaper, the same cost,
160 * or more expensive than path2 for fetching the specified fraction
161 * of the total tuples.
163 * If fraction is <= 0 or > 1, we interpret it as 1, ie, we select the
164 * path with the cheaper total_cost.
167 compare_fractional_path_costs(Path *path1, Path *path2,
173 if (fraction <= 0.0 || fraction >= 1.0)
174 return compare_path_costs(path1, path2, TOTAL_COST);
175 cost1 = path1->startup_cost +
176 fraction * (path1->total_cost - path1->startup_cost);
177 cost2 = path2->startup_cost +
178 fraction * (path2->total_cost - path2->startup_cost);
188 * Find the minimum-cost paths from among a relation's paths,
189 * and save them in the rel's cheapest-path fields.
191 * This is normally called only after we've finished constructing the path
192 * list for the rel node.
194 * If we find two paths of identical costs, try to keep the better-sorted one.
195 * The paths might have unrelated sort orderings, in which case we can only
196 * guess which might be better to keep, but if one is superior then we
197 * definitely should keep it.
200 set_cheapest(RelOptInfo *parent_rel)
202 List *pathlist = parent_rel->pathlist;
204 Path *cheapest_startup_path;
205 Path *cheapest_total_path;
207 Assert(IsA(parent_rel, RelOptInfo));
210 elog(ERROR, "could not devise a query plan for the given query");
212 cheapest_startup_path = cheapest_total_path = (Path *) lfirst(pathlist);
214 foreach(p, lnext(pathlist))
216 Path *path = (Path *) lfirst(p);
219 cmp = compare_path_costs(cheapest_startup_path, path, STARTUP_COST);
222 compare_pathkeys(cheapest_startup_path->pathkeys,
223 path->pathkeys) == PATHKEYS_BETTER2))
224 cheapest_startup_path = path;
226 cmp = compare_path_costs(cheapest_total_path, path, TOTAL_COST);
229 compare_pathkeys(cheapest_total_path->pathkeys,
230 path->pathkeys) == PATHKEYS_BETTER2))
231 cheapest_total_path = path;
234 parent_rel->cheapest_startup_path = cheapest_startup_path;
235 parent_rel->cheapest_total_path = cheapest_total_path;
236 parent_rel->cheapest_unique_path = NULL; /* computed only if needed */
241 * Consider a potential implementation path for the specified parent rel,
242 * and add it to the rel's pathlist if it is worthy of consideration.
243 * A path is worthy if it has either a better sort order (better pathkeys)
244 * or cheaper cost (on either dimension) than any of the existing old paths.
246 * Unless parent_rel->pruneable is false, we also remove from the rel's
247 * pathlist any old paths that are dominated by new_path --- that is,
248 * new_path is both cheaper and at least as well ordered.
250 * The pathlist is kept sorted by TOTAL_COST metric, with cheaper paths
251 * at the front. No code depends on that for correctness; it's simply
252 * a speed hack within this routine. Doing it that way makes it more
253 * likely that we will reject an inferior path after a few comparisons,
254 * rather than many comparisons.
256 * NOTE: discarded Path objects are immediately pfree'd to reduce planner
257 * memory consumption. We dare not try to free the substructure of a Path,
258 * since much of it may be shared with other Paths or the query tree itself;
259 * but just recycling discarded Path nodes is a very useful savings in
260 * a large join tree. We can recycle the List nodes of pathlist, too.
262 * 'parent_rel' is the relation entry to which the path corresponds.
263 * 'new_path' is a potential path for parent_rel.
265 * Returns nothing, but modifies parent_rel->pathlist.
268 add_path(RelOptInfo *parent_rel, Path *new_path)
270 bool accept_new = true; /* unless we find a superior old
272 List *insert_after = NIL; /* where to insert new item */
277 * Loop to check proposed new path against old paths. Note it is
278 * possible for more than one old path to be tossed out because
279 * new_path dominates it.
281 p1 = parent_rel->pathlist; /* cannot use foreach here */
284 Path *old_path = (Path *) lfirst(p1);
285 bool remove_old = false; /* unless new proves superior */
289 * As of Postgres 7.5, we use fuzzy cost comparison to avoid wasting
290 * cycles keeping paths that are really not significantly different
293 costcmp = compare_fuzzy_path_costs(new_path, old_path, TOTAL_COST);
296 * If the two paths compare differently for startup and total
297 * cost, then we want to keep both, and we can skip the (much
298 * slower) comparison of pathkeys. If they compare the same,
299 * proceed with the pathkeys comparison. Note: this test relies
300 * on the fact that compare_fuzzy_path_costs will only return 0 if
301 * both costs are effectively equal (and, therefore, there's no need
302 * to call it twice in that case).
305 costcmp == compare_fuzzy_path_costs(new_path, old_path,
308 switch (compare_pathkeys(new_path->pathkeys, old_path->pathkeys))
312 remove_old = true; /* new dominates old */
313 else if (costcmp > 0)
314 accept_new = false; /* old dominates new */
318 * Same pathkeys, and fuzzily the same cost, so
319 * keep just one --- but we'll do an exact cost
320 * comparison to decide which.
322 if (compare_path_costs(new_path, old_path,
324 remove_old = true; /* new dominates old */
326 accept_new = false; /* old equals or dominates
330 case PATHKEYS_BETTER1:
332 remove_old = true; /* new dominates old */
334 case PATHKEYS_BETTER2:
336 accept_new = false; /* old dominates new */
338 case PATHKEYS_DIFFERENT:
339 /* keep both paths, since they have different ordering */
345 * Remove current element from pathlist if dominated by new,
346 * unless xfunc told us not to remove any paths.
348 if (remove_old && parent_rel->pruneable)
350 List *p1_next = lnext(p1);
353 lnext(p1_prev) = p1_next;
355 parent_rel->pathlist = p1_next;
357 pfree(p1); /* this is why we can't use foreach */
362 /* new belongs after this old path if it has cost >= old's */
370 * If we found an old path that dominates new_path, we can quit
371 * scanning the pathlist; we will not add new_path, and we assume
372 * new_path cannot dominate any other elements of the pathlist.
380 /* Accept the new path: insert it at proper place in pathlist */
382 lnext(insert_after) = lcons(new_path, lnext(insert_after));
384 parent_rel->pathlist = lcons(new_path, parent_rel->pathlist);
388 /* Reject and recycle the new path */
394 /*****************************************************************************
395 * PATH NODE CREATION ROUTINES
396 *****************************************************************************/
399 * create_seqscan_path
400 * Creates a path corresponding to a sequential scan, returning the
404 create_seqscan_path(Query *root, RelOptInfo *rel)
406 Path *pathnode = makeNode(Path);
408 pathnode->pathtype = T_SeqScan;
409 pathnode->parent = rel;
410 pathnode->pathkeys = NIL; /* seqscan has unordered result */
412 cost_seqscan(pathnode, root, rel);
419 * Creates a path node for an index scan.
421 * 'rel' is the parent rel
422 * 'index' is an index on 'rel'
423 * 'restriction_clauses' is a list of lists of RestrictInfo nodes
424 * to be used as index qual conditions in the scan.
425 * 'pathkeys' describes the ordering of the path.
426 * 'indexscandir' is ForwardScanDirection or BackwardScanDirection
427 * for an ordered index, or NoMovementScanDirection for
428 * an unordered index.
430 * Returns the new path node.
433 create_index_path(Query *root,
436 List *restriction_clauses,
438 ScanDirection indexscandir)
440 IndexPath *pathnode = makeNode(IndexPath);
443 pathnode->path.pathtype = T_IndexScan;
444 pathnode->path.parent = rel;
445 pathnode->path.pathkeys = pathkeys;
447 /* Convert clauses to indexquals the executor can handle */
448 indexquals = expand_indexqual_conditions(index, restriction_clauses);
450 /* Flatten the clause-groups list to produce indexclauses list */
451 restriction_clauses = flatten_clausegroups_list(restriction_clauses);
454 * We are making a pathnode for a single-scan indexscan; therefore,
455 * indexinfo etc should be single-element lists.
457 pathnode->indexinfo = makeList1(index);
458 pathnode->indexclauses = makeList1(restriction_clauses);
459 pathnode->indexquals = makeList1(indexquals);
461 /* It's not an innerjoin path. */
462 pathnode->isjoininner = false;
464 pathnode->indexscandir = indexscandir;
467 * The number of rows is the same as the parent rel's estimate, since
468 * this isn't a join inner indexscan.
470 pathnode->rows = rel->rows;
472 cost_index(&pathnode->path, root, rel, index, indexquals, false);
478 * create_tidscan_path
479 * Creates a path corresponding to a tid_direct scan, returning the
483 create_tidscan_path(Query *root, RelOptInfo *rel, List *tideval)
485 TidPath *pathnode = makeNode(TidPath);
487 pathnode->path.pathtype = T_TidScan;
488 pathnode->path.parent = rel;
489 pathnode->path.pathkeys = NIL;
491 pathnode->tideval = tideval;
493 cost_tidscan(&pathnode->path, root, rel, tideval);
496 * divide selectivity for each clause to get an equal selectivity as
497 * IndexScan does OK ?
505 * Creates a path corresponding to an Append plan, returning the
509 create_append_path(RelOptInfo *rel, List *subpaths)
511 AppendPath *pathnode = makeNode(AppendPath);
514 pathnode->path.pathtype = T_Append;
515 pathnode->path.parent = rel;
516 pathnode->path.pathkeys = NIL; /* result is always considered
518 pathnode->subpaths = subpaths;
520 pathnode->path.startup_cost = 0;
521 pathnode->path.total_cost = 0;
524 Path *subpath = (Path *) lfirst(l);
526 if (l == subpaths) /* first node? */
527 pathnode->path.startup_cost = subpath->startup_cost;
528 pathnode->path.total_cost += subpath->total_cost;
536 * Creates a path corresponding to a Result plan, returning the
540 create_result_path(RelOptInfo *rel, Path *subpath, List *constantqual)
542 ResultPath *pathnode = makeNode(ResultPath);
544 pathnode->path.pathtype = T_Result;
545 pathnode->path.parent = rel; /* may be NULL */
548 pathnode->path.pathkeys = subpath->pathkeys;
550 pathnode->path.pathkeys = NIL;
552 pathnode->subpath = subpath;
553 pathnode->constantqual = constantqual;
555 /* Ideally should define cost_result(), but I'm too lazy */
558 pathnode->path.startup_cost = subpath->startup_cost;
559 pathnode->path.total_cost = subpath->total_cost;
563 pathnode->path.startup_cost = 0;
564 pathnode->path.total_cost = cpu_tuple_cost;
571 * create_material_path
572 * Creates a path corresponding to a Material plan, returning the
576 create_material_path(RelOptInfo *rel, Path *subpath)
578 MaterialPath *pathnode = makeNode(MaterialPath);
580 pathnode->path.pathtype = T_Material;
581 pathnode->path.parent = rel;
583 pathnode->path.pathkeys = subpath->pathkeys;
585 pathnode->subpath = subpath;
587 cost_material(&pathnode->path,
597 * Creates a path representing elimination of distinct rows from the
600 * If used at all, this is likely to be called repeatedly on the same rel;
601 * and the input subpath should always be the same (the cheapest_total path
602 * for the rel). So we cache the result.
605 create_unique_path(Query *root, RelOptInfo *rel, Path *subpath)
607 UniquePath *pathnode;
608 Path sort_path; /* dummy for result of cost_sort */
609 Path agg_path; /* dummy for result of cost_agg */
610 MemoryContext oldcontext;
611 List *sub_targetlist;
615 /* Caller made a mistake if subpath isn't cheapest_total */
616 Assert(subpath == rel->cheapest_total_path);
618 /* If result already cached, return it */
619 if (rel->cheapest_unique_path)
620 return (UniquePath *) rel->cheapest_unique_path;
623 * We must ensure path struct is allocated in same context as parent
624 * rel; otherwise GEQO memory management causes trouble. (Compare
625 * best_inner_indexscan().)
627 oldcontext = MemoryContextSwitchTo(GetMemoryChunkContext(rel));
629 pathnode = makeNode(UniquePath);
631 /* There is no substructure to allocate, so can switch back right away */
632 MemoryContextSwitchTo(oldcontext);
634 pathnode->path.pathtype = T_Unique;
635 pathnode->path.parent = rel;
638 * Treat the output as always unsorted, since we don't necessarily
639 * have pathkeys to represent it.
641 pathnode->path.pathkeys = NIL;
643 pathnode->subpath = subpath;
646 * If the input is a subquery whose output must be unique already,
647 * we don't need to do anything.
649 if (rel->rtekind == RTE_SUBQUERY)
651 RangeTblEntry *rte = rt_fetch(rel->relid, root->rtable);
653 if (is_distinct_query(rte->subquery))
655 pathnode->umethod = UNIQUE_PATH_NOOP;
656 pathnode->rows = rel->rows;
657 pathnode->path.startup_cost = subpath->startup_cost;
658 pathnode->path.total_cost = subpath->total_cost;
659 pathnode->path.pathkeys = subpath->pathkeys;
661 rel->cheapest_unique_path = (Path *) pathnode;
668 * Try to identify the targetlist that will actually be unique-ified.
669 * In current usage, this routine is only used for sub-selects of IN
670 * clauses, so we should be able to find the tlist in in_info_list.
672 sub_targetlist = NIL;
673 foreach(l, root->in_info_list)
675 InClauseInfo *ininfo = (InClauseInfo *) lfirst(l);
677 if (bms_equal(ininfo->righthand, rel->relids))
679 sub_targetlist = ininfo->sub_targetlist;
685 * If we know the targetlist, try to estimate number of result rows;
690 pathnode->rows = estimate_num_groups(root, sub_targetlist, rel->rows);
691 numCols = length(sub_targetlist);
695 pathnode->rows = rel->rows;
696 numCols = length(FastListValue(&rel->reltargetlist));
700 * Estimate cost for sort+unique implementation
702 cost_sort(&sort_path, root, NIL,
708 * Charge one cpu_operator_cost per comparison per input tuple. We
709 * assume all columns get compared at most of the tuples. (XXX
710 * probably this is an overestimate.) This should agree with
713 sort_path.total_cost += cpu_operator_cost * rel->rows * numCols;
716 * Is it safe to use a hashed implementation? If so, estimate and
717 * compare costs. We only try this if we know the targetlist for sure
718 * (else we can't be sure about the datatypes involved).
720 pathnode->umethod = UNIQUE_PATH_SORT;
721 if (enable_hashagg && sub_targetlist && hash_safe_tlist(sub_targetlist))
724 * Estimate the overhead per hashtable entry at 64 bytes (same as
727 int hashentrysize = rel->width + 64;
729 if (hashentrysize * pathnode->rows <= work_mem * 1024L)
731 cost_agg(&agg_path, root,
733 numCols, pathnode->rows,
734 subpath->startup_cost,
737 if (agg_path.total_cost < sort_path.total_cost)
738 pathnode->umethod = UNIQUE_PATH_HASH;
742 if (pathnode->umethod == UNIQUE_PATH_HASH)
744 pathnode->path.startup_cost = agg_path.startup_cost;
745 pathnode->path.total_cost = agg_path.total_cost;
749 pathnode->path.startup_cost = sort_path.startup_cost;
750 pathnode->path.total_cost = sort_path.total_cost;
753 rel->cheapest_unique_path = (Path *) pathnode;
759 * is_distinct_query - does query never return duplicate rows?
762 is_distinct_query(Query *query)
764 /* DISTINCT (but not DISTINCT ON) guarantees uniqueness */
765 if (has_distinct_clause(query))
768 /* UNION, INTERSECT, EXCEPT guarantee uniqueness, except with ALL */
769 if (query->setOperations)
771 SetOperationStmt *topop = (SetOperationStmt *) query->setOperations;
773 Assert(IsA(topop, SetOperationStmt));
774 Assert(topop->op != SETOP_NONE);
781 * GROUP BY guarantees uniqueness if all the grouped columns appear in
782 * the output. In our implementation this means checking they are non
785 if (query->groupClause)
789 foreach(gl, query->groupClause)
791 GroupClause *grpcl = (GroupClause *) lfirst(gl);
792 TargetEntry *tle = get_sortgroupclause_tle(grpcl,
795 if (tle->resdom->resjunk)
798 if (!gl) /* got to the end? */
803 * XXX Are there any other cases in which we can easily see the result
811 * hash_safe_tlist - can datatypes of given tlist be hashed?
813 * We assume hashed aggregation will work if the datatype's equality operator
814 * is marked hashjoinable.
816 * XXX this probably should be somewhere else. See also hash_safe_grouping
820 hash_safe_tlist(List *tlist)
826 Node *expr = (Node *) lfirst(tl);
830 optup = equality_oper(exprType(expr), true);
833 oprcanhash = ((Form_pg_operator) GETSTRUCT(optup))->oprcanhash;
834 ReleaseSysCache(optup);
842 * create_subqueryscan_path
843 * Creates a path corresponding to a sequential scan of a subquery,
844 * returning the pathnode.
847 create_subqueryscan_path(RelOptInfo *rel, List *pathkeys)
849 Path *pathnode = makeNode(Path);
851 pathnode->pathtype = T_SubqueryScan;
852 pathnode->parent = rel;
853 pathnode->pathkeys = pathkeys;
855 cost_subqueryscan(pathnode, rel);
861 * create_functionscan_path
862 * Creates a path corresponding to a sequential scan of a function,
863 * returning the pathnode.
866 create_functionscan_path(Query *root, RelOptInfo *rel)
868 Path *pathnode = makeNode(Path);
870 pathnode->pathtype = T_FunctionScan;
871 pathnode->parent = rel;
872 pathnode->pathkeys = NIL; /* for now, assume unordered result */
874 cost_functionscan(pathnode, root, rel);
880 * create_nestloop_path
881 * Creates a pathnode corresponding to a nestloop join between two
884 * 'joinrel' is the join relation.
885 * 'jointype' is the type of join required
886 * 'outer_path' is the outer path
887 * 'inner_path' is the inner path
888 * 'restrict_clauses' are the RestrictInfo nodes to apply at the join
889 * 'pathkeys' are the path keys of the new join path
891 * Returns the resulting path node.
894 create_nestloop_path(Query *root,
899 List *restrict_clauses,
902 NestPath *pathnode = makeNode(NestPath);
904 pathnode->path.pathtype = T_NestLoop;
905 pathnode->path.parent = joinrel;
906 pathnode->jointype = jointype;
907 pathnode->outerjoinpath = outer_path;
908 pathnode->innerjoinpath = inner_path;
909 pathnode->joinrestrictinfo = restrict_clauses;
910 pathnode->path.pathkeys = pathkeys;
912 cost_nestloop(pathnode, root);
918 * create_mergejoin_path
919 * Creates a pathnode corresponding to a mergejoin join between
922 * 'joinrel' is the join relation
923 * 'jointype' is the type of join required
924 * 'outer_path' is the outer path
925 * 'inner_path' is the inner path
926 * 'restrict_clauses' are the RestrictInfo nodes to apply at the join
927 * 'pathkeys' are the path keys of the new join path
928 * 'mergeclauses' are the RestrictInfo nodes to use as merge clauses
929 * (this should be a subset of the restrict_clauses list)
930 * 'outersortkeys' are the sort varkeys for the outer relation
931 * 'innersortkeys' are the sort varkeys for the inner relation
934 create_mergejoin_path(Query *root,
939 List *restrict_clauses,
945 MergePath *pathnode = makeNode(MergePath);
948 * If the given paths are already well enough ordered, we can skip
949 * doing an explicit sort.
952 pathkeys_contained_in(outersortkeys, outer_path->pathkeys))
955 pathkeys_contained_in(innersortkeys, inner_path->pathkeys))
959 * If we are not sorting the inner path, we may need a materialize
960 * node to ensure it can be marked/restored. (Sort does support
961 * mark/restore, so no materialize is needed in that case.)
963 * Since the inner side must be ordered, and only Sorts and IndexScans
964 * can create order to begin with, you might think there's no problem
965 * --- but you'd be wrong. Nestloop and merge joins can *preserve*
966 * the order of their inputs, so they can be selected as the input of
967 * a mergejoin, and they don't support mark/restore at present.
969 if (innersortkeys == NIL &&
970 !ExecSupportsMarkRestore(inner_path->pathtype))
971 inner_path = (Path *)
972 create_material_path(inner_path->parent, inner_path);
974 pathnode->jpath.path.pathtype = T_MergeJoin;
975 pathnode->jpath.path.parent = joinrel;
976 pathnode->jpath.jointype = jointype;
977 pathnode->jpath.outerjoinpath = outer_path;
978 pathnode->jpath.innerjoinpath = inner_path;
979 pathnode->jpath.joinrestrictinfo = restrict_clauses;
980 pathnode->jpath.path.pathkeys = pathkeys;
981 pathnode->path_mergeclauses = mergeclauses;
982 pathnode->outersortkeys = outersortkeys;
983 pathnode->innersortkeys = innersortkeys;
985 cost_mergejoin(pathnode, root);
991 * create_hashjoin_path
992 * Creates a pathnode corresponding to a hash join between two relations.
994 * 'joinrel' is the join relation
995 * 'jointype' is the type of join required
996 * 'outer_path' is the cheapest outer path
997 * 'inner_path' is the cheapest inner path
998 * 'restrict_clauses' are the RestrictInfo nodes to apply at the join
999 * 'hashclauses' are the RestrictInfo nodes to use as hash clauses
1000 * (this should be a subset of the restrict_clauses list)
1003 create_hashjoin_path(Query *root,
1004 RelOptInfo *joinrel,
1008 List *restrict_clauses,
1011 HashPath *pathnode = makeNode(HashPath);
1013 pathnode->jpath.path.pathtype = T_HashJoin;
1014 pathnode->jpath.path.parent = joinrel;
1015 pathnode->jpath.jointype = jointype;
1016 pathnode->jpath.outerjoinpath = outer_path;
1017 pathnode->jpath.innerjoinpath = inner_path;
1018 pathnode->jpath.joinrestrictinfo = restrict_clauses;
1019 /* A hashjoin never has pathkeys, since its ordering is unpredictable */
1020 pathnode->jpath.path.pathkeys = NIL;
1021 pathnode->path_hashclauses = hashclauses;
1023 cost_hashjoin(pathnode, root);