Re: Is it possible to speed this query up?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Is it possible to speed this query up?
Дата
Msg-id 17741.1153945487@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Is it possible to speed this query up?  (Arnau <arnaulist@andromeiberica.com>)
Список pgsql-performance
Arnau <arnaulist@andromeiberica.com> writes:
> the explain analyze shouts the following:

The expensive part appears to be this indexscan:

>                       ->  Index Scan using pk_agndusrgrp_usergroup on
> agenda_users_groups ug  (cost=0.00..123740.26 rows=2936058 width=30)
> (actual time=0.101..61921.260 rows=2836638 loops=1)

Since there's no index condition, the planner is evidently using this
scan just to obtain sort order.  I think ordinarily it would use a
seqscan and then sort the final result, which'd be a lot faster if the
whole result were being selected.  But you have a LIMIT and it's
mistakenly guessing that only a small part of the table will need to be
scanned before the LIMIT is satisfied.

Bottom line: try dropping the LIMIT.  If you really need the limit to be
enforced on the SQL side, you could try declaring the query as a cursor
and only fetching 150 rows from it.

            regards, tom lane

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

Предыдущее
От: Arnau
Дата:
Сообщение: Is it possible to speed this query up?
Следующее
От: Eliott
Дата:
Сообщение: performance issue with a specific query