Re: selects with large offset really slow

From: John Smith <john_smith_45678(at)yahoo(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: selects with large offset really slow
Date: 2003-02-07 22:19:02
Message-ID: 20030207221902.48287.qmail@web40711.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Richard Huxton <dev(at)archonet(dot)com> wrote: > explain analyze select l.id, l.url
> from links l
> inner join stats s
> on l.id = s.link_id
> and s.referrer_id = 1
> order by l.url
> limit 100
> offset 90000;

There are three options you might want to look at:

1. Use a temporary table, then select from that for each page.
2. Use a cursor, and just fetch 100 records at a time from it.
3. Cheat and fetch where l.url>=X, remembering X as the highest url from the
last set of results. This of course means pages of results will overlap.
I tried 1 & 2 - both take about the same about of time as the original query :(. How do people deal with paging results from large tables? As is, web site pages take around 30 seconds to load (often timing out).

John

---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Chris 2003-02-07 23:00:49 Inquiry From Form [pgsql]
Previous Message wsheldah 2003-02-07 22:10:20 Re: selects with large offset really slow