Re: Pagination of search results

From: "Cstdenis" <cstdenis(at)voicio(dot)com>
To: "Neil Saunders" <n(dot)j(dot)saunders(at)gmail(dot)com>, <pgsql-php(at)postgresql(dot)org>
Subject: Re: Pagination of search results
Date: 2005-11-26 08:59:53
Message-ID: 000a01c5f2dc$a3bfa560$6501a8c0@chris
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

Get the count once and store it in a session.

----- Original Message -----
From: "Neil Saunders" <n(dot)j(dot)saunders(at)gmail(dot)com>
To: <pgsql-php(at)postgresql(dot)org>
Sent: Wednesday, November 23, 2005 8:14 AM
Subject: [PHP] Pagination of search results

Hi,

I'm writing a search engine, the results of which will displayed in
blocks of 25, paginated. I will also display the number of records
found (1-25 of 345).

I'm trying to determine the most efficient way to implement this.
Since the session is dropped after the script is terminated, I'm
ruling our cursors. Also, cursors would prevent me from retrieving the
total number of records potentially returned from a search, and so I
couldn't display the correct number of page links. Also, this would
require persistent connections, which I'd like to avoid for a number
of reasons.

The best I've come up with is "SELECT b.*, c.cnt FROM table AS b,
(SELECT COUNT(1) AS cnt FROM table WHERE <LOTS OF CLAUSES>) AS c WHERE
<SAME LOT OF CLAUSES> LIMIT 25 OFFSET 0"

However this means that the query is essentially getting executed
twice for each page.

Is there any better way of implementing this? All advice gratefully
received.

Kind Regards,

Neil Saunders.

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

In response to

Responses

Browse pgsql-php by date

  From Date Subject
Next Message Damián Culotta 2005-11-27 19:33:35 Re: Pagination of search results
Previous Message Rafael Silva 2005-11-25 17:47:22 Cancel my mail