Skip site navigation (1) Skip section navigation (2)

pgsql: Apply a band-aid fix for the problem that 8.2 and up completely

From: tgl(at)postgresql(dot)org (Tom Lane)
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Apply a band-aid fix for the problem that 8.2 and up completely
Date: 2007-08-31 23:35:22
Message-ID: 20070831233522.820E8754201@cvs.postgresql.org (view raw or flat)
Thread:
Lists: pgsql-committers
Log Message:
-----------
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.

Modified Files:
--------------
    pgsql/src/backend/optimizer/path:
        clausesel.c (r1.86 -> r1.87)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/optimizer/path/clausesel.c?r1=1.86&r2=1.87)
    pgsql/src/backend/utils/adt:
        selfuncs.c (r1.235 -> r1.236)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/utils/adt/selfuncs.c?r1=1.235&r2=1.236)
    pgsql/src/include/utils:
        selfuncs.h (r1.39 -> r1.40)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/include/utils/selfuncs.h?r1=1.39&r2=1.40)

pgsql-committers by date

Next:From: Tom LaneDate: 2007-08-31 23:35:30
Subject: pgsql: Apply a band-aid fix for the problem that 8.2 and up completely
Previous:From: Bruce MomjianDate: 2007-08-31 21:33:48
Subject: pgsql: Only use SGML indexterm "zone" when we want to get the entire

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group