Re: problem in select - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: problem in select
Date
Msg-id 20020916173621.B15848@svana.org
Whole thread Raw
In response to Re: problem in select  ("frank_lupo" <frank_lupo@email.it>)
List pgsql-general
Well, here's your problem. Using both IN (which is slow) and DISTINCT (which
is completely unnessesary).

How does this differ from:

select titolo,id,anno
from ircalend
where anno=2002
and exists (select 1 from ircalend_3 where idcalen=ircalend.id)
order by anno,titolo;

On Mon, Sep 16, 2002 at 08:46:27AM +0200, frank_lupo wrote:
> gedis30=# explain select titolo,id,anno from ircalend where anno=2002 and id in(select distinct(idcalend) from
ircalend_3)order by anno,titolo; 
> NOTICE:  QUERY PLAN:
> Sort  (cost=47353.16..47353.16 rows=1 width=49)
>   ->  Seq Scan on ircalend  (cost=0.00..47353.15 rows=1 width=49)
>         SubPlan
>           ->  Materialize  (cost=6764.58..6764.58 rows=7111 width=4)
>                 ->  Unique  (cost=0.00..6764.58 rows=7111 width=4)
>                       ->  Index Scan using ircalend_3_idcalend on ircalend_3  (cost=0.00..6586.80 rows=71112 width=4)
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> There are 10 kinds of people in the world, those that can do binary
> arithmetic and those that can't.

pgsql-general by date:

Previous
From: "frank_lupo"
Date:
Subject: Re: problem in select
Next
From: Manfred Koizar
Date:
Subject: Re: postgres crash