1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-02 09:02:37 +03:00

Fix planner to restore its previous level of intelligence about pushing

constants through full joins, as in

	select * from tenk1 a full join tenk1 b using (unique1)
	where unique1 = 42;

which should generate a fairly cheap plan where we apply the constraint
unique1 = 42 in each relation scan.  This had been broken by my patch of
2008-06-27, which is now reverted in favor of a more invasive but hopefully
less incorrect approach.  That patch was meant to prevent incorrect extraction
of OR'd indexclauses from OR conditions above an outer join.  To do that
correctly we need more information than the outerjoin_delay flag can provide,
so add a nullable_relids field to RestrictInfo that records exactly which
relations are nulled by outer joins that are underneath a particular qual
clause.  A side benefit is that we can make the test in create_or_index_quals
more specific: it is now smart enough to extract an OR'd indexclause into the
outer side of an outer join, even though it must not do so in the inner side.
The old coding couldn't distinguish these cases so it could not do either.
This commit is contained in:
Tom Lane
2009-04-16 20:42:16 +00:00
parent c5593d5405
commit d7a6a04dc7
9 changed files with 132 additions and 68 deletions

View File

@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.238 2009/03/11 03:32:22 tgl Exp $
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.239 2009/04/16 20:42:16 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -2325,11 +2325,7 @@ expand_indexqual_conditions(IndexOptInfo *index, List *clausegroups)
if (boolqual)
{
resultquals = lappend(resultquals,
make_restrictinfo(boolqual,
true,
false,
false,
NULL));
make_simple_restrictinfo(boolqual));
continue;
}
}
@ -2360,11 +2356,7 @@ expand_indexqual_conditions(IndexOptInfo *index, List *clausegroups)
{
Assert(index->amsearchnulls);
resultquals = lappend(resultquals,
make_restrictinfo(clause,
true,
false,
false,
NULL));
make_simple_restrictinfo(clause));
}
else
elog(ERROR, "unsupported indexqual type: %d",
@ -2737,7 +2729,7 @@ expand_indexqual_rowcompare(RestrictInfo *rinfo,
matching_cols);
rc->rargs = list_truncate((List *) copyObject(clause->rargs),
matching_cols);
return make_restrictinfo((Expr *) rc, true, false, false, NULL);
return make_simple_restrictinfo((Expr *) rc);
}
else
{
@ -2746,7 +2738,7 @@ expand_indexqual_rowcompare(RestrictInfo *rinfo,
opexpr = make_opclause(linitial_oid(new_ops), BOOLOID, false,
copyObject(linitial(clause->largs)),
copyObject(linitial(clause->rargs)));
return make_restrictinfo(opexpr, true, false, false, NULL);
return make_simple_restrictinfo(opexpr);
}
}
@ -2832,7 +2824,7 @@ prefix_quals(Node *leftop, Oid opfamily,
elog(ERROR, "no = operator for opfamily %u", opfamily);
expr = make_opclause(oproid, BOOLOID, false,
(Expr *) leftop, (Expr *) prefix_const);
result = list_make1(make_restrictinfo(expr, true, false, false, NULL));
result = list_make1(make_simple_restrictinfo(expr));
return result;
}
@ -2847,7 +2839,7 @@ prefix_quals(Node *leftop, Oid opfamily,
elog(ERROR, "no >= operator for opfamily %u", opfamily);
expr = make_opclause(oproid, BOOLOID, false,
(Expr *) leftop, (Expr *) prefix_const);
result = list_make1(make_restrictinfo(expr, true, false, false, NULL));
result = list_make1(make_simple_restrictinfo(expr));
/*-------
* If we can create a string larger than the prefix, we can say
@ -2864,8 +2856,7 @@ prefix_quals(Node *leftop, Oid opfamily,
{
expr = make_opclause(oproid, BOOLOID, false,
(Expr *) leftop, (Expr *) greaterstr);
result = lappend(result,
make_restrictinfo(expr, true, false, false, NULL));
result = lappend(result, make_simple_restrictinfo(expr));
}
return result;
@ -2928,7 +2919,7 @@ network_prefix_quals(Node *leftop, Oid expr_op, Oid opfamily, Datum rightop)
(Expr *) leftop,
(Expr *) makeConst(datatype, -1, -1, opr1right,
false, false));
result = list_make1(make_restrictinfo(expr, true, false, false, NULL));
result = list_make1(make_simple_restrictinfo(expr));
/* create clause "key <= network_scan_last( rightop )" */
@ -2943,8 +2934,7 @@ network_prefix_quals(Node *leftop, Oid expr_op, Oid opfamily, Datum rightop)
(Expr *) leftop,
(Expr *) makeConst(datatype, -1, -1, opr2right,
false, false));
result = lappend(result,
make_restrictinfo(expr, true, false, false, NULL));
result = lappend(result, make_simple_restrictinfo(expr));
return result;
}