1 /*-------------------------------------------------------------------------
4 * Routines to find possible search paths for processing a query
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/path/allpaths.c,v 1.117 2004/06/01 03:02:51 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 "rewrite/rewriteManip.h"
35 /* These parameters are set by GUC */
36 bool enable_geqo = false; /* just in case GUC doesn't set it */
40 static void set_base_rel_pathlists(Query *root);
41 static void set_plain_rel_pathlist(Query *root, RelOptInfo *rel,
43 static void set_inherited_rel_pathlist(Query *root, RelOptInfo *rel,
44 Index rti, RangeTblEntry *rte,
46 static void set_subquery_pathlist(Query *root, RelOptInfo *rel,
47 Index rti, RangeTblEntry *rte);
48 static void set_function_pathlist(Query *root, RelOptInfo *rel,
50 static RelOptInfo *make_one_rel_by_joins(Query *root, int levels_needed,
52 static bool subquery_is_pushdown_safe(Query *subquery, Query *topquery,
53 bool *differentTypes);
54 static bool recurse_pushdown_safe(Node *setOp, Query *topquery,
55 bool *differentTypes);
56 static void compare_tlist_datatypes(List *tlist, List *colTypes,
57 bool *differentTypes);
58 static bool qual_is_pushdown_safe(Query *subquery, Index rti, Node *qual,
59 bool *differentTypes);
60 static void subquery_push_qual(Query *subquery,
61 RangeTblEntry *rte, Index rti, Node *qual);
62 static void recurse_push_qual(Node *setOp, Query *topquery,
63 RangeTblEntry *rte, Index rti, Node *qual);
68 * Finds all possible access paths for executing a query, returning a
69 * single rel that represents the join of all base rels in the query.
72 make_one_rel(Query *root)
77 * Generate access paths for the base rels.
79 set_base_rel_pathlists(root);
82 * Generate access paths for the entire join tree.
84 Assert(root->jointree != NULL && IsA(root->jointree, FromExpr));
86 rel = make_fromexpr_rel(root, root->jointree);
89 * The result should join all the query's base rels.
91 Assert(bms_num_members(rel->relids) == list_length(root->base_rel_list));
97 * set_base_rel_pathlists
98 * Finds all paths available for scanning each base-relation entry.
99 * Sequential scan and any available indices are considered.
100 * Each useful path is attached to its relation's 'pathlist' field.
103 set_base_rel_pathlists(Query *root)
107 foreach(l, root->base_rel_list)
109 RelOptInfo *rel = (RelOptInfo *) lfirst(l);
110 Index rti = rel->relid;
114 Assert(rti > 0); /* better be base rel */
115 rte = rt_fetch(rti, root->rtable);
117 if (rel->rtekind == RTE_SUBQUERY)
119 /* Subquery --- generate a separate plan for it */
120 set_subquery_pathlist(root, rel, rti, rte);
122 else if (rel->rtekind == RTE_FUNCTION)
124 /* RangeFunction --- generate a separate plan for it */
125 set_function_pathlist(root, rel, rte);
127 else if ((inheritlist = expand_inherited_rtentry(root, rti, true))
130 /* Relation is root of an inheritance tree, process specially */
131 set_inherited_rel_pathlist(root, rel, rti, rte, inheritlist);
136 set_plain_rel_pathlist(root, rel, rte);
139 #ifdef OPTIMIZER_DEBUG
140 debug_print_rel(root, rel);
146 * set_plain_rel_pathlist
147 * Build access paths for a plain relation (no subquery, no inheritance)
150 set_plain_rel_pathlist(Query *root, RelOptInfo *rel, RangeTblEntry *rte)
152 /* Mark rel with estimated output rows, width, etc */
153 set_baserel_size_estimates(root, rel);
155 /* Test any partial indexes of rel for applicability */
156 check_partial_indexes(root, rel);
159 * Check to see if we can extract any restriction conditions from
160 * join quals that are OR-of-AND structures. If so, add them to the
161 * rel's restriction list, and recompute the size estimates.
163 if (create_or_index_quals(root, rel))
164 set_baserel_size_estimates(root, rel);
167 * Generate paths and add them to the rel's pathlist.
169 * Note: add_path() will discard any paths that are dominated by another
170 * available path, keeping only those paths that are superior along at
171 * least one dimension of cost or sortedness.
174 /* Consider sequential scan */
175 add_path(rel, create_seqscan_path(root, rel));
177 /* Consider TID scans */
178 create_tidscan_paths(root, rel);
180 /* Consider index paths for both simple and OR index clauses */
181 create_index_paths(root, rel);
182 create_or_index_paths(root, rel);
184 /* Now find the cheapest of the paths for this rel */
189 * set_inherited_rel_pathlist
190 * Build access paths for a inheritance tree rooted at rel
192 * inheritlist is a list of RT indexes of all tables in the inheritance tree,
193 * including a duplicate of the parent itself. Note we will not come here
194 * unless there's at least one child in addition to the parent.
196 * NOTE: the passed-in rel and RTE will henceforth represent the appended
197 * result of the whole inheritance tree. The members of inheritlist represent
198 * the individual tables --- in particular, the inheritlist member that is a
199 * duplicate of the parent RTE represents the parent table alone.
200 * We will generate plans to scan the individual tables that refer to
201 * the inheritlist RTEs, whereas Vars elsewhere in the plan tree that
202 * refer to the original RTE are taken to refer to the append output.
203 * In particular, this means we have separate RelOptInfos for the parent
204 * table and for the append output, which is a good thing because they're
208 set_inherited_rel_pathlist(Query *root, RelOptInfo *rel,
209 Index rti, RangeTblEntry *rte,
212 int parentRTindex = rti;
213 Oid parentOID = rte->relid;
214 List *subpaths = NIL;
218 * XXX for now, can't handle inherited expansion of FOR UPDATE; can we
221 if (list_member_int(root->rowMarks, parentRTindex))
223 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
224 errmsg("SELECT FOR UPDATE is not supported for inheritance queries")));
227 * The executor will check the parent table's access permissions when
228 * it examines the parent's inheritlist entry. There's no need to
229 * check twice, so turn off access check bits in the original RTE.
231 rte->requiredPerms = 0;
234 * Initialize to compute size estimates for whole inheritance tree
240 * Generate access paths for each table in the tree (parent AND
241 * children), and pick the cheapest path for each table.
243 foreach(il, inheritlist)
245 int childRTindex = lfirst_int(il);
246 RangeTblEntry *childrte;
248 RelOptInfo *childrel;
249 ListCell *parentvars;
252 childrte = rt_fetch(childRTindex, root->rtable);
253 childOID = childrte->relid;
256 * Make a RelOptInfo for the child so we can do planning. Do NOT
257 * attach the RelOptInfo to the query's base_rel_list, however,
258 * since the child is not part of the main join tree. Instead,
259 * the child RelOptInfo is added to other_rel_list.
261 childrel = build_other_rel(root, childRTindex);
264 * Copy the parent's targetlist and restriction quals to the
265 * child, with attribute-number adjustment as needed. We don't
266 * bother to copy the join quals, since we can't do any joining of
267 * the individual tables. Also, we just zap attr_needed rather
268 * than trying to adjust it; it won't be looked at in the child.
270 childrel->reltargetlist = (List *)
271 adjust_inherited_attrs((Node *) rel->reltargetlist,
276 childrel->attr_needed = NULL;
277 childrel->baserestrictinfo = (List *)
278 adjust_inherited_attrs((Node *) rel->baserestrictinfo,
285 * Now compute child access paths, and save the cheapest.
287 set_plain_rel_pathlist(root, childrel, childrte);
289 subpaths = lappend(subpaths, childrel->cheapest_total_path);
292 * Propagate size information from the child back to the parent.
293 * For simplicity, we use the largest widths from any child as the
296 rel->rows += childrel->rows;
297 if (childrel->width > rel->width)
298 rel->width = childrel->width;
300 forboth(parentvars, rel->reltargetlist,
301 childvars, childrel->reltargetlist)
303 Var *parentvar = (Var *) lfirst(parentvars);
304 Var *childvar = (Var *) lfirst(childvars);
305 int parentndx = parentvar->varattno - rel->min_attr;
306 int childndx = childvar->varattno - childrel->min_attr;
308 if (childrel->attr_widths[childndx] > rel->attr_widths[parentndx])
309 rel->attr_widths[parentndx] = childrel->attr_widths[childndx];
314 * Finally, build Append path and install it as the only access path
315 * for the parent rel.
317 add_path(rel, (Path *) create_append_path(rel, subpaths));
319 /* Select cheapest path (pretty easy in this case...) */
324 * set_subquery_pathlist
325 * Build the (single) access path for a subquery RTE
328 set_subquery_pathlist(Query *root, RelOptInfo *rel,
329 Index rti, RangeTblEntry *rte)
331 Query *subquery = rte->subquery;
332 bool *differentTypes;
335 /* We need a workspace for keeping track of set-op type coercions */
336 differentTypes = (bool *)
337 palloc0((list_length(subquery->targetList) + 1) * sizeof(bool));
340 * If there are any restriction clauses that have been attached to the
341 * subquery relation, consider pushing them down to become HAVING
342 * quals of the subquery itself. (Not WHERE clauses, since they may
343 * refer to subquery outputs that are aggregate results. But
344 * planner.c will transfer them into the subquery's WHERE if they do
345 * not.) This transformation is useful because it may allow us to
346 * generate a better plan for the subquery than evaluating all the
347 * subquery output rows and then filtering them.
349 * There are several cases where we cannot push down clauses.
350 * Restrictions involving the subquery are checked by
351 * subquery_is_pushdown_safe(). Restrictions on individual clauses
352 * are checked by qual_is_pushdown_safe().
354 * Non-pushed-down clauses will get evaluated as qpquals of the
357 * XXX Are there any cases where we want to make a policy decision not to
358 * push down a pushable qual, because it'd result in a worse plan?
360 if (rel->baserestrictinfo != NIL &&
361 subquery_is_pushdown_safe(subquery, subquery, differentTypes))
363 /* OK to consider pushing down individual quals */
364 List *upperrestrictlist = NIL;
367 foreach(l, rel->baserestrictinfo)
369 RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
370 Node *clause = (Node *) rinfo->clause;
372 if (qual_is_pushdown_safe(subquery, rti, clause, differentTypes))
375 subquery_push_qual(subquery, rte, rti, clause);
379 /* Keep it in the upper query */
380 upperrestrictlist = lappend(upperrestrictlist, rinfo);
383 rel->baserestrictinfo = upperrestrictlist;
386 pfree(differentTypes);
388 /* Generate the plan for the subquery */
389 rel->subplan = subquery_planner(subquery, 0.0 /* default case */ );
391 /* Copy number of output rows from subplan */
392 rel->tuples = rel->subplan->plan_rows;
394 /* Mark rel with estimated output rows, width, etc */
395 set_baserel_size_estimates(root, rel);
397 /* Convert subquery pathkeys to outer representation */
398 pathkeys = build_subquery_pathkeys(root, rel, subquery);
400 /* Generate appropriate path */
401 add_path(rel, create_subqueryscan_path(rel, pathkeys));
403 /* Select cheapest path (pretty easy in this case...) */
408 * set_function_pathlist
409 * Build the (single) access path for a function RTE
412 set_function_pathlist(Query *root, RelOptInfo *rel, RangeTblEntry *rte)
414 /* Mark rel with estimated output rows, width, etc */
415 set_function_size_estimates(root, rel);
417 /* Generate appropriate path */
418 add_path(rel, create_functionscan_path(root, rel));
420 /* Select cheapest path (pretty easy in this case...) */
426 * Build access paths for a FromExpr jointree node.
429 make_fromexpr_rel(Query *root, FromExpr *from)
432 List *initial_rels = NIL;
436 * Count the number of child jointree nodes. This is the depth of the
437 * dynamic-programming algorithm we must employ to consider all ways
438 * of joining the child nodes.
440 levels_needed = list_length(from->fromlist);
442 if (levels_needed <= 0)
443 return NULL; /* nothing to do? */
446 * Construct a list of rels corresponding to the child jointree nodes.
447 * This may contain both base rels and rels constructed according to
448 * explicit JOIN directives.
450 foreach(jt, from->fromlist)
452 Node *jtnode = (Node *) lfirst(jt);
454 initial_rels = lappend(initial_rels,
455 make_jointree_rel(root, jtnode));
458 if (levels_needed == 1)
461 * Single jointree node, so we're done.
463 return (RelOptInfo *) linitial(initial_rels);
468 * Consider the different orders in which we could join the rels,
469 * using either GEQO or regular optimizer.
471 if (enable_geqo && levels_needed >= geqo_threshold)
472 return geqo(root, levels_needed, initial_rels);
474 return make_one_rel_by_joins(root, levels_needed, initial_rels);
479 * make_one_rel_by_joins
480 * Find all possible joinpaths for a query by successively finding ways
481 * to join component relations into join relations.
483 * 'levels_needed' is the number of iterations needed, ie, the number of
484 * independent jointree items in the query. This is > 1.
486 * 'initial_rels' is a list of RelOptInfo nodes for each independent
487 * jointree item. These are the components to be joined together.
489 * Returns the final level of join relations, i.e., the relation that is
490 * the result of joining all the original relations together.
493 make_one_rel_by_joins(Query *root, int levels_needed, List *initial_rels)
500 * We employ a simple "dynamic programming" algorithm: we first find
501 * all ways to build joins of two jointree items, then all ways to
502 * build joins of three items (from two-item joins and single items),
503 * then four-item joins, and so on until we have considered all ways
504 * to join all the items into one rel.
506 * joinitems[j] is a list of all the j-item rels. Initially we set
507 * joinitems[1] to represent all the single-jointree-item relations.
509 joinitems = (List **) palloc0((levels_needed + 1) * sizeof(List *));
511 joinitems[1] = initial_rels;
513 for (lev = 2; lev <= levels_needed; lev++)
518 * Determine all possible pairs of relations to be joined at this
519 * level, and build paths for making each one from every available
520 * pair of lower-level relations.
522 joinitems[lev] = make_rels_by_joins(root, lev, joinitems);
525 * Do cleanup work on each just-processed rel.
527 foreach(x, joinitems[lev])
529 rel = (RelOptInfo *) lfirst(x);
531 /* Find and save the cheapest paths for this rel */
534 #ifdef OPTIMIZER_DEBUG
535 debug_print_rel(root, rel);
541 * We should have a single rel at the final level.
543 if (joinitems[levels_needed] == NIL)
544 elog(ERROR, "failed to build any %d-way joins", levels_needed);
545 Assert(list_length(joinitems[levels_needed]) == 1);
547 rel = (RelOptInfo *) linitial(joinitems[levels_needed]);
552 /*****************************************************************************
553 * PUSHING QUALS DOWN INTO SUBQUERIES
554 *****************************************************************************/
557 * subquery_is_pushdown_safe - is a subquery safe for pushing down quals?
559 * subquery is the particular component query being checked. topquery
560 * is the top component of a set-operations tree (the same Query if no
561 * set-op is involved).
563 * Conditions checked here:
565 * 1. If the subquery has a LIMIT clause, we must not push down any quals,
566 * since that could change the set of rows returned.
568 * 2. If the subquery contains EXCEPT or EXCEPT ALL set ops we cannot push
569 * quals into it, because that would change the results.
571 * 3. For subqueries using UNION/UNION ALL/INTERSECT/INTERSECT ALL, we can
572 * push quals into each component query, but the quals can only reference
573 * subquery columns that suffer no type coercions in the set operation.
574 * Otherwise there are possible semantic gotchas. So, we check the
575 * component queries to see if any of them have different output types;
576 * differentTypes[k] is set true if column k has different type in any
580 subquery_is_pushdown_safe(Query *subquery, Query *topquery,
581 bool *differentTypes)
583 SetOperationStmt *topop;
586 if (subquery->limitOffset != NULL || subquery->limitCount != NULL)
589 /* Are we at top level, or looking at a setop component? */
590 if (subquery == topquery)
592 /* Top level, so check any component queries */
593 if (subquery->setOperations != NULL)
594 if (!recurse_pushdown_safe(subquery->setOperations, topquery,
600 /* Setop component must not have more components (too weird) */
601 if (subquery->setOperations != NULL)
603 /* Check whether setop component output types match top level */
604 topop = (SetOperationStmt *) topquery->setOperations;
605 Assert(topop && IsA(topop, SetOperationStmt));
606 compare_tlist_datatypes(subquery->targetList,
614 * Helper routine to recurse through setOperations tree
617 recurse_pushdown_safe(Node *setOp, Query *topquery,
618 bool *differentTypes)
620 if (IsA(setOp, RangeTblRef))
622 RangeTblRef *rtr = (RangeTblRef *) setOp;
623 RangeTblEntry *rte = rt_fetch(rtr->rtindex, topquery->rtable);
624 Query *subquery = rte->subquery;
626 Assert(subquery != NULL);
627 return subquery_is_pushdown_safe(subquery, topquery, differentTypes);
629 else if (IsA(setOp, SetOperationStmt))
631 SetOperationStmt *op = (SetOperationStmt *) setOp;
633 /* EXCEPT is no good */
634 if (op->op == SETOP_EXCEPT)
637 if (!recurse_pushdown_safe(op->larg, topquery, differentTypes))
639 if (!recurse_pushdown_safe(op->rarg, topquery, differentTypes))
644 elog(ERROR, "unrecognized node type: %d",
645 (int) nodeTag(setOp));
651 * Compare tlist's datatypes against the list of set-operation result types.
652 * For any items that are different, mark the appropriate element of
653 * differentTypes[] to show that this column will have type conversions.
656 compare_tlist_datatypes(List *tlist, List *colTypes,
657 bool *differentTypes)
660 ListCell *colType = list_head(colTypes);
664 TargetEntry *tle = (TargetEntry *) lfirst(l);
666 if (tle->resdom->resjunk)
667 continue; /* ignore resjunk columns */
669 elog(ERROR, "wrong number of tlist entries");
670 if (tle->resdom->restype != lfirst_oid(colType))
671 differentTypes[tle->resdom->resno] = true;
672 colType = lnext(colType);
675 elog(ERROR, "wrong number of tlist entries");
679 * qual_is_pushdown_safe - is a particular qual safe to push down?
681 * qual is a restriction clause applying to the given subquery (whose RTE
682 * has index rti in the parent query).
684 * Conditions checked here:
686 * 1. The qual must not contain any subselects (mainly because I'm not sure
687 * it will work correctly: sublinks will already have been transformed into
688 * subplans in the qual, but not in the subquery).
690 * 2. The qual must not refer to any subquery output columns that were
691 * found to have inconsistent types across a set operation tree by
692 * subquery_is_pushdown_safe().
694 * 3. If the subquery uses DISTINCT ON, we must not push down any quals that
695 * refer to non-DISTINCT output columns, because that could change the set
696 * of rows returned. This condition is vacuous for DISTINCT, because then
697 * there are no non-DISTINCT output columns, but unfortunately it's fairly
698 * expensive to tell the difference between DISTINCT and DISTINCT ON in the
699 * parsetree representation. It's cheaper to just make sure all the Vars
700 * in the qual refer to DISTINCT columns.
702 * 4. We must not push down any quals that refer to subselect outputs that
703 * return sets, else we'd introduce functions-returning-sets into the
704 * subquery's WHERE/HAVING quals.
707 qual_is_pushdown_safe(Query *subquery, Index rti, Node *qual,
708 bool *differentTypes)
713 Bitmapset *tested = NULL;
715 /* Refuse subselects (point 1) */
716 if (contain_subplans(qual))
720 * Examine all Vars used in clause; since it's a restriction clause,
721 * all such Vars must refer to subselect output columns.
723 vars = pull_var_clause(qual, false);
726 Var *var = (Var *) lfirst(vl);
729 Assert(var->varno == rti);
732 * We use a bitmapset to avoid testing the same attno more than
733 * once. (NB: this only works because subquery outputs can't have
736 if (bms_is_member(var->varattno, tested))
738 tested = bms_add_member(tested, var->varattno);
741 if (differentTypes[var->varattno])
747 /* Must find the tlist element referenced by the Var */
748 tle = get_tle_by_resno(subquery->targetList, var->varattno);
750 Assert(!tle->resdom->resjunk);
752 /* If subquery uses DISTINCT or DISTINCT ON, check point 3 */
753 if (subquery->distinctClause != NIL &&
754 !targetIsInSortList(tle, subquery->distinctClause))
756 /* non-DISTINCT column, so fail */
761 /* Refuse functions returning sets (point 4) */
762 if (expression_returns_set((Node *) tle->expr))
776 * subquery_push_qual - push down a qual that we have determined is safe
779 subquery_push_qual(Query *subquery, RangeTblEntry *rte, Index rti, Node *qual)
781 if (subquery->setOperations != NULL)
783 /* Recurse to push it separately to each component query */
784 recurse_push_qual(subquery->setOperations, subquery, rte, rti, qual);
789 * We need to replace Vars in the qual (which must refer to
790 * outputs of the subquery) with copies of the subquery's
791 * targetlist expressions. Note that at this point, any uplevel
792 * Vars in the qual should have been replaced with Params, so they
795 * This step also ensures that when we are pushing into a setop tree,
796 * each component query gets its own copy of the qual.
798 qual = ResolveNew(qual, rti, 0, rte,
799 subquery->targetList,
801 subquery->havingQual = make_and_qual(subquery->havingQual,
805 * We need not change the subquery's hasAggs or hasSublinks flags,
806 * since we can't be pushing down any aggregates that weren't
807 * there before, and we don't push down subselects at all.
813 * Helper routine to recurse through setOperations tree
816 recurse_push_qual(Node *setOp, Query *topquery,
817 RangeTblEntry *rte, Index rti, Node *qual)
819 if (IsA(setOp, RangeTblRef))
821 RangeTblRef *rtr = (RangeTblRef *) setOp;
822 RangeTblEntry *subrte = rt_fetch(rtr->rtindex, topquery->rtable);
823 Query *subquery = subrte->subquery;
825 Assert(subquery != NULL);
826 subquery_push_qual(subquery, rte, rti, qual);
828 else if (IsA(setOp, SetOperationStmt))
830 SetOperationStmt *op = (SetOperationStmt *) setOp;
832 recurse_push_qual(op->larg, topquery, rte, rti, qual);
833 recurse_push_qual(op->rarg, topquery, rte, rti, qual);
837 elog(ERROR, "unrecognized node type: %d",
838 (int) nodeTag(setOp));
842 /*****************************************************************************
844 *****************************************************************************/
846 #ifdef OPTIMIZER_DEBUG
849 print_relids(Relids relids)
855 tmprelids = bms_copy(relids);
856 while ((x = bms_first_member(tmprelids)) >= 0)
867 print_restrictclauses(Query *root, List *clauses)
873 RestrictInfo *c = lfirst(l);
875 print_expr((Node *) c->clause, root->rtable);
882 print_path(Query *root, Path *path, int indent)
886 Path *subpath = NULL;
889 switch (nodeTag(path))
905 subpath = ((ResultPath *) path)->subpath;
909 subpath = ((MaterialPath *) path)->subpath;
913 subpath = ((UniquePath *) path)->subpath;
932 for (i = 0; i < indent; i++)
939 print_relids(path->parent->relids);
940 printf(") rows=%.0f", path->parent->rows);
942 printf(" cost=%.2f..%.2f\n", path->startup_cost, path->total_cost);
946 for (i = 0; i < indent; i++)
948 printf(" pathkeys: ");
949 print_pathkeys(path->pathkeys, root->rtable);
954 JoinPath *jp = (JoinPath *) path;
956 for (i = 0; i < indent; i++)
958 printf(" clauses: ");
959 print_restrictclauses(root, jp->joinrestrictinfo);
962 if (IsA(path, MergePath))
964 MergePath *mp = (MergePath *) path;
966 if (mp->outersortkeys || mp->innersortkeys)
968 for (i = 0; i < indent; i++)
970 printf(" sortouter=%d sortinner=%d\n",
971 ((mp->outersortkeys) ? 1 : 0),
972 ((mp->innersortkeys) ? 1 : 0));
976 print_path(root, jp->outerjoinpath, indent + 1);
977 print_path(root, jp->innerjoinpath, indent + 1);
981 print_path(root, subpath, indent + 1);
985 debug_print_rel(Query *root, RelOptInfo *rel)
989 printf("RELOPTINFO (");
990 print_relids(rel->relids);
991 printf("): rows=%.0f width=%d\n", rel->rows, rel->width);
993 if (rel->baserestrictinfo)
995 printf("\tbaserestrictinfo: ");
996 print_restrictclauses(root, rel->baserestrictinfo);
1000 foreach(l, rel->joininfo)
1002 JoinInfo *j = (JoinInfo *) lfirst(l);
1004 printf("\tjoininfo (");
1005 print_relids(j->unjoined_relids);
1007 print_restrictclauses(root, j->jinfo_restrictinfo);
1011 printf("\tpath list:\n");
1012 foreach(l, rel->pathlist)
1013 print_path(root, lfirst(l), 1);
1014 printf("\n\tcheapest startup path:\n");
1015 print_path(root, rel->cheapest_startup_path, 1);
1016 printf("\n\tcheapest total path:\n");
1017 print_path(root, rel->cheapest_total_path, 1);
1022 #endif /* OPTIMIZER_DEBUG */