Re: Help with rewriting query

Поиск
Список
Период
Сортировка
От Tobias Brox
Тема Re: Help with rewriting query
Дата
Msg-id 20050608195625.GM8451@tobias.nordicbet.com
обсуждение исходный текст
Ответ на Help with rewriting query  (Junaili Lie <junaili@gmail.com>)
Ответы Re: Help with rewriting query  (Junaili Lie <junaili@gmail.com>)
Список pgsql-performance
[Junaili Lie - Wed at 12:34:32PM -0700]
> select f.p_id, max(f.id) from person p, food f where p.id=f.p_id group
> by f.p_id will work.
> But I understand this is not the most efficient way. Is there another
> way to rewrite this query? (maybe one that involves order by desc
> limit 1)

eventually, try something like

  select p.id,(select f.id from food f where f.p_id=p.id order by f.id desc limit 1)
  from person p

not tested, no warranties.

Since subqueries can be inefficient, use "explain analyze" to see which one
is actually better.

This issue will be solved in future versions of postgresql.

--
Tobias Brox, +47-91700050
Tallinn

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

Предыдущее
От: Junaili Lie
Дата:
Сообщение: Help with rewriting query
Следующее
От: "Kevin Grittner"
Дата:
Сообщение: Recommendations for configuring a 200 GB database