Re: What's faster? - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: What's faster?
Date
Msg-id 20060209193811.GE14852@svana.org
Whole thread Raw
In response to Re: What's faster?  ("Uwe C. Schroeder" <uwe@oss4u.com>)
Responses Insert more than one t-uple in a single sql
List 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@svana.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.

Attachment

pgsql-general by date:

Previous
From: "Benjamin Arai"
Date:
Subject: Return more then one value using PL
Next
From: "Mike G."
Date:
Subject: Update table with data from another table