Re: select IN problem

Поиск
Список
Период
Сортировка
От Doug Silver
Тема Re: select IN problem
Дата
Msg-id Pine.LNX.4.21.0202221413060.10661-100000@danzig.sd.quantified.net
обсуждение исходный текст
Ответ на Re: select IN problem  (Andrew McMillan <andrew@catalyst.net.nz>)
Ответы Re: select IN problem  (Andrew McMillan <andrew@catalyst.net.nz>)
Список pgsql-novice
On 23 Feb 2002, Andrew McMillan wrote:
>
> SELECT td.transaction_id FROM transactions_detail td
> WHERE EXISTS (SELECT transaction_id FROM transactions t
>    WHERE t.transaction_id = td.transaction_id
>      AND t.enter_date > CAST('2002-02-02' AS DATE );
>
> Could well work better.  The problem you are likely to be encountering
> is that IN (...) will not use an index.
>
> To see the query plans generated by the different SQL, use 'EXPLAIN <sql
> command>' - it is _well_ worth coming to grips with what EXPLAIN can
> tell you.
>
> You could also be better with a plan that did a simple JOIN and
> DISTINCT:
>
> SELECT DISTINCT td.transaction_id
> FROM transactions_detail td, transactions t
> WHERE t.enter_date > '2002-02-02'
>   AND td.transaction_id = t.transaction_id;
>
> Regards,
>                     Andrew.
>

Ok, the transactions table does have an index, so that must be the problem
there, but should it give an error or will it eventually return something?

Thanks, #2 worked as I should have tried something like that earlier.
Still a bit rusty with my sql queries ...

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Doug Silver
Network Manager
Quantified Systems, Inc
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


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

Предыдущее
От: Andrew McMillan
Дата:
Сообщение: Re: indexes on multiple columns
Следующее
От: Andrew McMillan
Дата:
Сообщение: Re: select IN problem