Re: Pagination - 1 or 2 queries?

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: CSN <cool_screen_name90001(at)yahoo(dot)com>
Cc: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Pagination - 1 or 2 queries?
Date: 2003-09-05 21:03:05
Message-ID: 200309052103.h85L35Z18434@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

CSN wrote:
>
> Behind the scenes, is there much performance
> difference between:
>
> SELECT *
> FROM table_with_millions_of_rows
> ORDER BY col1;
>
> and:
>
> SELECT *
> FROM table_with_millions_of_rows
> ORDER BY col1
> LIMIT 100
> OFFSET 100000;

Yes, the optimizer knows it doesn't have to execute the entire query, so
the later can be faster, but that doesn't return the COUNT(*), as
requested.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Claudio Lapidus 2003-09-05 21:09:51 aggregate function
Previous Message CSN 2003-09-05 20:56:35 Re: Pagination - 1 or 2 queries?