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.127 2005/04/21 19:18:12 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(Query *root);
42 static void set_plain_rel_pathlist(Query *root, RelOptInfo *rel,
44 static void set_inherited_rel_pathlist(Query *root, RelOptInfo *rel,
45 Index rti, RangeTblEntry *rte,
47 static void set_subquery_pathlist(Query *root, RelOptInfo *rel,
48 Index rti, RangeTblEntry *rte);
49 static void set_function_pathlist(Query *root, RelOptInfo *rel,
51 static RelOptInfo *make_one_rel_by_joins(Query *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, List *rtable,
62 Index rti, Node *qual);
63 static void recurse_push_qual(Node *setOp, Query *topquery,
64 List *rtable, 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(Query *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->jointree != NULL && IsA(root->jointree, FromExpr));
87 rel = make_fromexpr_rel(root, root->jointree);
90 * The result should join all the query's base rels.
92 Assert(bms_num_members(rel->relids) == list_length(root->base_rel_list));
98 * set_base_rel_pathlists
99 * Finds all paths available for scanning each base-relation entry.
100 * Sequential scan and any available indices are considered.
101 * Each useful path is attached to its relation's 'pathlist' field.
104 set_base_rel_pathlists(Query *root)
108 foreach(l, root->base_rel_list)
110 RelOptInfo *rel = (RelOptInfo *) lfirst(l);
111 Index rti = rel->relid;
115 Assert(rti > 0); /* better be base rel */
116 rte = rt_fetch(rti, root->rtable);
118 if (rel->rtekind == RTE_SUBQUERY)
120 /* Subquery --- generate a separate plan for it */
121 set_subquery_pathlist(root, rel, rti, rte);
123 else if (rel->rtekind == RTE_FUNCTION)
125 /* RangeFunction --- generate a separate plan for it */
126 set_function_pathlist(root, rel, rte);
128 else if ((inheritlist = expand_inherited_rtentry(root, rti)) != NIL)
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 join
160 * quals that are OR-of-AND structures. If so, add them to the rel's
161 * 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 * Initialize to compute size estimates for whole inheritance tree
233 * Generate access paths for each table in the tree (parent AND
234 * children), and pick the cheapest path for each table.
236 foreach(il, inheritlist)
238 int childRTindex = lfirst_int(il);
239 RangeTblEntry *childrte;
241 RelOptInfo *childrel;
242 ListCell *parentvars;
245 childrte = rt_fetch(childRTindex, root->rtable);
246 childOID = childrte->relid;
249 * Make a RelOptInfo for the child so we can do planning. Do NOT
250 * attach the RelOptInfo to the query's base_rel_list, however,
251 * since the child is not part of the main join tree. Instead,
252 * the child RelOptInfo is added to other_rel_list.
254 childrel = build_other_rel(root, childRTindex);
257 * Copy the parent's targetlist and restriction quals to the
258 * child, with attribute-number adjustment as needed. We don't
259 * bother to copy the join quals, since we can't do any joining of
260 * the individual tables. Also, we just zap attr_needed rather
261 * than trying to adjust it; it won't be looked at in the child.
263 childrel->reltargetlist = (List *)
264 adjust_inherited_attrs((Node *) rel->reltargetlist,
269 childrel->attr_needed = NULL;
270 childrel->baserestrictinfo = (List *)
271 adjust_inherited_attrs((Node *) rel->baserestrictinfo,
278 * Now compute child access paths, and save the cheapest.
280 set_plain_rel_pathlist(root, childrel, childrte);
282 subpaths = lappend(subpaths, childrel->cheapest_total_path);
285 * Propagate size information from the child back to the parent.
286 * For simplicity, we use the largest widths from any child as the
289 rel->rows += childrel->rows;
290 if (childrel->width > rel->width)
291 rel->width = childrel->width;
293 forboth(parentvars, rel->reltargetlist,
294 childvars, childrel->reltargetlist)
296 Var *parentvar = (Var *) lfirst(parentvars);
297 Var *childvar = (Var *) lfirst(childvars);
299 if (IsA(parentvar, Var) &&IsA(childvar, Var))
301 int pndx = parentvar->varattno - rel->min_attr;
302 int cndx = childvar->varattno - childrel->min_attr;
304 if (childrel->attr_widths[cndx] > rel->attr_widths[pndx])
305 rel->attr_widths[pndx] = childrel->attr_widths[cndx];
311 * Finally, build Append path and install it as the only access path
312 * for the parent rel.
314 add_path(rel, (Path *) create_append_path(rel, subpaths));
316 /* Select cheapest path (pretty easy in this case...) */
321 * set_subquery_pathlist
322 * Build the (single) access path for a subquery RTE
325 set_subquery_pathlist(Query *root, RelOptInfo *rel,
326 Index rti, RangeTblEntry *rte)
328 Query *subquery = rte->subquery;
329 bool *differentTypes;
332 /* We need a workspace for keeping track of set-op type coercions */
333 differentTypes = (bool *)
334 palloc0((list_length(subquery->targetList) + 1) * sizeof(bool));
337 * If there are any restriction clauses that have been attached to the
338 * subquery relation, consider pushing them down to become WHERE or
339 * HAVING quals of the subquery itself. This transformation is useful
340 * because it may allow us to generate a better plan for the subquery
341 * than evaluating all the subquery output rows and then filtering them.
343 * There are several cases where we cannot push down clauses.
344 * Restrictions involving the subquery are checked by
345 * subquery_is_pushdown_safe(). Restrictions on individual clauses
346 * are checked by qual_is_pushdown_safe().
348 * Non-pushed-down clauses will get evaluated as qpquals of the
351 * XXX Are there any cases where we want to make a policy decision not to
352 * push down a pushable qual, because it'd result in a worse plan?
354 if (rel->baserestrictinfo != NIL &&
355 subquery_is_pushdown_safe(subquery, subquery, differentTypes))
357 /* OK to consider pushing down individual quals */
358 List *upperrestrictlist = NIL;
361 foreach(l, rel->baserestrictinfo)
363 RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
364 Node *clause = (Node *) rinfo->clause;
366 if (qual_is_pushdown_safe(subquery, rti, clause, differentTypes))
369 subquery_push_qual(subquery, root->rtable, rti, clause);
373 /* Keep it in the upper query */
374 upperrestrictlist = lappend(upperrestrictlist, rinfo);
377 rel->baserestrictinfo = upperrestrictlist;
380 pfree(differentTypes);
382 /* Generate the plan for the subquery */
383 rel->subplan = subquery_planner(subquery, 0.0 /* default case */ );
385 /* Copy number of output rows from subplan */
386 rel->tuples = rel->subplan->plan_rows;
388 /* Mark rel with estimated output rows, width, etc */
389 set_baserel_size_estimates(root, rel);
391 /* Convert subquery pathkeys to outer representation */
392 pathkeys = build_subquery_pathkeys(root, rel, subquery);
394 /* Generate appropriate path */
395 add_path(rel, create_subqueryscan_path(rel, pathkeys));
397 /* Select cheapest path (pretty easy in this case...) */
402 * set_function_pathlist
403 * Build the (single) access path for a function RTE
406 set_function_pathlist(Query *root, RelOptInfo *rel, RangeTblEntry *rte)
408 /* Mark rel with estimated output rows, width, etc */
409 set_function_size_estimates(root, rel);
411 /* Generate appropriate path */
412 add_path(rel, create_functionscan_path(root, rel));
414 /* Select cheapest path (pretty easy in this case...) */
420 * Build access paths for a FromExpr jointree node.
423 make_fromexpr_rel(Query *root, FromExpr *from)
426 List *initial_rels = NIL;
430 * Count the number of child jointree nodes. This is the depth of the
431 * dynamic-programming algorithm we must employ to consider all ways
432 * of joining the child nodes.
434 levels_needed = list_length(from->fromlist);
436 if (levels_needed <= 0)
437 return NULL; /* nothing to do? */
440 * Construct a list of rels corresponding to the child jointree nodes.
441 * This may contain both base rels and rels constructed according to
442 * explicit JOIN directives.
444 foreach(jt, from->fromlist)
446 Node *jtnode = (Node *) lfirst(jt);
448 initial_rels = lappend(initial_rels,
449 make_jointree_rel(root, jtnode));
452 if (levels_needed == 1)
455 * Single jointree node, so we're done.
457 return (RelOptInfo *) linitial(initial_rels);
462 * Consider the different orders in which we could join the rels,
463 * using either GEQO or regular optimizer.
465 if (enable_geqo && levels_needed >= geqo_threshold)
466 return geqo(root, levels_needed, initial_rels);
468 return make_one_rel_by_joins(root, levels_needed, initial_rels);
473 * make_one_rel_by_joins
474 * Find all possible joinpaths for a query by successively finding ways
475 * to join component relations into join relations.
477 * 'levels_needed' is the number of iterations needed, ie, the number of
478 * independent jointree items in the query. This is > 1.
480 * 'initial_rels' is a list of RelOptInfo nodes for each independent
481 * jointree item. These are the components to be joined together.
483 * Returns the final level of join relations, i.e., the relation that is
484 * the result of joining all the original relations together.
487 make_one_rel_by_joins(Query *root, int levels_needed, List *initial_rels)
494 * We employ a simple "dynamic programming" algorithm: we first find
495 * all ways to build joins of two jointree items, then all ways to
496 * build joins of three items (from two-item joins and single items),
497 * then four-item joins, and so on until we have considered all ways
498 * to join all the items into one rel.
500 * joinitems[j] is a list of all the j-item rels. Initially we set
501 * joinitems[1] to represent all the single-jointree-item relations.
503 joinitems = (List **) palloc0((levels_needed + 1) * sizeof(List *));
505 joinitems[1] = initial_rels;
507 for (lev = 2; lev <= levels_needed; lev++)
512 * Determine all possible pairs of relations to be joined at this
513 * level, and build paths for making each one from every available
514 * pair of lower-level relations.
516 joinitems[lev] = make_rels_by_joins(root, lev, joinitems);
519 * Do cleanup work on each just-processed rel.
521 foreach(x, joinitems[lev])
523 rel = (RelOptInfo *) lfirst(x);
525 /* Find and save the cheapest paths for this rel */
528 #ifdef OPTIMIZER_DEBUG
529 debug_print_rel(root, rel);
535 * We should have a single rel at the final level.
537 if (joinitems[levels_needed] == NIL)
538 elog(ERROR, "failed to build any %d-way joins", levels_needed);
539 Assert(list_length(joinitems[levels_needed]) == 1);
541 rel = (RelOptInfo *) linitial(joinitems[levels_needed]);
546 /*****************************************************************************
547 * PUSHING QUALS DOWN INTO SUBQUERIES
548 *****************************************************************************/
551 * subquery_is_pushdown_safe - is a subquery safe for pushing down quals?
553 * subquery is the particular component query being checked. topquery
554 * is the top component of a set-operations tree (the same Query if no
555 * set-op is involved).
557 * Conditions checked here:
559 * 1. If the subquery has a LIMIT clause, we must not push down any quals,
560 * since that could change the set of rows returned.
562 * 2. If the subquery contains EXCEPT or EXCEPT ALL set ops we cannot push
563 * quals into it, because that would change the results.
565 * 3. For subqueries using UNION/UNION ALL/INTERSECT/INTERSECT ALL, we can
566 * push quals into each component query, but the quals can only reference
567 * subquery columns that suffer no type coercions in the set operation.
568 * Otherwise there are possible semantic gotchas. So, we check the
569 * component queries to see if any of them have different output types;
570 * differentTypes[k] is set true if column k has different type in any
574 subquery_is_pushdown_safe(Query *subquery, Query *topquery,
575 bool *differentTypes)
577 SetOperationStmt *topop;
580 if (subquery->limitOffset != NULL || subquery->limitCount != NULL)
583 /* Are we at top level, or looking at a setop component? */
584 if (subquery == topquery)
586 /* Top level, so check any component queries */
587 if (subquery->setOperations != NULL)
588 if (!recurse_pushdown_safe(subquery->setOperations, topquery,
594 /* Setop component must not have more components (too weird) */
595 if (subquery->setOperations != NULL)
597 /* Check whether setop component output types match top level */
598 topop = (SetOperationStmt *) topquery->setOperations;
599 Assert(topop && IsA(topop, SetOperationStmt));
600 compare_tlist_datatypes(subquery->targetList,
608 * Helper routine to recurse through setOperations tree
611 recurse_pushdown_safe(Node *setOp, Query *topquery,
612 bool *differentTypes)
614 if (IsA(setOp, RangeTblRef))
616 RangeTblRef *rtr = (RangeTblRef *) setOp;
617 RangeTblEntry *rte = rt_fetch(rtr->rtindex, topquery->rtable);
618 Query *subquery = rte->subquery;
620 Assert(subquery != NULL);
621 return subquery_is_pushdown_safe(subquery, topquery, differentTypes);
623 else if (IsA(setOp, SetOperationStmt))
625 SetOperationStmt *op = (SetOperationStmt *) setOp;
627 /* EXCEPT is no good */
628 if (op->op == SETOP_EXCEPT)
631 if (!recurse_pushdown_safe(op->larg, topquery, differentTypes))
633 if (!recurse_pushdown_safe(op->rarg, topquery, differentTypes))
638 elog(ERROR, "unrecognized node type: %d",
639 (int) nodeTag(setOp));
645 * Compare tlist's datatypes against the list of set-operation result types.
646 * For any items that are different, mark the appropriate element of
647 * differentTypes[] to show that this column will have type conversions.
650 compare_tlist_datatypes(List *tlist, List *colTypes,
651 bool *differentTypes)
654 ListCell *colType = list_head(colTypes);
658 TargetEntry *tle = (TargetEntry *) lfirst(l);
661 continue; /* ignore resjunk columns */
663 elog(ERROR, "wrong number of tlist entries");
664 if (exprType((Node *) tle->expr) != lfirst_oid(colType))
665 differentTypes[tle->resno] = true;
666 colType = lnext(colType);
669 elog(ERROR, "wrong number of tlist entries");
673 * qual_is_pushdown_safe - is a particular qual safe to push down?
675 * qual is a restriction clause applying to the given subquery (whose RTE
676 * has index rti in the parent query).
678 * Conditions checked here:
680 * 1. The qual must not contain any subselects (mainly because I'm not sure
681 * it will work correctly: sublinks will already have been transformed into
682 * subplans in the qual, but not in the subquery).
684 * 2. The qual must not refer to any subquery output columns that were
685 * found to have inconsistent types across a set operation tree by
686 * subquery_is_pushdown_safe().
688 * 3. If the subquery uses DISTINCT ON, we must not push down any quals that
689 * refer to non-DISTINCT output columns, because that could change the set
690 * of rows returned. This condition is vacuous for DISTINCT, because then
691 * there are no non-DISTINCT output columns, but unfortunately it's fairly
692 * expensive to tell the difference between DISTINCT and DISTINCT ON in the
693 * parsetree representation. It's cheaper to just make sure all the Vars
694 * in the qual refer to DISTINCT columns.
696 * 4. We must not push down any quals that refer to subselect outputs that
697 * return sets, else we'd introduce functions-returning-sets into the
698 * subquery's WHERE/HAVING quals.
701 qual_is_pushdown_safe(Query *subquery, Index rti, Node *qual,
702 bool *differentTypes)
707 Bitmapset *tested = NULL;
709 /* Refuse subselects (point 1) */
710 if (contain_subplans(qual))
714 * Examine all Vars used in clause; since it's a restriction clause,
715 * all such Vars must refer to subselect output columns.
717 vars = pull_var_clause(qual, false);
720 Var *var = (Var *) lfirst(vl);
723 Assert(var->varno == rti);
726 * We use a bitmapset to avoid testing the same attno more than
727 * once. (NB: this only works because subquery outputs can't have
730 if (bms_is_member(var->varattno, tested))
732 tested = bms_add_member(tested, var->varattno);
735 if (differentTypes[var->varattno])
741 /* Must find the tlist element referenced by the Var */
742 tle = get_tle_by_resno(subquery->targetList, var->varattno);
744 Assert(!tle->resjunk);
746 /* If subquery uses DISTINCT or DISTINCT ON, check point 3 */
747 if (subquery->distinctClause != NIL &&
748 !targetIsInSortList(tle, subquery->distinctClause))
750 /* non-DISTINCT column, so fail */
755 /* Refuse functions returning sets (point 4) */
756 if (expression_returns_set((Node *) tle->expr))
770 * subquery_push_qual - push down a qual that we have determined is safe
773 subquery_push_qual(Query *subquery, List *rtable, Index rti, Node *qual)
775 if (subquery->setOperations != NULL)
777 /* Recurse to push it separately to each component query */
778 recurse_push_qual(subquery->setOperations, subquery,
784 * We need to replace Vars in the qual (which must refer to
785 * outputs of the subquery) with copies of the subquery's
786 * targetlist expressions. Note that at this point, any uplevel
787 * Vars in the qual should have been replaced with Params, so they
790 * This step also ensures that when we are pushing into a setop tree,
791 * each component query gets its own copy of the qual.
793 qual = ResolveNew(qual, rti, 0, rtable,
794 subquery->targetList,
798 * Now attach the qual to the proper place: normally WHERE, but
799 * if the subquery uses grouping or aggregation, put it in HAVING
800 * (since the qual really refers to the group-result rows).
802 if (subquery->hasAggs || subquery->groupClause || subquery->havingQual)
803 subquery->havingQual = make_and_qual(subquery->havingQual, qual);
805 subquery->jointree->quals =
806 make_and_qual(subquery->jointree->quals, qual);
809 * We need not change the subquery's hasAggs or hasSublinks flags,
810 * since we can't be pushing down any aggregates that weren't
811 * there before, and we don't push down subselects at all.
817 * Helper routine to recurse through setOperations tree
820 recurse_push_qual(Node *setOp, Query *topquery,
821 List *rtable, Index rti, Node *qual)
823 if (IsA(setOp, RangeTblRef))
825 RangeTblRef *rtr = (RangeTblRef *) setOp;
826 RangeTblEntry *subrte = rt_fetch(rtr->rtindex, topquery->rtable);
827 Query *subquery = subrte->subquery;
829 Assert(subquery != NULL);
830 subquery_push_qual(subquery, rtable, rti, qual);
832 else if (IsA(setOp, SetOperationStmt))
834 SetOperationStmt *op = (SetOperationStmt *) setOp;
836 recurse_push_qual(op->larg, topquery, rtable, rti, qual);
837 recurse_push_qual(op->rarg, topquery, rtable, rti, qual);
841 elog(ERROR, "unrecognized node type: %d",
842 (int) nodeTag(setOp));
846 /*****************************************************************************
848 *****************************************************************************/
850 #ifdef OPTIMIZER_DEBUG
853 print_relids(Relids relids)
859 tmprelids = bms_copy(relids);
860 while ((x = bms_first_member(tmprelids)) >= 0)
871 print_restrictclauses(Query *root, List *clauses)
877 RestrictInfo *c = lfirst(l);
879 print_expr((Node *) c->clause, root->rtable);
886 print_path(Query *root, Path *path, int indent)
890 Path *subpath = NULL;
893 switch (nodeTag(path))
901 case T_BitmapHeapPath:
902 ptype = "BitmapHeapScan";
904 case T_BitmapAndPath:
905 ptype = "BitmapAndPath";
908 ptype = "BitmapOrPath";
918 subpath = ((ResultPath *) path)->subpath;
922 subpath = ((MaterialPath *) path)->subpath;
926 subpath = ((UniquePath *) path)->subpath;
945 for (i = 0; i < indent; i++)
952 print_relids(path->parent->relids);
953 printf(") rows=%.0f", path->parent->rows);
955 printf(" cost=%.2f..%.2f\n", path->startup_cost, path->total_cost);
959 for (i = 0; i < indent; i++)
961 printf(" pathkeys: ");
962 print_pathkeys(path->pathkeys, root->rtable);
967 JoinPath *jp = (JoinPath *) path;
969 for (i = 0; i < indent; i++)
971 printf(" clauses: ");
972 print_restrictclauses(root, jp->joinrestrictinfo);
975 if (IsA(path, MergePath))
977 MergePath *mp = (MergePath *) path;
979 if (mp->outersortkeys || mp->innersortkeys)
981 for (i = 0; i < indent; i++)
983 printf(" sortouter=%d sortinner=%d\n",
984 ((mp->outersortkeys) ? 1 : 0),
985 ((mp->innersortkeys) ? 1 : 0));
989 print_path(root, jp->outerjoinpath, indent + 1);
990 print_path(root, jp->innerjoinpath, indent + 1);
994 print_path(root, subpath, indent + 1);
998 debug_print_rel(Query *root, RelOptInfo *rel)
1002 printf("RELOPTINFO (");
1003 print_relids(rel->relids);
1004 printf("): rows=%.0f width=%d\n", rel->rows, rel->width);
1006 if (rel->baserestrictinfo)
1008 printf("\tbaserestrictinfo: ");
1009 print_restrictclauses(root, rel->baserestrictinfo);
1013 foreach(l, rel->joininfo)
1015 JoinInfo *j = (JoinInfo *) lfirst(l);
1017 printf("\tjoininfo (");
1018 print_relids(j->unjoined_relids);
1020 print_restrictclauses(root, j->jinfo_restrictinfo);
1024 printf("\tpath list:\n");
1025 foreach(l, rel->pathlist)
1026 print_path(root, lfirst(l), 1);
1027 printf("\n\tcheapest startup path:\n");
1028 print_path(root, rel->cheapest_startup_path, 1);
1029 printf("\n\tcheapest total path:\n");
1030 print_path(root, rel->cheapest_total_path, 1);
1035 #endif /* OPTIMIZER_DEBUG */