Re: Nested query performance issue

Поиск
Список
Период
Сортировка
От Glenn Maynard
Тема Re: Nested query performance issue
Дата
Msg-id d18085b50904092311i42fcd2fbwbe39cb9361a989f4@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Nested query performance issue  (Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>)
Ответы Re: Nested query performance issue
Список pgsql-performance
On Thu, Apr 9, 2009 at 7:29 AM, Heikki Linnakangas
<heikki.linnakangas@enterprisedb.com> wrote:
> CREATE FUNCTION topnscores(game_id int , n int) RETURNS SETOF score LANGUAGE
> SQL AS $$
> SELECT * FROM score s WHERE s.game_id = $1 ORDER BY score DESC LIMIT $2
> $$;
>
> SELECT (sub.ts).id, (sub.ts).score, (sub.ts).game_id
> FROM (SELECT topnscores(g.id, 5) ts FROM game g) sub;

The inner query:

SELECT topnscores(g.id, 5) ts FROM game g

http://www.postgresql.org/docs/8.3/static/xfunc-sql.html says this is
deprecated (though no deprecation warning is being generated):

> Currently, functions returning sets can also be called in the select list of a query. For each row that the query
generatesby itself, the function returning set is invoked, and an output row is generated for each element of the
function'sresult set. Note, however, that this capability is deprecated and might be removed in future releases. 

It doesn't say how else to write this, though, and it's not obvious to
me.  "SELECT ts.* FROM topnscores(g.id, 5) AS ts, game g" doesn't work
("function expression in FROM cannot refer to other relations of same
query level").  Is there an equivalent way to do this so I won't have
deprecation looming over my back?  I'm likely to become very dependent
on this pattern.

--
Glenn Maynard

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

Предыдущее
От: Josh Berkus
Дата:
Сообщение: Re: Using IOZone to simulate DB access patterns
Следующее
От: Mark Kirkwood
Дата:
Сообщение: Re: Using IOZone to simulate DB access patterns