Re: Unnecessary function calls

From: Markus Schiltknecht <markus(at)bluegap(dot)ch>
To: Terry Fielder <terry(at)ashtonwoodshomes(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Unnecessary function calls
Date: 2006-05-02 12:16:38
Message-ID: 1146572198.18433.54.camel@fotomarburg
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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
> )

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Markus Schiltknecht 2006-05-02 12:27:46 Re: Unnecessary function calls
Previous Message Martijn van Oosterhout 2006-05-02 12:02:19 Re: Unnecessary function calls