* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.316 2005/10/15 02:49:18 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.317 2005/11/14 23:54:12 tgl Exp $
*
*-------------------------------------------------------------------------
*/
COPY_NODE_FIELD(clause);
COPY_SCALAR_FIELD(is_pushed_down);
+ COPY_SCALAR_FIELD(outerjoin_delayed);
COPY_SCALAR_FIELD(can_join);
COPY_BITMAPSET_FIELD(clause_relids);
COPY_BITMAPSET_FIELD(required_relids);
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.253 2005/10/15 02:49:18 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.254 2005/11/14 23:54:15 tgl Exp $
*
*-------------------------------------------------------------------------
*/
{
COMPARE_NODE_FIELD(clause);
COMPARE_SCALAR_FIELD(is_pushed_down);
+ COMPARE_SCALAR_FIELD(outerjoin_delayed);
COMPARE_BITMAPSET_FIELD(required_relids);
/*
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.261 2005/10/15 02:49:18 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.262 2005/11/14 23:54:15 tgl Exp $
*
* NOTES
* Every node type that can appear in stored rules' parsetrees *must*
/* NB: this isn't a complete set of fields */
WRITE_NODE_FIELD(clause);
WRITE_BOOL_FIELD(is_pushed_down);
+ WRITE_BOOL_FIELD(outerjoin_delayed);
WRITE_BOOL_FIELD(can_join);
WRITE_BITMAPSET_FIELD(clause_relids);
WRITE_BITMAPSET_FIELD(required_relids);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.191 2005/10/15 02:49:19 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.192 2005/11/14 23:54:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
resultquals = lappend(resultquals,
make_restrictinfo(boolqual,
true,
+ false,
NULL));
continue;
}
elog(ERROR, "no = operator for opclass %u", opclass);
expr = make_opclause(oproid, BOOLOID, false,
(Expr *) leftop, (Expr *) prefix_const);
- result = list_make1(make_restrictinfo(expr, true, NULL));
+ result = list_make1(make_restrictinfo(expr, true, false, NULL));
return result;
}
elog(ERROR, "no >= operator for opclass %u", opclass);
expr = make_opclause(oproid, BOOLOID, false,
(Expr *) leftop, (Expr *) prefix_const);
- result = list_make1(make_restrictinfo(expr, true, NULL));
+ result = list_make1(make_restrictinfo(expr, true, false, NULL));
/*-------
* If we can create a string larger than the prefix, we can say
elog(ERROR, "no < operator for opclass %u", opclass);
expr = make_opclause(oproid, BOOLOID, false,
(Expr *) leftop, (Expr *) greaterstr);
- result = lappend(result, make_restrictinfo(expr, true, NULL));
+ result = lappend(result, make_restrictinfo(expr, true, false, NULL));
}
return result;
(Expr *) leftop,
(Expr *) makeConst(datatype, -1, opr1right,
false, false));
- result = list_make1(make_restrictinfo(expr, true, NULL));
+ result = list_make1(make_restrictinfo(expr, true, false, NULL));
/* create clause "key <= network_scan_last( rightop )" */
(Expr *) leftop,
(Expr *) makeConst(datatype, -1, opr2right,
false, false));
- result = lappend(result, make_restrictinfo(expr, true, NULL));
+ result = lappend(result, make_restrictinfo(expr, true, false, NULL));
return result;
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/path/orindxpath.c,v 1.75 2005/10/15 02:49:20 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/path/orindxpath.c,v 1.76 2005/11/14 23:54:18 tgl Exp $
*
*-------------------------------------------------------------------------
*/
ListCell *i;
/*
- * Find potentially interesting OR joinclauses.
+ * Find potentially interesting OR joinclauses. Note we must ignore any
+ * joinclauses that are marked outerjoin_delayed, because they cannot
+ * be pushed down to the per-relation level due to outer-join rules.
+ * (XXX in some cases it might be possible to allow this, but it would
+ * require substantially more bookkeeping about where the clause came
+ * from.)
*/
foreach(i, rel->joininfo)
{
RestrictInfo *rinfo = (RestrictInfo *) lfirst(i);
- if (restriction_is_or_clause(rinfo))
+ if (restriction_is_or_clause(rinfo) &&
+ !rinfo->outerjoin_delayed)
{
/*
* Use the generate_bitmap_or_paths() machinery to estimate the
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.110 2005/10/15 02:49:20 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.111 2005/11/14 23:54:18 tgl Exp $
*
*-------------------------------------------------------------------------
*/
Relids qualscope)
{
Relids relids;
+ bool outerjoin_delayed;
bool maybe_equijoin;
bool maybe_outer_join;
RestrictInfo *restrictinfo;
*/
Assert(bms_equal(relids, qualscope));
/* Needn't feed it back for more deductions */
+ outerjoin_delayed = false;
maybe_equijoin = false;
maybe_outer_join = false;
}
* except for not setting maybe_equijoin (see below).
*/
relids = qualscope;
+ outerjoin_delayed = true;
/*
* We can't use such a clause to deduce equijoin (the left and right
Relids tmprelids;
int relno;
+ outerjoin_delayed = false;
tmprelids = bms_copy(relids);
while ((relno = bms_first_member(tmprelids)) >= 0)
{
RelOptInfo *rel = find_base_rel(root, relno);
if (rel->outerjoinset != NULL)
+ {
addrelids = bms_add_members(addrelids, rel->outerjoinset);
+ outerjoin_delayed = true;
+ }
}
bms_free(tmprelids);
*/
restrictinfo = make_restrictinfo((Expr *) clause,
is_pushed_down,
+ outerjoin_delayed,
relids);
/*
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/util/restrictinfo.c,v 1.41 2005/10/15 02:49:21 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/util/restrictinfo.c,v 1.42 2005/11/14 23:54:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
static RestrictInfo *make_restrictinfo_internal(Expr *clause,
Expr *orclause,
bool is_pushed_down,
+ bool outerjoin_delayed,
Relids required_relids);
static Expr *make_sub_restrictinfos(Expr *clause,
- bool is_pushed_down);
+ bool is_pushed_down,
+ bool outerjoin_delayed);
static RestrictInfo *join_clause_is_redundant(PlannerInfo *root,
RestrictInfo *rinfo,
List *reference_list,
*
* Build a RestrictInfo node containing the given subexpression.
*
- * The is_pushed_down flag must be supplied by the caller.
- * required_relids can be NULL, in which case it defaults to the
+ * The is_pushed_down and outerjoin_delayed flags must be supplied by the
+ * caller. required_relids can be NULL, in which case it defaults to the
* actual clause contents (i.e., clause_relids).
*
* We initialize fields that depend only on the given subexpression, leaving
* later.
*/
RestrictInfo *
-make_restrictinfo(Expr *clause, bool is_pushed_down, Relids required_relids)
+make_restrictinfo(Expr *clause,
+ bool is_pushed_down,
+ bool outerjoin_delayed,
+ Relids required_relids)
{
/*
* If it's an OR clause, build a modified copy with RestrictInfos inserted
* above each subclause of the top-level AND/OR structure.
*/
if (or_clause((Node *) clause))
- return (RestrictInfo *) make_sub_restrictinfos(clause, is_pushed_down);
+ return (RestrictInfo *) make_sub_restrictinfos(clause,
+ is_pushed_down,
+ outerjoin_delayed);
/* Shouldn't be an AND clause, else AND/OR flattening messed up */
Assert(!and_clause((Node *) clause));
- return make_restrictinfo_internal(clause, NULL, is_pushed_down,
+ return make_restrictinfo_internal(clause, NULL,
+ is_pushed_down, outerjoin_delayed,
required_relids);
}
* The result is a List (effectively, implicit-AND representation) of
* RestrictInfos.
*
+ * The caller must pass is_pushed_down, but we assume outerjoin_delayed
+ * is false (no such qual should ever get into a bitmapqual).
+ *
* If include_predicates is true, we add any partial index predicates to
* the explicit index quals. When this is not true, we return a condition
* that might be weaker than the actual scan represents.
list_make1(make_restrictinfo_internal(make_orclause(withoutris),
make_orclause(withris),
is_pushed_down,
+ false,
NULL));
}
}
result = lappend(result,
make_restrictinfo(pred,
is_pushed_down,
+ false,
NULL));
}
}
*/
static RestrictInfo *
make_restrictinfo_internal(Expr *clause, Expr *orclause,
- bool is_pushed_down, Relids required_relids)
+ bool is_pushed_down, bool outerjoin_delayed,
+ Relids required_relids)
{
RestrictInfo *restrictinfo = makeNode(RestrictInfo);
restrictinfo->clause = clause;
restrictinfo->orclause = orclause;
restrictinfo->is_pushed_down = is_pushed_down;
+ restrictinfo->outerjoin_delayed = outerjoin_delayed;
restrictinfo->can_join = false; /* may get set below */
/*
* simple clauses are valid RestrictInfos.
*/
static Expr *
-make_sub_restrictinfos(Expr *clause, bool is_pushed_down)
+make_sub_restrictinfos(Expr *clause,
+ bool is_pushed_down, bool outerjoin_delayed)
{
if (or_clause((Node *) clause))
{
foreach(temp, ((BoolExpr *) clause)->args)
orlist = lappend(orlist,
make_sub_restrictinfos(lfirst(temp),
- is_pushed_down));
+ is_pushed_down,
+ outerjoin_delayed));
return (Expr *) make_restrictinfo_internal(clause,
make_orclause(orlist),
is_pushed_down,
+ outerjoin_delayed,
NULL);
}
else if (and_clause((Node *) clause))
foreach(temp, ((BoolExpr *) clause)->args)
andlist = lappend(andlist,
make_sub_restrictinfos(lfirst(temp),
- is_pushed_down));
+ is_pushed_down,
+ outerjoin_delayed));
return make_andclause(andlist);
}
else
return (Expr *) make_restrictinfo_internal(clause,
NULL,
is_pushed_down,
+ outerjoin_delayed,
NULL);
}
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.119 2005/10/15 02:49:45 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.120 2005/11/14 23:54:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* joined, will also have is_pushed_down set because it will get attached to
* some lower joinrel.
*
+ * When application of a qual must be delayed by outer join, we also mark it
+ * with outerjoin_delayed = true. This isn't redundant with required_relids
+ * because that might equal clause_relids whether or not it's an outer-join
+ * clause.
+ *
* In general, the referenced clause might be arbitrarily complex. The
* kinds of clauses we can handle as indexscan quals, mergejoin clauses,
* or hashjoin clauses are fairly limited --- the code for each kind of
bool is_pushed_down; /* TRUE if clause was pushed down in level */
+ bool outerjoin_delayed; /* TRUE if delayed by outer join */
+
/*
* This flag is set true if the clause looks potentially useful as a merge
* or hash join clause, that is if it is a binary opclause with
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/optimizer/restrictinfo.h,v 1.34 2005/10/15 02:49:45 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/optimizer/restrictinfo.h,v 1.35 2005/11/14 23:54:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
extern RestrictInfo *make_restrictinfo(Expr *clause,
bool is_pushed_down,
+ bool outerjoin_delayed,
Relids required_relids);
extern List *make_restrictinfo_from_bitmapqual(Path *bitmapqual,
bool is_pushed_down,