1 /*-------------------------------------------------------------------------
4 * Routines to find possible search paths for processing a query
6 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.133 2005/06/09 04:18:59 tgl Exp $
13 *-------------------------------------------------------------------------
18 #ifdef OPTIMIZER_DEBUG
19 #include "nodes/print.h"
21 #include "optimizer/clauses.h"
22 #include "optimizer/cost.h"
23 #include "optimizer/geqo.h"
24 #include "optimizer/pathnode.h"
25 #include "optimizer/paths.h"
26 #include "optimizer/plancat.h"
27 #include "optimizer/planner.h"
28 #include "optimizer/prep.h"
29 #include "optimizer/var.h"
30 #include "parser/parsetree.h"
31 #include "parser/parse_clause.h"
32 #include "parser/parse_expr.h"
33 #include "rewrite/rewriteManip.h"
36 /* These parameters are set by GUC */
37 bool enable_geqo = false; /* just in case GUC doesn't set it */
41 static void set_base_rel_pathlists(PlannerInfo *root);
42 static void set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
44 static void set_inherited_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
45 Index rti, RangeTblEntry *rte,
47 static void set_subquery_pathlist(PlannerInfo *root, RelOptInfo *rel,
48 Index rti, RangeTblEntry *rte);
49 static void set_function_pathlist(PlannerInfo *root, RelOptInfo *rel,
51 static RelOptInfo *make_one_rel_by_joins(PlannerInfo *root, int levels_needed,
53 static bool subquery_is_pushdown_safe(Query *subquery, Query *topquery,
54 bool *differentTypes);
55 static bool recurse_pushdown_safe(Node *setOp, Query *topquery,
56 bool *differentTypes);
57 static void compare_tlist_datatypes(List *tlist, List *colTypes,
58 bool *differentTypes);
59 static bool qual_is_pushdown_safe(Query *subquery, Index rti, Node *qual,
60 bool *differentTypes);
61 static void subquery_push_qual(Query *subquery,
62 RangeTblEntry *rte, Index rti, Node *qual);
63 static void recurse_push_qual(Node *setOp, Query *topquery,
64 RangeTblEntry *rte, Index rti, Node *qual);
69 * Finds all possible access paths for executing a query, returning a
70 * single rel that represents the join of all base rels in the query.
73 make_one_rel(PlannerInfo *root)
78 * Generate access paths for the base rels.
80 set_base_rel_pathlists(root);
83 * Generate access paths for the entire join tree.
85 Assert(root->parse->jointree != NULL &&
86 IsA(root->parse->jointree, FromExpr));
88 rel = make_fromexpr_rel(root, root->parse->jointree);
91 * The result should join all and only the query's base rels.
93 #ifdef USE_ASSERT_CHECKING
95 int num_base_rels = 0;
98 for (rti = 1; rti < root->base_rel_array_size; rti++)
100 RelOptInfo *brel = root->base_rel_array[rti];
105 Assert(brel->relid == rti); /* sanity check on array */
107 /* ignore RTEs that are "other rels" */
108 if (brel->reloptkind != RELOPT_BASEREL)
111 Assert(bms_is_member(rti, rel->relids));
115 Assert(bms_num_members(rel->relids) == num_base_rels);
123 * set_base_rel_pathlists
124 * Finds all paths available for scanning each base-relation entry.
125 * Sequential scan and any available indices are considered.
126 * Each useful path is attached to its relation's 'pathlist' field.
129 set_base_rel_pathlists(PlannerInfo *root)
134 * Note: because we call expand_inherited_rtentry inside the loop,
135 * it's quite possible for the base_rel_array to be enlarged while
136 * the loop runs. Hence don't try to optimize the loop.
138 for (rti = 1; rti < root->base_rel_array_size; rti++)
140 RelOptInfo *rel = root->base_rel_array[rti];
144 /* there may be empty slots corresponding to non-baserel RTEs */
148 Assert(rel->relid == rti); /* sanity check on array */
150 /* ignore RTEs that are "other rels" */
151 if (rel->reloptkind != RELOPT_BASEREL)
154 rte = rt_fetch(rti, root->parse->rtable);
156 if (rel->rtekind == RTE_SUBQUERY)
158 /* Subquery --- generate a separate plan for it */
159 set_subquery_pathlist(root, rel, rti, rte);
161 else if (rel->rtekind == RTE_FUNCTION)
163 /* RangeFunction --- generate a separate plan for it */
164 set_function_pathlist(root, rel, rte);
166 else if ((inheritlist = expand_inherited_rtentry(root, rti)) != NIL)
168 /* Relation is root of an inheritance tree, process specially */
169 set_inherited_rel_pathlist(root, rel, rti, rte, inheritlist);
174 set_plain_rel_pathlist(root, rel, rte);
177 #ifdef OPTIMIZER_DEBUG
178 debug_print_rel(root, rel);
184 * set_plain_rel_pathlist
185 * Build access paths for a plain relation (no subquery, no inheritance)
188 set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
190 /* Mark rel with estimated output rows, width, etc */
191 set_baserel_size_estimates(root, rel);
193 /* Test any partial indexes of rel for applicability */
194 check_partial_indexes(root, rel);
197 * Check to see if we can extract any restriction conditions from join
198 * quals that are OR-of-AND structures. If so, add them to the rel's
199 * restriction list, and recompute the size estimates.
201 if (create_or_index_quals(root, rel))
202 set_baserel_size_estimates(root, rel);
205 * Generate paths and add them to the rel's pathlist.
207 * Note: add_path() will discard any paths that are dominated by another
208 * available path, keeping only those paths that are superior along at
209 * least one dimension of cost or sortedness.
212 /* Consider sequential scan */
213 add_path(rel, create_seqscan_path(root, rel));
215 /* Consider index scans */
216 create_index_paths(root, rel);
218 /* Consider TID scans */
219 create_tidscan_paths(root, rel);
221 /* Now find the cheapest of the paths for this rel */
226 * set_inherited_rel_pathlist
227 * Build access paths for a inheritance tree rooted at rel
229 * inheritlist is a list of RT indexes of all tables in the inheritance tree,
230 * including a duplicate of the parent itself. Note we will not come here
231 * unless there's at least one child in addition to the parent.
233 * NOTE: the passed-in rel and RTE will henceforth represent the appended
234 * result of the whole inheritance tree. The members of inheritlist represent
235 * the individual tables --- in particular, the inheritlist member that is a
236 * duplicate of the parent RTE represents the parent table alone.
237 * We will generate plans to scan the individual tables that refer to
238 * the inheritlist RTEs, whereas Vars elsewhere in the plan tree that
239 * refer to the original RTE are taken to refer to the append output.
240 * In particular, this means we have separate RelOptInfos for the parent
241 * table and for the append output, which is a good thing because they're
245 set_inherited_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
246 Index rti, RangeTblEntry *rte,
249 int parentRTindex = rti;
250 Oid parentOID = rte->relid;
251 List *subpaths = NIL;
255 * XXX for now, can't handle inherited expansion of FOR UPDATE/SHARE;
258 if (list_member_int(root->parse->rowMarks, parentRTindex))
260 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
261 errmsg("SELECT FOR UPDATE/SHARE is not supported for inheritance queries")));
264 * Initialize to compute size estimates for whole inheritance tree
270 * Generate access paths for each table in the tree (parent AND
271 * children), and pick the cheapest path for each table.
273 foreach(il, inheritlist)
275 int childRTindex = lfirst_int(il);
276 RangeTblEntry *childrte;
278 RelOptInfo *childrel;
279 ListCell *parentvars;
282 childrte = rt_fetch(childRTindex, root->parse->rtable);
283 childOID = childrte->relid;
286 * Make a RelOptInfo for the child so we can do planning.
287 * Mark it as an "other rel" since it will not be part of the
290 childrel = build_other_rel(root, childRTindex);
293 * Copy the parent's targetlist and restriction quals to the
294 * child, with attribute-number adjustment as needed. We don't
295 * bother to copy the join quals, since we can't do any joining of
296 * the individual tables. Also, we just zap attr_needed rather
297 * than trying to adjust it; it won't be looked at in the child.
299 childrel->reltargetlist = (List *)
300 adjust_inherited_attrs((Node *) rel->reltargetlist,
305 childrel->attr_needed = NULL;
306 childrel->baserestrictinfo = (List *)
307 adjust_inherited_attrs((Node *) rel->baserestrictinfo,
314 * Now compute child access paths, and save the cheapest.
316 set_plain_rel_pathlist(root, childrel, childrte);
318 subpaths = lappend(subpaths, childrel->cheapest_total_path);
321 * Propagate size information from the child back to the parent.
322 * For simplicity, we use the largest widths from any child as the
325 rel->rows += childrel->rows;
326 if (childrel->width > rel->width)
327 rel->width = childrel->width;
329 forboth(parentvars, rel->reltargetlist,
330 childvars, childrel->reltargetlist)
332 Var *parentvar = (Var *) lfirst(parentvars);
333 Var *childvar = (Var *) lfirst(childvars);
335 if (IsA(parentvar, Var) &&IsA(childvar, Var))
337 int pndx = parentvar->varattno - rel->min_attr;
338 int cndx = childvar->varattno - childrel->min_attr;
340 if (childrel->attr_widths[cndx] > rel->attr_widths[pndx])
341 rel->attr_widths[pndx] = childrel->attr_widths[cndx];
347 * Finally, build Append path and install it as the only access path
348 * for the parent rel.
350 add_path(rel, (Path *) create_append_path(rel, subpaths));
352 /* Select cheapest path (pretty easy in this case...) */
357 * set_subquery_pathlist
358 * Build the (single) access path for a subquery RTE
361 set_subquery_pathlist(PlannerInfo *root, RelOptInfo *rel,
362 Index rti, RangeTblEntry *rte)
364 Query *subquery = rte->subquery;
365 bool *differentTypes;
367 List *subquery_pathkeys;
369 /* We need a workspace for keeping track of set-op type coercions */
370 differentTypes = (bool *)
371 palloc0((list_length(subquery->targetList) + 1) * sizeof(bool));
374 * If there are any restriction clauses that have been attached to the
375 * subquery relation, consider pushing them down to become WHERE or
376 * HAVING quals of the subquery itself. This transformation is useful
377 * because it may allow us to generate a better plan for the subquery
378 * than evaluating all the subquery output rows and then filtering them.
380 * There are several cases where we cannot push down clauses.
381 * Restrictions involving the subquery are checked by
382 * subquery_is_pushdown_safe(). Restrictions on individual clauses
383 * are checked by qual_is_pushdown_safe().
385 * Non-pushed-down clauses will get evaluated as qpquals of the
388 * XXX Are there any cases where we want to make a policy decision not to
389 * push down a pushable qual, because it'd result in a worse plan?
391 if (rel->baserestrictinfo != NIL &&
392 subquery_is_pushdown_safe(subquery, subquery, differentTypes))
394 /* OK to consider pushing down individual quals */
395 List *upperrestrictlist = NIL;
398 foreach(l, rel->baserestrictinfo)
400 RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
401 Node *clause = (Node *) rinfo->clause;
403 if (qual_is_pushdown_safe(subquery, rti, clause, differentTypes))
406 subquery_push_qual(subquery, rte, rti, clause);
410 /* Keep it in the upper query */
411 upperrestrictlist = lappend(upperrestrictlist, rinfo);
414 rel->baserestrictinfo = upperrestrictlist;
417 pfree(differentTypes);
419 /* Generate the plan for the subquery */
420 rel->subplan = subquery_planner(subquery, 0.0 /* default case */,
423 /* Copy number of output rows from subplan */
424 rel->tuples = rel->subplan->plan_rows;
426 /* Mark rel with estimated output rows, width, etc */
427 set_baserel_size_estimates(root, rel);
429 /* Convert subquery pathkeys to outer representation */
430 pathkeys = convert_subquery_pathkeys(root, rel, subquery_pathkeys);
432 /* Generate appropriate path */
433 add_path(rel, create_subqueryscan_path(rel, pathkeys));
435 /* Select cheapest path (pretty easy in this case...) */
440 * set_function_pathlist
441 * Build the (single) access path for a function RTE
444 set_function_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
446 /* Mark rel with estimated output rows, width, etc */
447 set_function_size_estimates(root, rel);
449 /* Generate appropriate path */
450 add_path(rel, create_functionscan_path(root, rel));
452 /* Select cheapest path (pretty easy in this case...) */
458 * Build access paths for a FromExpr jointree node.
461 make_fromexpr_rel(PlannerInfo *root, FromExpr *from)
464 List *initial_rels = NIL;
468 * Count the number of child jointree nodes. This is the depth of the
469 * dynamic-programming algorithm we must employ to consider all ways
470 * of joining the child nodes.
472 levels_needed = list_length(from->fromlist);
474 if (levels_needed <= 0)
475 return NULL; /* nothing to do? */
478 * Construct a list of rels corresponding to the child jointree nodes.
479 * This may contain both base rels and rels constructed according to
480 * explicit JOIN directives.
482 foreach(jt, from->fromlist)
484 Node *jtnode = (Node *) lfirst(jt);
486 initial_rels = lappend(initial_rels,
487 make_jointree_rel(root, jtnode));
490 if (levels_needed == 1)
493 * Single jointree node, so we're done.
495 return (RelOptInfo *) linitial(initial_rels);
500 * Consider the different orders in which we could join the rels,
501 * using either GEQO or regular optimizer.
503 if (enable_geqo && levels_needed >= geqo_threshold)
504 return geqo(root, levels_needed, initial_rels);
506 return make_one_rel_by_joins(root, levels_needed, initial_rels);
511 * make_one_rel_by_joins
512 * Find all possible joinpaths for a query by successively finding ways
513 * to join component relations into join relations.
515 * 'levels_needed' is the number of iterations needed, ie, the number of
516 * independent jointree items in the query. This is > 1.
518 * 'initial_rels' is a list of RelOptInfo nodes for each independent
519 * jointree item. These are the components to be joined together.
521 * Returns the final level of join relations, i.e., the relation that is
522 * the result of joining all the original relations together.
525 make_one_rel_by_joins(PlannerInfo *root, int levels_needed, List *initial_rels)
532 * We employ a simple "dynamic programming" algorithm: we first find
533 * all ways to build joins of two jointree items, then all ways to
534 * build joins of three items (from two-item joins and single items),
535 * then four-item joins, and so on until we have considered all ways
536 * to join all the items into one rel.
538 * joinitems[j] is a list of all the j-item rels. Initially we set
539 * joinitems[1] to represent all the single-jointree-item relations.
541 joinitems = (List **) palloc0((levels_needed + 1) * sizeof(List *));
543 joinitems[1] = initial_rels;
545 for (lev = 2; lev <= levels_needed; lev++)
550 * Determine all possible pairs of relations to be joined at this
551 * level, and build paths for making each one from every available
552 * pair of lower-level relations.
554 joinitems[lev] = make_rels_by_joins(root, lev, joinitems);
557 * Do cleanup work on each just-processed rel.
559 foreach(x, joinitems[lev])
561 rel = (RelOptInfo *) lfirst(x);
563 /* Find and save the cheapest paths for this rel */
566 #ifdef OPTIMIZER_DEBUG
567 debug_print_rel(root, rel);
573 * We should have a single rel at the final level.
575 if (joinitems[levels_needed] == NIL)
576 elog(ERROR, "failed to build any %d-way joins", levels_needed);
577 Assert(list_length(joinitems[levels_needed]) == 1);
579 rel = (RelOptInfo *) linitial(joinitems[levels_needed]);
584 /*****************************************************************************
585 * PUSHING QUALS DOWN INTO SUBQUERIES
586 *****************************************************************************/
589 * subquery_is_pushdown_safe - is a subquery safe for pushing down quals?
591 * subquery is the particular component query being checked. topquery
592 * is the top component of a set-operations tree (the same Query if no
593 * set-op is involved).
595 * Conditions checked here:
597 * 1. If the subquery has a LIMIT clause, we must not push down any quals,
598 * since that could change the set of rows returned.
600 * 2. If the subquery contains EXCEPT or EXCEPT ALL set ops we cannot push
601 * quals into it, because that would change the results.
603 * 3. For subqueries using UNION/UNION ALL/INTERSECT/INTERSECT ALL, we can
604 * push quals into each component query, but the quals can only reference
605 * subquery columns that suffer no type coercions in the set operation.
606 * Otherwise there are possible semantic gotchas. So, we check the
607 * component queries to see if any of them have different output types;
608 * differentTypes[k] is set true if column k has different type in any
612 subquery_is_pushdown_safe(Query *subquery, Query *topquery,
613 bool *differentTypes)
615 SetOperationStmt *topop;
618 if (subquery->limitOffset != NULL || subquery->limitCount != NULL)
621 /* Are we at top level, or looking at a setop component? */
622 if (subquery == topquery)
624 /* Top level, so check any component queries */
625 if (subquery->setOperations != NULL)
626 if (!recurse_pushdown_safe(subquery->setOperations, topquery,
632 /* Setop component must not have more components (too weird) */
633 if (subquery->setOperations != NULL)
635 /* Check whether setop component output types match top level */
636 topop = (SetOperationStmt *) topquery->setOperations;
637 Assert(topop && IsA(topop, SetOperationStmt));
638 compare_tlist_datatypes(subquery->targetList,
646 * Helper routine to recurse through setOperations tree
649 recurse_pushdown_safe(Node *setOp, Query *topquery,
650 bool *differentTypes)
652 if (IsA(setOp, RangeTblRef))
654 RangeTblRef *rtr = (RangeTblRef *) setOp;
655 RangeTblEntry *rte = rt_fetch(rtr->rtindex, topquery->rtable);
656 Query *subquery = rte->subquery;
658 Assert(subquery != NULL);
659 return subquery_is_pushdown_safe(subquery, topquery, differentTypes);
661 else if (IsA(setOp, SetOperationStmt))
663 SetOperationStmt *op = (SetOperationStmt *) setOp;
665 /* EXCEPT is no good */
666 if (op->op == SETOP_EXCEPT)
669 if (!recurse_pushdown_safe(op->larg, topquery, differentTypes))
671 if (!recurse_pushdown_safe(op->rarg, topquery, differentTypes))
676 elog(ERROR, "unrecognized node type: %d",
677 (int) nodeTag(setOp));
683 * Compare tlist's datatypes against the list of set-operation result types.
684 * For any items that are different, mark the appropriate element of
685 * differentTypes[] to show that this column will have type conversions.
688 compare_tlist_datatypes(List *tlist, List *colTypes,
689 bool *differentTypes)
692 ListCell *colType = list_head(colTypes);
696 TargetEntry *tle = (TargetEntry *) lfirst(l);
699 continue; /* ignore resjunk columns */
701 elog(ERROR, "wrong number of tlist entries");
702 if (exprType((Node *) tle->expr) != lfirst_oid(colType))
703 differentTypes[tle->resno] = true;
704 colType = lnext(colType);
707 elog(ERROR, "wrong number of tlist entries");
711 * qual_is_pushdown_safe - is a particular qual safe to push down?
713 * qual is a restriction clause applying to the given subquery (whose RTE
714 * has index rti in the parent query).
716 * Conditions checked here:
718 * 1. The qual must not contain any subselects (mainly because I'm not sure
719 * it will work correctly: sublinks will already have been transformed into
720 * subplans in the qual, but not in the subquery).
722 * 2. The qual must not refer to any subquery output columns that were
723 * found to have inconsistent types across a set operation tree by
724 * subquery_is_pushdown_safe().
726 * 3. If the subquery uses DISTINCT ON, we must not push down any quals that
727 * refer to non-DISTINCT output columns, because that could change the set
728 * of rows returned. This condition is vacuous for DISTINCT, because then
729 * there are no non-DISTINCT output columns, but unfortunately it's fairly
730 * expensive to tell the difference between DISTINCT and DISTINCT ON in the
731 * parsetree representation. It's cheaper to just make sure all the Vars
732 * in the qual refer to DISTINCT columns.
734 * 4. We must not push down any quals that refer to subselect outputs that
735 * return sets, else we'd introduce functions-returning-sets into the
736 * subquery's WHERE/HAVING quals.
739 qual_is_pushdown_safe(Query *subquery, Index rti, Node *qual,
740 bool *differentTypes)
745 Bitmapset *tested = NULL;
747 /* Refuse subselects (point 1) */
748 if (contain_subplans(qual))
752 * Examine all Vars used in clause; since it's a restriction clause,
753 * all such Vars must refer to subselect output columns.
755 vars = pull_var_clause(qual, false);
758 Var *var = (Var *) lfirst(vl);
761 Assert(var->varno == rti);
764 * We use a bitmapset to avoid testing the same attno more than
765 * once. (NB: this only works because subquery outputs can't have
768 if (bms_is_member(var->varattno, tested))
770 tested = bms_add_member(tested, var->varattno);
773 if (differentTypes[var->varattno])
779 /* Must find the tlist element referenced by the Var */
780 tle = get_tle_by_resno(subquery->targetList, var->varattno);
782 Assert(!tle->resjunk);
784 /* If subquery uses DISTINCT or DISTINCT ON, check point 3 */
785 if (subquery->distinctClause != NIL &&
786 !targetIsInSortList(tle, subquery->distinctClause))
788 /* non-DISTINCT column, so fail */
793 /* Refuse functions returning sets (point 4) */
794 if (expression_returns_set((Node *) tle->expr))
808 * subquery_push_qual - push down a qual that we have determined is safe
811 subquery_push_qual(Query *subquery, RangeTblEntry *rte, Index rti, Node *qual)
813 if (subquery->setOperations != NULL)
815 /* Recurse to push it separately to each component query */
816 recurse_push_qual(subquery->setOperations, subquery,
822 * We need to replace Vars in the qual (which must refer to
823 * outputs of the subquery) with copies of the subquery's
824 * targetlist expressions. Note that at this point, any uplevel
825 * Vars in the qual should have been replaced with Params, so they
828 * This step also ensures that when we are pushing into a setop tree,
829 * each component query gets its own copy of the qual.
831 qual = ResolveNew(qual, rti, 0, rte,
832 subquery->targetList,
836 * Now attach the qual to the proper place: normally WHERE, but
837 * if the subquery uses grouping or aggregation, put it in HAVING
838 * (since the qual really refers to the group-result rows).
840 if (subquery->hasAggs || subquery->groupClause || subquery->havingQual)
841 subquery->havingQual = make_and_qual(subquery->havingQual, qual);
843 subquery->jointree->quals =
844 make_and_qual(subquery->jointree->quals, qual);
847 * We need not change the subquery's hasAggs or hasSublinks flags,
848 * since we can't be pushing down any aggregates that weren't
849 * there before, and we don't push down subselects at all.
855 * Helper routine to recurse through setOperations tree
858 recurse_push_qual(Node *setOp, Query *topquery,
859 RangeTblEntry *rte, Index rti, Node *qual)
861 if (IsA(setOp, RangeTblRef))
863 RangeTblRef *rtr = (RangeTblRef *) setOp;
864 RangeTblEntry *subrte = rt_fetch(rtr->rtindex, topquery->rtable);
865 Query *subquery = subrte->subquery;
867 Assert(subquery != NULL);
868 subquery_push_qual(subquery, rte, rti, qual);
870 else if (IsA(setOp, SetOperationStmt))
872 SetOperationStmt *op = (SetOperationStmt *) setOp;
874 recurse_push_qual(op->larg, topquery, rte, rti, qual);
875 recurse_push_qual(op->rarg, topquery, rte, rti, qual);
879 elog(ERROR, "unrecognized node type: %d",
880 (int) nodeTag(setOp));
884 /*****************************************************************************
886 *****************************************************************************/
888 #ifdef OPTIMIZER_DEBUG
891 print_relids(Relids relids)
897 tmprelids = bms_copy(relids);
898 while ((x = bms_first_member(tmprelids)) >= 0)
909 print_restrictclauses(PlannerInfo *root, List *clauses)
915 RestrictInfo *c = lfirst(l);
917 print_expr((Node *) c->clause, root->parse->rtable);
924 print_path(PlannerInfo *root, Path *path, int indent)
928 Path *subpath = NULL;
931 switch (nodeTag(path))
939 case T_BitmapHeapPath:
940 ptype = "BitmapHeapScan";
942 case T_BitmapAndPath:
943 ptype = "BitmapAndPath";
946 ptype = "BitmapOrPath";
956 subpath = ((ResultPath *) path)->subpath;
960 subpath = ((MaterialPath *) path)->subpath;
964 subpath = ((UniquePath *) path)->subpath;
983 for (i = 0; i < indent; i++)
990 print_relids(path->parent->relids);
991 printf(") rows=%.0f", path->parent->rows);
993 printf(" cost=%.2f..%.2f\n", path->startup_cost, path->total_cost);
997 for (i = 0; i < indent; i++)
999 printf(" pathkeys: ");
1000 print_pathkeys(path->pathkeys, root->parse->rtable);
1005 JoinPath *jp = (JoinPath *) path;
1007 for (i = 0; i < indent; i++)
1009 printf(" clauses: ");
1010 print_restrictclauses(root, jp->joinrestrictinfo);
1013 if (IsA(path, MergePath))
1015 MergePath *mp = (MergePath *) path;
1017 if (mp->outersortkeys || mp->innersortkeys)
1019 for (i = 0; i < indent; i++)
1021 printf(" sortouter=%d sortinner=%d\n",
1022 ((mp->outersortkeys) ? 1 : 0),
1023 ((mp->innersortkeys) ? 1 : 0));
1027 print_path(root, jp->outerjoinpath, indent + 1);
1028 print_path(root, jp->innerjoinpath, indent + 1);
1032 print_path(root, subpath, indent + 1);
1036 debug_print_rel(PlannerInfo *root, RelOptInfo *rel)
1040 printf("RELOPTINFO (");
1041 print_relids(rel->relids);
1042 printf("): rows=%.0f width=%d\n", rel->rows, rel->width);
1044 if (rel->baserestrictinfo)
1046 printf("\tbaserestrictinfo: ");
1047 print_restrictclauses(root, rel->baserestrictinfo);
1053 printf("\tjoininfo: ");
1054 print_restrictclauses(root, rel->joininfo);
1058 printf("\tpath list:\n");
1059 foreach(l, rel->pathlist)
1060 print_path(root, lfirst(l), 1);
1061 printf("\n\tcheapest startup path:\n");
1062 print_path(root, rel->cheapest_startup_path, 1);
1063 printf("\n\tcheapest total path:\n");
1064 print_path(root, rel->cheapest_total_path, 1);
1069 #endif /* OPTIMIZER_DEBUG */