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

From Uwe C. Schroeder
Subject Re: What's faster?
Date
Msg-id 200602091052.03440.uwe@oss4u.com
Whole thread Raw
In response to What's faster?  ("Silas Justiniano" <silasju@gmail.com>)
Responses Re: What's faster?  (Martijn van Oosterhout <kleptog@svana.org>)
List pgsql-general
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.



On Wednesday 08 February 2006 19:45, Silas Justiniano wrote:
> Hello all!
>
> I'm performing a query that returns me hundreds of records... but I
> need cut them in pages that have 15 items! (using PHP)
>
> So, is it faster:
>
>   select blablabal from _complex_query
>   if (count($result) > 15) show_pages;
>   show_only_15_rows($result);
>
> or:
>
>   select count(*) from _complex_query
>   if ($result1 > 15) show_pages;
>   select blablabal from _complex_query LIMIT ... (see the LIMIT!)
>   show $result
>
> On the first, I can use pg_num_rows instead of count(), too.
>
> what do you think?
>
> Thank you!
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
>                http://www.postgresql.org/docs/faq

--
    UC

--
Open Source Solutions 4U, LLC    1618 Kelly St
Phone:  +1 707 568 3056        Santa Rosa, CA 95401
Cell:   +1 650 302 2405        United States
Fax:    +1 707 568 6416

pgsql-general by date:

Previous
From: Florian Weimer
Date:
Subject: Re: Debian Packages For PostgreSQL
Next
From: Hrishikesh Deshmukh
Date:
Subject: PgAdmin3 for Suse AMD64