Pagination of search results
Pagination of search results
am 23.11.2005 17:14:16 von Neil Saunders
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 ) AS c WHERE
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 receive=
d.
Kind Regards,
Neil Saunders.
---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend
Re: Pagination of search results
am 23.11.2005 17:34:43 von dculotta
I think that this is the way.
You need at first time know the number of recrods at first, then you need=
that's records to show.
----- Mensaje original -----
De: Neil Saunders
Fecha: Mi=E9rcoles, Noviembre 23, 2005 1:14 pm
Asunto: [PHP] Pagination of search results
> Hi,
>=20
> 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).
>=20
> 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.
>=20
> The best I've come up with is "SELECT b.*, c.cnt FROM table AS b,
> (SELECT COUNT(1) AS cnt FROM table WHERE ) AS c WHERE
> LIMIT 25 OFFSET 0"
>=20
> However this means that the query is essentially getting executed
> twice for each page.
>=20
> Is there any better way of implementing this? All advice gratefully=20
> received.
> Kind Regards,
>=20
> Neil Saunders.
>=20
> ---------------------------(end of broadcast)-----------------------
> ----
> TIP 6: explain analyze is your friend
>=20
---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match
Re: Pagination of search results
am 23.11.2005 22:06:32 von Keary Suska
on 11/23/05 9:14 AM, n.j.saunders@gmail.com purportedly said:
> 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 ) AS c WHERE
> 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.
As I understand the query planner in PG optimizes for LIMIT, but may not be
able to work in all situations or may require some tweaking for best
performance. If performance is a big issue, the way I have found (that has
the least overall overhead) is to have the application cache results--either
in memory (stored as part of the PHP session) or as a temporary text file
tied to the session. For the latter, the tricky bit is making sure to remove
old files, and there are several ways this can be done depending on
anticipated volume and storage issues. For the former, you need to watch out
for memory issues. I tend to prefer the latter technique unless I can
guarantee that results will be small (including accumulated storage from
multiple simultaneous sessions).
Best regards,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly
Re: Pagination of search results
am 26.11.2005 09:59:53 von Cstdenis
Get the count once and store it in a session.
----- Original Message -----
From: "Neil Saunders"
To:
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 ) AS c WHERE
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
---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings
Re: Pagination of search results
am 27.11.2005 20:33:35 von dculotta
If you sotre the count into a session, maybe you show incorrect information.
It's possible that someone insert a new record when you are changing from
one page to another.
Sorry, my english it's very bad.
----- Original Message -----
From: "Cstdenis"
To: "Neil Saunders" ;
Sent: Saturday, November 26, 2005 5:59 AM
Subject: Re: [PHP] Pagination of search results
> Get the count once and store it in a session.
>
> ----- Original Message -----
> From: "Neil Saunders"
> To:
> 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 ) AS c WHERE
> 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
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
>
>
---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?
http://www.postgresql.org/docs/faq