Re: Slow query with backwards index scan

От: Tilmann Singer
Тема: Re: Slow query with backwards index scan
Дата: ,
Msg-id: 20070728192713.GH19392@tils.net
(см: обсуждение, исходный текст)
Ответ на: Re: Slow query with backwards index scan  ()
Ответы: Re: Slow query with backwards index scan  (Craig James)
Re: Slow query with backwards index scan  (Jeremy Harris)
Список: pgsql-performance

Скрыть дерево обсуждения

Slow query with backwards index scan  (Tilmann Singer, )
 Re: Slow query with backwards index scan  (Nis Jørgensen, )
  Re: Slow query with backwards index scan  (Tilmann Singer, )
 Re: Slow query with backwards index scan  (, )
  Re: Slow query with backwards index scan  (Tilmann Singer, )
   Re: Slow query with backwards index scan  (Craig James, )
    Re: Slow query with backwards index scan  (Tilmann Singer, )
     Re: Slow query with backwards index scan  (Nis Jørgensen, )
      Re: Slow query with backwards index scan  (Tilmann Singer, )
       Re: Slow query with backwards index scan  (Nis Jørgensen, )
   Re: Slow query with backwards index scan  (Jeremy Harris, )
 Re: Slow query with backwards index scan  (, )

*  <> [20070728 21:05]:
> Let's try putting the sort/limit in each piece of the UNION to speed them up separately.
>
> SELECT * FROM (
>  (SELECT * FROM large_table lt
>  WHERE lt.user_id = 12345
>  ORDER BY created_at DESC LIMIT 10) AS q1
>  UNION
>  (SELECT * FROM large_table lt
>  WHERE user_id IN (SELECT contact_id FROM relationships WHERE user_id=12345)
>  ORDER BY created_at DESC LIMIT 10) AS q2
> ORDER BY created_at DESC LIMIT 10;

It's not possible to use ORDER BY or LIMIT within unioned queries.

http://www.postgresql.org/docs/8.2/static/sql-select.html#SQL-UNION

Would that make sense at all given the way the postgresql planner
works?  Does that work in other DB's?


Til


В списке pgsql-performance по дате сообщения:

От: "Bruno Rodrigues Siqueira"
Дата:
Сообщение: RES: select on 1milion register = 6s
От: "Scott Marlowe"
Дата:
Сообщение: Re: select on 1milion register = 6s