Re: Is it possible to speed this query up?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Arnau <arnaulist@xxxxxxxxxxxxxxxxxx> 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


[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux