Re: Strange Execution-Plan for NOT EXISTS

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jens Hartwig <jhartwig(at)debis(dot)com>
Cc: PostgreSQL SQL <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Strange Execution-Plan for NOT EXISTS
Date: 2001-01-08 19:12:17
Message-ID: 18767.978981137@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Jens Hartwig <jhartwig(at)debis(dot)com> writes:
> select (min(id) + 1)
> from t_dummy d1
> where not exists (
> select id
> from t_dummy d2
> where d2.id = (d1.id + 1)
> );

> Aggregate (cost=2924207.88..2924207.88 rows=1 width=12)
-> Seq Scan on t_dummy d1 (cost=0.00..2924207.88 rows=1 width=12)
> SubPlan
> -> Seq Scan on t_dummy d2 (cost=0.00..331.36 rows=1 width=12)

> Why that? Wouldnt it be possible to simple use the primary key index in
> the sub-query

I think that 7.0.* is too stupid to consider an indexscan for a
qualifier that looks like "indexvar = ($1 + 1)", which is what you
effectively have in this case ($1 being the Param passed in from
the outer plan). It only recognizes "indexvar = constant" and
"indexvar = param" as indexable expressions. Current sources do
better.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Robert B. Easter 2001-01-08 22:24:41 Re: Sv: how to build this query ??? Please help !!!
Previous Message Jens Hartwig 2001-01-08 08:56:29 Re: create default