Search Postgresql Archives

Re: Is there a way too speed up Limit with high OFFSET ?

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

 



Hello

2010/8/12 Georgi Ivanov <georgi.r.ivanov@xxxxxxxxx>:
> Hi,
> I have query like this
> Select * from tabelname limit 10 OFFSET 10;
>
> If i increase the OFFSET to 1000 for example, the query runs slower . The
> bigger is OFFSET the slower is the query.
>

sure - database have to process all rows and skip a first n of result.
This method isn't very efective.

> This is standard pagination feature i use for my website.
> Actually the query is little bit more complex than this, but it is generally
> a
> select with a join.
>
> So i wander if there is a way to speed up this kind of query ?
>
> I'm now reading about windowing functions , but I'm not sure this is the way
> to go for this feature.
>

yes, you have to store a last primary key on page. Then if you wont to
show a next page, you have to select like

SELECT * FROM tablename WHERE id > last_primary_key_on_previous_page LIMIT 10.

When this method isn't possible, then you have to ensure the fast
processing of query without OFFSET. Maybe you have to add index,
increate a work_mem, ...

Regards

Pavel Stehule

>
>

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux