Re: problem (bug?) with "in (subquery)"

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: problem (bug?) with "in (subquery)"
Дата
Msg-id 20050715133404.GA30210@winnie.fuhr.org
обсуждение исходный текст
Ответ на problem (bug?) with "in (subquery)"  (Luca Pireddu <luca@cs.ualberta.ca>)
Ответы Re: problem (bug?) with "in (subquery)"  (Luca Pireddu <lucap@shaw.ca>)
Список pgsql-sql
On Thu, Jul 14, 2005 at 01:34:21AM -0600, Luca Pireddu wrote:
> I have the following query that isn't behaving like I would expect:
> 
> select * from strains s where s.id in (select strain_id from pathway_strains);

Any reason the subquery isn't doing "SELECT DISTINCT strain_id"?

> I would expect each strain record to appear only once.  Instead I get output 
> like this, where the same strain id appears many times:
> 
>   id   |     name     | organism
> -------+--------------+----------
>     83 | common       |       82 
>     83 | common       |       82 
>     83 | common       |       82 

What happens when you try each of the following?  Do they give the
expected results?  I did some tests and I'm wondering if the planner's
hash join is responsible for the duplicate rows.

SELECT * FROM strains WHERE id IN ( SELECT strain_id FROM pathway_strains ORDER BY strain_id
);

CREATE TEMPORARY TABLE foo AS SELECT strain_id FROM pathway_strains;
SELECT * FROM strains WHERE id IN (SELECT strain_id FROM foo);

SET enable_hashjoin TO off;
SELECT * FROM strains WHERE id IN (SELECT strain_id FROM pathway_strains);

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/


В списке pgsql-sql по дате отправления:

Предыдущее
От: Neil Dugan
Дата:
Сообщение: Re: How to obtain the list of data table name only
Следующее
От: Tom Lane
Дата:
Сообщение: Re: problem (bug?) with "in (subquery)"