Re: What's faster?

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: "Uwe C(dot) Schroeder" <uwe(at)oss4u(dot)com>
Cc: pgsql-general(at)postgresql(dot)org, Silas Justiniano <silasju(at)gmail(dot)com>
Subject: Re: What's faster?
Date: 2006-02-09 19:38:11
Message-ID: 20060209193811.GE14852@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Feb 09, 2006 at 10:52:03AM -0800, Uwe C. Schroeder wrote:
> Depending on your keys neither.
> Rather let the DB handle the resultset. count(*) is quite slow.
>
> How about something like
>
> select blablabla from _complex_query order by _key_ (optional DESC or ASC)
> OFFSET xxx LIMIT 15
>
> where your offset would be a parameter from the php side and is basically the
> page number of the number of pages you want to display.
> The only drawback of that is that you will never see the total number of hits.
> So maybe you do a count(*) ONCE and then use the above query to loop over the
> resultset - or you don't show the number of pages and just have a "next
> results" and "previous results" button that adjusts the offset parameter.

Another possibility is to put a limit of 151. If you get 151 rows you
print 1 2 3 .. 8 9 10 More. If you get less you know how many pages. As
you get to page 5 you can limit to 225+1.

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2006-02-09 19:49:19 Re: [GENERAL] Sequences/defaults and pg_dump
Previous Message Joachim Wieland 2006-02-09 19:31:07 Re: [GENERAL] Sequences/defaults and pg_dump