Re: how to make this database / query faster

From: "Richard Broersma" <richard(dot)broersma(at)gmail(dot)com>
To: mark <markkicks(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: how to make this database / query faster
Date: 2008-03-15 23:37:40
Message-ID: 396486430803151637g2d581f54i149e03eab61b4bd1@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, Mar 15, 2008 at 4:21 PM, mark <markkicks(at)gmail(dot)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;

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message mark 2008-03-15 23:41:56 Re: how to make this database / query faster
Previous Message Terry Fielder 2008-03-15 23:25:32 Re: Loging of postgres requests