Re: how to make this database / query faster - Mailing list pgsql-general

From Richard Broersma
Subject Re: how to make this database / query faster
Date
Msg-id 396486430803151637g2d581f54i149e03eab61b4bd1@mail.gmail.com
Whole thread Raw
In response to how to make this database / query faster  (mark <markkicks@gmail.com>)
Responses Re: how to make this database / query faster  (mark <markkicks@gmail.com>)
List pgsql-general
On Sat, Mar 15, 2008 at 4:21 PM, mark <markkicks@gmail.com> wrote:
 
select * from users where session_key is not Null order by id offset OFFSET limit 300

OFFSET actually scans past all of the records that specify in the "OFFSET".  So the bigger your offset the longer the scan will be.
 
One solution is to retain the last ID from the previous scan:
 
SELECT *
  FROM Users
 WHERE session_key IS NOT NULL
    AND id > your_last_id
  LIMIT 300;

pgsql-general by date:

Previous
From: Terry Fielder
Date:
Subject: Re: Loging of postgres requests
Next
From: mark
Date:
Subject: Re: how to make this database / query faster