aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/path/prune.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/optimizer/path/prune.c')
-rw-r--r--src/backend/optimizer/path/prune.c58
1 files changed, 31 insertions, 27 deletions
diff --git a/src/backend/optimizer/path/prune.c b/src/backend/optimizer/path/prune.c
index 5b032491600..33fb67bc573 100644
--- a/src/backend/optimizer/path/prune.c
+++ b/src/backend/optimizer/path/prune.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/prune.c,v 1.42 1999/07/16 04:59:16 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/prune.c,v 1.43 1999/08/16 02:17:52 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -18,17 +18,15 @@
#include "optimizer/pathnode.h"
#include "optimizer/paths.h"
-
-
-static List *merge_rel_with_same_relids(RelOptInfo *rel, Relids unjoined_relids);
+static List *merge_rel_with_same_relids(RelOptInfo *rel, List *unmerged_rels);
/*
* merge_rels_with_same_relids
* Removes any redundant relation entries from a list of rel nodes
- * 'rel_list'. Obviously, the first relation can't be a duplicate.
+ * 'rel_list', merging their pathlists into the first non-duplicate
+ * relation entry for each value of relids.
*
* Returns the resulting list.
- *
*/
void
merge_rels_with_same_relids(List *rel_list)
@@ -37,17 +35,21 @@ merge_rels_with_same_relids(List *rel_list)
/*
* rel_list can shorten while running as duplicate relations are
- * deleted
+ * deleted. Obviously, the first relation can't be a duplicate,
+ * so the list head pointer won't change.
*/
foreach(i, rel_list)
- lnext(i) = merge_rel_with_same_relids((RelOptInfo *) lfirst(i), lnext(i));
+ {
+ lnext(i) = merge_rel_with_same_relids((RelOptInfo *) lfirst(i),
+ lnext(i));
+ }
}
/*
* merge_rel_with_same_relids
- * Prunes those relations from 'unjoined_relids' that are redundant with
+ * Prunes those relations from 'unmerged_rels' that are redundant with
* 'rel'. A relation is redundant if it is built up of the same
- * relations as 'rel'. Paths for the redundant relation are merged into
+ * relations as 'rel'. Paths for the redundant relations are merged into
* the pathlist of 'rel'.
*
* Returns a list of non-redundant relations, and sets the pathlist field
@@ -55,50 +57,52 @@ merge_rels_with_same_relids(List *rel_list)
*
*/
static List *
-merge_rel_with_same_relids(RelOptInfo *rel, Relids unjoined_relids)
+merge_rel_with_same_relids(RelOptInfo *rel, List *unmerged_rels)
{
- List *i = NIL;
List *result = NIL;
+ List *i;
- foreach(i, unjoined_relids)
+ foreach(i, unmerged_rels)
{
- RelOptInfo *unjoined_rel = (RelOptInfo *) lfirst(i);
-
- if (same(rel->relids, unjoined_rel->relids))
+ RelOptInfo *unmerged_rel = (RelOptInfo *) lfirst(i);
+ if (same(rel->relids, unmerged_rel->relids))
+ {
/*
- * This are on the same relations, so get the best of their
- * pathlists.
+ * These rels are for the same set of base relations,
+ * so get the best of their pathlists. We assume it's
+ * ok to reassign a path to the other RelOptInfo without
+ * doing more than changing its parent pointer (cf. pathnode.c).
*/
rel->pathlist = add_pathlist(rel,
rel->pathlist,
- unjoined_rel->pathlist);
+ unmerged_rel->pathlist);
+ }
else
- result = lappend(result, unjoined_rel);
+ result = lappend(result, unmerged_rel);
}
return result;
}
/*
* rels_set_cheapest
- * For each relation entry in 'rel_list' (which corresponds to a join
- * relation), set pointers to the cheapest path
+ * For each relation entry in 'rel_list' (which should contain only join
+ * relations), set pointers to the cheapest path and compute rel size.
*/
void
rels_set_cheapest(List *rel_list)
{
- List *x = NIL;
- RelOptInfo *rel = (RelOptInfo *) NULL;
- JoinPath *cheapest;
+ List *x;
foreach(x, rel_list)
{
- rel = (RelOptInfo *) lfirst(x);
+ RelOptInfo *rel = (RelOptInfo *) lfirst(x);
+ JoinPath *cheapest;
cheapest = (JoinPath *) set_cheapest(rel, rel->pathlist);
if (IsA_JoinPath(cheapest))
rel->size = compute_joinrel_size(cheapest);
else
- elog(ERROR, "non JoinPath called");
+ elog(ERROR, "rels_set_cheapest: non JoinPath found");
}
}