Re: What's faster?

From: "Uwe C(dot) Schroeder" <uwe(at)oss4u(dot)com>
To: pgsql-general(at)postgresql(dot)org
Cc: "Silas Justiniano" <silasju(at)gmail(dot)com>
Subject: Re: What's faster?
Date: 2006-02-09 18:52:03
Message-ID: 200602091052.03440.uwe@oss4u.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Hrishikesh Deshmukh 2006-02-09 18:52:08 PgAdmin3 for Suse AMD64
Previous Message Florian Weimer 2006-02-09 18:46:16 Re: Debian Packages For PostgreSQL