aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/plan/initsplan.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/optimizer/plan/initsplan.c')
-rw-r--r--src/backend/optimizer/plan/initsplan.c231
1 files changed, 113 insertions, 118 deletions
diff --git a/src/backend/optimizer/plan/initsplan.c b/src/backend/optimizer/plan/initsplan.c
index 7e3d5bca55b..dd8fc4fa2d7 100644
--- a/src/backend/optimizer/plan/initsplan.c
+++ b/src/backend/optimizer/plan/initsplan.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.109 2005/09/28 21:17:02 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.110 2005/10/15 02:49:20 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -221,7 +221,7 @@ distribute_quals_to_rels(PlannerInfo *root, Node *jtnode,
result = bms_add_members(result,
distribute_quals_to_rels(root,
lfirst(l),
- below_outer_join));
+ below_outer_join));
}
/*
@@ -243,17 +243,17 @@ distribute_quals_to_rels(PlannerInfo *root, Node *jtnode,
ListCell *qual;
/*
- * Order of operations here is subtle and critical. First we
- * recurse to handle sub-JOINs. Their join quals will be placed
- * without regard for whether this level is an outer join, which
- * is correct. Then we place our own join quals, which are
- * restricted by lower outer joins in any case, and are forced to
- * this level if this is an outer join and they mention the outer
- * side. Finally, if this is an outer join, we mark baserels
- * contained within the inner side(s) with our own rel set; this
- * will prevent quals above us in the join tree that use those
- * rels from being pushed down below this level. (It's okay for
- * upper quals to be pushed down to the outer side, however.)
+ * Order of operations here is subtle and critical. First we recurse
+ * to handle sub-JOINs. Their join quals will be placed without
+ * regard for whether this level is an outer join, which is correct.
+ * Then we place our own join quals, which are restricted by lower
+ * outer joins in any case, and are forced to this level if this is an
+ * outer join and they mention the outer side. Finally, if this is an
+ * outer join, we mark baserels contained within the inner side(s)
+ * with our own rel set; this will prevent quals above us in the join
+ * tree that use those rels from being pushed down below this level.
+ * (It's okay for upper quals to be pushed down to the outer side,
+ * however.)
*/
switch (j->jointype)
{
@@ -302,19 +302,19 @@ distribute_quals_to_rels(PlannerInfo *root, Node *jtnode,
case JOIN_UNION:
/*
- * This is where we fail if upper levels of planner
- * haven't rewritten UNION JOIN as an Append ...
+ * This is where we fail if upper levels of planner haven't
+ * rewritten UNION JOIN as an Append ...
*/
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("UNION JOIN is not implemented")));
- nonnullable_rels = NULL; /* keep compiler quiet */
+ nonnullable_rels = NULL; /* keep compiler quiet */
nullable_rels = NULL;
break;
default:
elog(ERROR, "unrecognized join type: %d",
(int) j->jointype);
- nonnullable_rels = NULL; /* keep compiler quiet */
+ nonnullable_rels = NULL; /* keep compiler quiet */
nullable_rels = NULL;
break;
}
@@ -349,19 +349,19 @@ mark_baserels_for_outer_join(PlannerInfo *root, Relids rels, Relids outerrels)
RelOptInfo *rel = find_base_rel(root, relno);
/*
- * Since we do this bottom-up, any outer-rels previously marked
- * should be within the new outer join set.
+ * Since we do this bottom-up, any outer-rels previously marked should
+ * be within the new outer join set.
*/
Assert(bms_is_subset(rel->outerjoinset, outerrels));
/*
* Presently the executor cannot support FOR UPDATE/SHARE marking of
* rels appearing on the nullable side of an outer join. (It's
- * somewhat unclear what that would mean, anyway: what should we
- * mark when a result row is generated from no element of the
- * nullable relation?) So, complain if target rel is FOR UPDATE/SHARE.
- * It's sufficient to make this check once per rel, so do it only
- * if rel wasn't already known nullable.
+ * somewhat unclear what that would mean, anyway: what should we mark
+ * when a result row is generated from no element of the nullable
+ * relation?) So, complain if target rel is FOR UPDATE/SHARE. It's
+ * sufficient to make this check once per rel, so do it only if rel
+ * wasn't already known nullable.
*/
if (rel->outerjoinset == NULL)
{
@@ -430,9 +430,9 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
/*
* If the clause is variable-free, we force it to be evaluated at its
* original syntactic level. Note that this should not happen for
- * top-level clauses, because query_planner() special-cases them. But
- * it will happen for variable-free JOIN/ON clauses. We don't have to
- * be real smart about such a case, we just have to be correct.
+ * top-level clauses, because query_planner() special-cases them. But it
+ * will happen for variable-free JOIN/ON clauses. We don't have to be
+ * real smart about such a case, we just have to be correct.
*/
if (bms_is_empty(relids))
relids = qualscope;
@@ -446,8 +446,8 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
/*
* If the qual came from implied-equality deduction, we always
* evaluate the qual at its natural semantic level. It is the
- * responsibility of the deducer not to create any quals that
- * should be delayed by outer-join rules.
+ * responsibility of the deducer not to create any quals that should
+ * be delayed by outer-join rules.
*/
Assert(bms_equal(relids, qualscope));
/* Needn't feed it back for more deductions */
@@ -457,28 +457,28 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
else if (bms_overlap(relids, outerjoin_nonnullable))
{
/*
- * The qual is attached to an outer join and mentions (some of
- * the) rels on the nonnullable side. Force the qual to be
- * evaluated exactly at the level of joining corresponding to the
- * outer join. We cannot let it get pushed down into the
- * nonnullable side, since then we'd produce no output rows,
- * rather than the intended single null-extended row, for any
- * nonnullable-side rows failing the qual.
+ * The qual is attached to an outer join and mentions (some of the)
+ * rels on the nonnullable side. Force the qual to be evaluated
+ * exactly at the level of joining corresponding to the outer join. We
+ * cannot let it get pushed down into the nonnullable side, since then
+ * we'd produce no output rows, rather than the intended single
+ * null-extended row, for any nonnullable-side rows failing the qual.
*
- * Note: an outer-join qual that mentions only nullable-side rels can
- * be pushed down into the nullable side without changing the join
+ * Note: an outer-join qual that mentions only nullable-side rels can be
+ * pushed down into the nullable side without changing the join
* result, so we treat it the same as an ordinary inner-join qual,
* except for not setting maybe_equijoin (see below).
*/
relids = qualscope;
+
/*
- * We can't use such a clause to deduce equijoin (the left and
- * right sides might be unequal above the join because one of
- * them has gone to NULL) ... but we might be able to use it
- * for more limited purposes. Note: for the current uses of
- * deductions from an outer-join clause, it seems safe to make
- * the deductions even when the clause is below a higher-level
- * outer join; so we do not check below_outer_join here.
+ * We can't use such a clause to deduce equijoin (the left and right
+ * sides might be unequal above the join because one of them has gone
+ * to NULL) ... but we might be able to use it for more limited
+ * purposes. Note: for the current uses of deductions from an
+ * outer-join clause, it seems safe to make the deductions even when
+ * the clause is below a higher-level outer join; so we do not check
+ * below_outer_join here.
*/
maybe_equijoin = false;
maybe_outer_join = true;
@@ -486,15 +486,14 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
else
{
/*
- * For a non-outer-join qual, we can evaluate the qual as soon as
- * (1) we have all the rels it mentions, and (2) we are at or
- * above any outer joins that can null any of these rels and are
- * below the syntactic location of the given qual. To enforce the
- * latter, scan the base rels listed in relids, and merge their
- * outer-join sets into the clause's own reference list. At the
- * time we are called, the outerjoinset of each baserel will show
- * exactly those outer joins that are below the qual in the join
- * tree.
+ * For a non-outer-join qual, we can evaluate the qual as soon as (1)
+ * we have all the rels it mentions, and (2) we are at or above any
+ * outer joins that can null any of these rels and are below the
+ * syntactic location of the given qual. To enforce the latter, scan
+ * the base rels listed in relids, and merge their outer-join sets
+ * into the clause's own reference list. At the time we are called,
+ * the outerjoinset of each baserel will show exactly those outer
+ * joins that are below the qual in the join tree.
*/
Relids addrelids = NULL;
Relids tmprelids;
@@ -513,13 +512,13 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
if (bms_is_subset(addrelids, relids))
{
/*
- * Qual is not delayed by any lower outer-join restriction.
- * If it is not itself below or within an outer join, we
- * can consider it "valid everywhere", so consider feeding
- * it to the equijoin machinery. (If it is within an outer
- * join, we can't consider it "valid everywhere": once the
- * contained variables have gone to NULL, we'd be asserting
- * things like NULL = NULL, which is not true.)
+ * Qual is not delayed by any lower outer-join restriction. If it
+ * is not itself below or within an outer join, we can consider it
+ * "valid everywhere", so consider feeding it to the equijoin
+ * machinery. (If it is within an outer join, we can't consider
+ * it "valid everywhere": once the contained variables have gone
+ * to NULL, we'd be asserting things like NULL = NULL, which is
+ * not true.)
*/
if (!below_outer_join && outerjoin_nonnullable == NULL)
maybe_equijoin = true;
@@ -533,8 +532,8 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
Assert(bms_is_subset(relids, qualscope));
/*
- * Because application of the qual will be delayed by outer
- * join, we mustn't assume its vars are equal everywhere.
+ * Because application of the qual will be delayed by outer join,
+ * we mustn't assume its vars are equal everywhere.
*/
maybe_equijoin = false;
}
@@ -543,11 +542,10 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
}
/*
- * Mark the qual as "pushed down" if it can be applied at a level
- * below its original syntactic level. This allows us to distinguish
- * original JOIN/ON quals from higher-level quals pushed down to the
- * same joinrel. A qual originating from WHERE is always considered
- * "pushed down".
+ * Mark the qual as "pushed down" if it can be applied at a level below
+ * its original syntactic level. This allows us to distinguish original
+ * JOIN/ON quals from higher-level quals pushed down to the same joinrel.
+ * A qual originating from WHERE is always considered "pushed down".
*/
if (!is_pushed_down)
is_pushed_down = !bms_equal(relids, qualscope);
@@ -573,25 +571,24 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
rel = find_base_rel(root, bms_singleton_member(relids));
/*
- * Check for a "mergejoinable" clause even though it's not a
- * join clause. This is so that we can recognize that "a.x =
- * a.y" makes x and y eligible to be considered equal, even
- * when they belong to the same rel. Without this, we would
- * not recognize that "a.x = a.y AND a.x = b.z AND a.y = c.q"
- * allows us to consider z and q equal after their rels are
- * joined.
+ * Check for a "mergejoinable" clause even though it's not a join
+ * clause. This is so that we can recognize that "a.x = a.y"
+ * makes x and y eligible to be considered equal, even when they
+ * belong to the same rel. Without this, we would not recognize
+ * that "a.x = a.y AND a.x = b.z AND a.y = c.q" allows us to
+ * consider z and q equal after their rels are joined.
*/
check_mergejoinable(restrictinfo);
/*
- * If the clause was deduced from implied equality, check to
- * see whether it is redundant with restriction clauses we
- * already have for this rel. Note we cannot apply this check
- * to user-written clauses, since we haven't found the
- * canonical pathkey sets yet while processing user clauses.
- * (NB: no comparable check is done in the join-clause case;
- * redundancy will be detected when the join clause is moved
- * into a join rel's restriction list.)
+ * If the clause was deduced from implied equality, check to see
+ * whether it is redundant with restriction clauses we already
+ * have for this rel. Note we cannot apply this check to
+ * user-written clauses, since we haven't found the canonical
+ * pathkey sets yet while processing user clauses. (NB: no
+ * comparable check is done in the join-clause case; redundancy
+ * will be detected when the join clause is moved into a join
+ * rel's restriction list.)
*/
if (!is_deduced ||
!qual_is_redundant(root, restrictinfo,
@@ -605,17 +602,17 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
case BMS_MULTIPLE:
/*
- * 'clause' is a join clause, since there is more than one rel
- * in the relid set.
+ * 'clause' is a join clause, since there is more than one rel in
+ * the relid set.
*/
/*
* Check for hash or mergejoinable operators.
*
- * We don't bother setting the hashjoin info if we're not going
- * to need it. We do want to know about mergejoinable ops in
- * all cases, however, because we use mergejoinable ops for
- * other purposes such as detecting redundant clauses.
+ * We don't bother setting the hashjoin info if we're not going to
+ * need it. We do want to know about mergejoinable ops in all
+ * cases, however, because we use mergejoinable ops for other
+ * purposes such as detecting redundant clauses.
*/
check_mergejoinable(restrictinfo);
if (enable_hashjoin)
@@ -628,9 +625,9 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
/*
* Add vars used in the join clause to targetlists of their
- * relations, so that they will be emitted by the plan nodes
- * that scan those relations (else they won't be available at
- * the join node!).
+ * relations, so that they will be emitted by the plan nodes that
+ * scan those relations (else they won't be available at the join
+ * node!).
*/
vars = pull_var_clause(clause, false);
add_vars_to_targetlist(root, vars, relids);
@@ -639,17 +636,16 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
default:
/*
- * 'clause' references no rels, and therefore we have no place
- * to attach it. Shouldn't get here if callers are working
- * properly.
+ * 'clause' references no rels, and therefore we have no place to
+ * attach it. Shouldn't get here if callers are working properly.
*/
elog(ERROR, "cannot cope with variable-free clause");
break;
}
/*
- * If the clause has a mergejoinable operator, we may be able to
- * deduce more things from it under the principle of transitivity.
+ * If the clause has a mergejoinable operator, we may be able to deduce
+ * more things from it under the principle of transitivity.
*
* If it is not an outer-join qualification nor bubbled up due to an outer
* join, then the two sides represent equivalent PathKeyItems for path
@@ -744,8 +740,8 @@ process_implied_equality(PlannerInfo *root,
/*
* If the exprs involve a single rel, we need to look at that rel's
- * baserestrictinfo list. If multiple rels, we can scan the joininfo
- * list of any of 'em.
+ * baserestrictinfo list. If multiple rels, we can scan the joininfo list
+ * of any of 'em.
*/
if (membership == BMS_SINGLETON)
{
@@ -767,8 +763,8 @@ process_implied_equality(PlannerInfo *root,
}
/*
- * Scan to see if equality is already known. If so, we're done in the
- * add case, and done after removing it in the delete case.
+ * Scan to see if equality is already known. If so, we're done in the add
+ * case, and done after removing it in the delete case.
*/
foreach(itm, restrictlist)
{
@@ -791,7 +787,7 @@ process_implied_equality(PlannerInfo *root,
{
/* delete it from local restrictinfo list */
rel1->baserestrictinfo = list_delete_ptr(rel1->baserestrictinfo,
- restrictinfo);
+ restrictinfo);
}
else
{
@@ -808,8 +804,8 @@ process_implied_equality(PlannerInfo *root,
return;
/*
- * This equality is new information, so construct a clause
- * representing it to add to the query data structures.
+ * This equality is new information, so construct a clause representing it
+ * to add to the query data structures.
*/
ltype = exprType(item1);
rtype = exprType(item2);
@@ -818,14 +814,14 @@ process_implied_equality(PlannerInfo *root,
if (!HeapTupleIsValid(eq_operator))
{
/*
- * Would it be safe to just not add the equality to the query if
- * we have no suitable equality operator for the combination of
+ * Would it be safe to just not add the equality to the query if we
+ * have no suitable equality operator for the combination of
* datatypes? NO, because sortkey selection may screw up anyway.
*/
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
- errmsg("could not identify an equality operator for types %s and %s",
- format_type_be(ltype), format_type_be(rtype))));
+ errmsg("could not identify an equality operator for types %s and %s",
+ format_type_be(ltype), format_type_be(rtype))));
}
pgopform = (Form_pg_operator) GETSTRUCT(eq_operator);
@@ -856,8 +852,8 @@ process_implied_equality(PlannerInfo *root,
/*
* Push the new clause into all the appropriate restrictinfo lists.
*
- * Note: we mark the qual "pushed down" to ensure that it can never be
- * taken for an original JOIN/ON clause.
+ * Note: we mark the qual "pushed down" to ensure that it can never be taken
+ * for an original JOIN/ON clause.
*/
distribute_qual_to_rels(root, (Node *) clause,
true, true, false, NULL, relids);
@@ -911,9 +907,9 @@ qual_is_redundant(PlannerInfo *root,
return false;
/*
- * Scan existing quals to find those referencing same pathkeys.
- * Usually there will be few, if any, so build a list of just the
- * interesting ones.
+ * Scan existing quals to find those referencing same pathkeys. Usually
+ * there will be few, if any, so build a list of just the interesting
+ * ones.
*/
oldquals = NIL;
foreach(olditem, restrictlist)
@@ -933,11 +929,10 @@ qual_is_redundant(PlannerInfo *root,
/*
* Now, we want to develop a list of exprs that are known equal to the
- * left side of the new qual. We traverse the old-quals list
- * repeatedly to transitively expand the exprs list. If at any point
- * we find we can reach the right-side expr of the new qual, we are
- * done. We give up when we can't expand the equalexprs list any
- * more.
+ * left side of the new qual. We traverse the old-quals list repeatedly
+ * to transitively expand the exprs list. If at any point we find we can
+ * reach the right-side expr of the new qual, we are done. We give up
+ * when we can't expand the equalexprs list any more.
*/
equalexprs = list_make1(newleft);
do