Re: possible bug in 8.4

From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>
Cc: PostgreSQL-development Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: possible bug in 8.4
Date: 2008-12-18 17:45:42
Message-ID: 87y6ydl6m1.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl> writes:

> gj=# explain select a.a from a where a not in (select a from b);
> QUERY PLAN
> -------------------------------------------------------------------------
> Seq Scan on a (cost=99035.00..257874197565.00 rows=3000000 width=4)
> Filter: (NOT (subplan))
> SubPlan
> -> Materialize (cost=99035.00..171493.00 rows=5400000 width=4)
> -> Seq Scan on b (cost=0.00..75177.00 rows=5400000 width=4)
> (5 rows)
>
>
> that's absolutely humongous cost, and it really does take ages before this
> thing finishes (had to kill it after an hour).

I think Postgres can't do better because there could be a NULL in the
subquery. If there's a NULL in the subquery then no record would match.

Now your column is NOT NULL so Postgres could do better but AFAIK we don't
look at column constraints like NOT NULL when planning. Historically we
couldn't because we didn't have plan invalidation -- and the plan you posted
below with the Anti-Join is brand new in 8.4 -- so there is room for
improvement but it's not exactly a bug.

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Ask me about EnterpriseDB's On-Demand Production Tuning

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Simon Riggs 2008-12-18 17:47:35 Re: Latest version of Hot Standby patch
Previous Message Bruce Momjian 2008-12-18 17:34:09 Re: Updates of SE-PostgreSQL 8.4devel patches (r1324)