diff options
| author | Tom Lane | 2007-08-31 23:35:22 +0000 |
|---|---|---|
| committer | Tom Lane | 2007-08-31 23:35:22 +0000 |
| commit | 0ee5a39862748b846786db48f41cc29eab38c015 (patch) | |
| tree | f08622f82609ccd3c8ff7f156f6177a94e31089a /src/include | |
| parent | a55eab89219dde7a98ee75da4cad56ff19d84582 (diff) | |
Apply a band-aid fix for the problem that 8.2 and up completely misestimate
the number of rows likely to be produced by a query such as
SELECT * FROM t1 LEFT JOIN t2 USING (key) WHERE t2.key IS NULL;
What this is doing is selecting for t1 rows with no match in t2, and thus
it may produce a significant number of rows even if the t2.key table column
contains no nulls at all. 8.2 thinks the table column's null fraction is
relevant and thus may estimate no rows out, which results in terrible plans
if there are more joins above this one. A proper fix for this will involve
passing much more information about the context of a clause to the selectivity
estimator functions than we ever have. There's no time left to write such a
patch for 8.3, and it wouldn't be back-patchable into 8.2 anyway. Instead,
put in an ad-hoc test to defeat the normal table-stats-based estimation when
an IS NULL test is evaluated at an outer join, and just use a constant
estimate instead --- I went with 0.5 for lack of a better idea. This won't
catch every case but it will catch the typical ways of writing such queries,
and it seems unlikely to make things worse for other queries.
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/utils/selfuncs.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/include/utils/selfuncs.h b/src/include/utils/selfuncs.h index f0c6f20427c..fc409d9bddd 100644 --- a/src/include/utils/selfuncs.h +++ b/src/include/utils/selfuncs.h @@ -8,7 +8,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/utils/selfuncs.h,v 1.39 2007/01/22 20:00:40 tgl Exp $ + * $PostgreSQL: pgsql/src/include/utils/selfuncs.h,v 1.40 2007/08/31 23:35:22 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -149,7 +149,7 @@ extern Datum icnlikejoinsel(PG_FUNCTION_ARGS); extern Selectivity booltestsel(PlannerInfo *root, BoolTestType booltesttype, Node *arg, int varRelid, JoinType jointype); extern Selectivity nulltestsel(PlannerInfo *root, NullTestType nulltesttype, - Node *arg, int varRelid); + Node *arg, int varRelid, JoinType jointype); extern Selectivity scalararraysel(PlannerInfo *root, ScalarArrayOpExpr *clause, bool is_join_clause, |
