Re: plan difference between set-returning function with ROWS within IN() and a plain join

Поиск
Список
Период
Сортировка
От Merlin Moncure
Тема Re: plan difference between set-returning function with ROWS within IN() and a plain join
Дата
Msg-id b42b73150805100442n103701c4ud105cddac6f391e0@mail.gmail.com
обсуждение исходный текст
Ответ на Re: plan difference between set-returning function with ROWS within IN() and a plain join  (Frank van Vugt <ftm.van.vugt@foxi.nl>)
Список pgsql-performance
On Tue, May 6, 2008 at 11:27 AM, Frank van Vugt <ftm.van.vugt@foxi.nl> wrote:
>> > db=# explain analyse
>> >     select sum(base_total_val)
>> >     from sales_invoice
>> >     where id in (select id from si_credit_tree(80500007));
>>
>> Did you check whether this query even gives the right answer?
>
> You knew the right answer to that already ;)
>
>> I think you forgot the alias foo(id) in the subselect and it's
>> actually reducing to "where id in (id)", ie, TRUE.
>
> Tricky, but completely obvious once pointed out, that's _exactly_ what was
> happening.

This is one of the reasons why, for a table named 'foo', I name the
columns 'foo_id', not 'id'.  Also, if you prefix the id column with
the table name, you can usually use JOIN USING which is a little bit
tighter and easier than JOIN ON.

merlin

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: "append" takes a lot of time in a query
Следующее
От: Rauan Maemirov
Дата:
Сообщение: Re: Query Optimization with Kruskal’s Algorithm