*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/path/clausesel.c,v 1.89 2008/01/01 19:45:50 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/path/clausesel.c,v 1.90 2008/01/11 17:00:45 tgl Exp $
*
*-------------------------------------------------------------------------
*/
int varRelid,
JoinType jointype)
{
- Selectivity s1 = 1.0; /* default for any unhandled clause type */
+ Selectivity s1 = 0.5; /* default for any unhandled clause type */
RestrictInfo *rinfo = NULL;
bool cacheable = false;
if (rinfo->pseudoconstant)
{
if (!IsA(rinfo->clause, Const))
- return s1;
+ return (Selectivity) 1.0;
}
/*
{
/*
* XXX not smart about subquery references... any way to do
- * better?
+ * better than default?
*/
- s1 = 0.5;
}
else
{
}
else
{
- /* XXX any way to do better? */
- s1 = (Selectivity) 0.5;
+ /* XXX any way to do better than default? */
}
}
else if (not_clause(clause))
s1 = s1 + s2 - s1 * s2;
}
}
- else if (is_opclause(clause))
+ else if (is_opclause(clause) || IsA(clause, DistinctExpr))
{
Oid opno = ((OpExpr *) clause)->opno;
bool is_join_clause;
((OpExpr *) clause)->args,
varRelid);
}
+
+ /*
+ * DistinctExpr has the same representation as OpExpr, but the
+ * contained operator is "=" not "<>", so we must negate the result.
+ * This estimation method doesn't give the right behavior for nulls,
+ * but it's better than doing nothing.
+ */
+ if (IsA(clause, DistinctExpr))
+ s1 = 1.0 - s1;
}
else if (is_funcclause(clause))
{
*/
s1 = (Selectivity) 0.3333333;
}
+#ifdef NOT_USED
else if (is_subplan(clause))
{
/*
*/
s1 = (Selectivity) 0.5;
}
- else if (IsA(clause, DistinctExpr))
- {
- /* can we do better? */
- s1 = (Selectivity) 0.5;
- }
+#endif
else if (IsA(clause, ScalarArrayOpExpr))
{
/* First, decide if it's a join clause, same as for OpExpr */