Re: Unnecessary function calls

Поиск
Список
Период
Сортировка
От Markus Schiltknecht
Тема Re: Unnecessary function calls
Дата
Msg-id 1146572198.18433.54.camel@fotomarburg
обсуждение исходный текст
Ответ на Unnecessary function calls  (Markus Schiltknecht <markus@bluegap.ch>)
Ответы Re: Unnecessary function calls  (Terry Fielder <terry@ashtonwoodshomes.com>)
Список pgsql-general
Hello Terry,

Thanks a lot. That's so simple I didn't see it. (The original query is
much more complex.)

The only problem is, rank is not a column of category itself, but a
joined row. With this solution, the join will have to be performed
twice. But since this doesn't cost that much and because the second join
is only done for 5 rows at the max this does not hurt.

The more complete query now looks a little ugly:

SELECT id, get_category_text_path(id), r.rank
FROM category
JOIN rank_lookup AS r ON cat_id = id
WHERE id IN (
    SELECT c.id
    FROM category AS c
    JOIN rank_lookup AS rr ON rr.cat_id = c.id
    ORDER BY rr.rank
    LIMIT 5
)

It's not possible to optimize out that second join, is it?

Regards

Markus

On Tue, 2006-05-02 at 07:39 -0400, Terry Fielder wrote:
> SELECT id, get_category_text_path(id)
> FROM category
> WHERE id IN (
>    SELECT c.id
>    FROM category AS c
>    ORDER BY c.rank
>    LIMIT 5
> )



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

Предыдущее
От: Martijn van Oosterhout
Дата:
Сообщение: Re: Unnecessary function calls
Следующее
От: Terry Fielder
Дата:
Сообщение: Re: Unnecessary function calls