pg.ddx.io pgsql-php@postgresql.org mailing list archive
help / color / mirror / Atom feedPagination of search results
5+ messages / 5 participants
[nested] [flat]
* Pagination of search results
@ 2005-11-23 16:14 Neil Saunders <n.j.saunders@gmail.com>
2005-11-23 21:06 ` Re: Pagination of search results Keary Suska <hierophant@pcisys.net>
2005-11-26 08:59 ` Re: Pagination of search results Cstdenis <cstdenis@voicio.com>
0 siblings, 2 replies; 5+ messages in thread
From: Neil Saunders @ 2005-11-23 16:14 UTC (permalink / raw)
To: pgsql-php
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.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Pagination of search results
2005-11-23 16:14 Pagination of search results Neil Saunders <n.j.saunders@gmail.com>
@ 2005-11-23 21:06 ` Keary Suska <hierophant@pcisys.net>
1 sibling, 0 replies; 5+ messages in thread
From: Keary Suska @ 2005-11-23 21:06 UTC (permalink / raw)
To: pgsql-php
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 <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.
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"
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Pagination of search results
2005-11-23 16:14 Pagination of search results Neil Saunders <n.j.saunders@gmail.com>
@ 2005-11-26 08:59 ` Cstdenis <cstdenis@voicio.com>
2005-11-27 19:33 ` Re: Pagination of search results Damián Culotta <dculotta@fibertel.com.ar>
1 sibling, 1 reply; 5+ messages in thread
From: Cstdenis @ 2005-11-26 08:59 UTC (permalink / raw)
To: Neil Saunders <n.j.saunders@gmail.com>; pgsql-php
Get the count once and store it in a session.
----- Original Message -----
From: "Neil Saunders" <n.j.saunders@gmail.com>
To: <pgsql-php@postgresql.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
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Pagination of search results
2005-11-23 16:14 Pagination of search results Neil Saunders <n.j.saunders@gmail.com>
2005-11-26 08:59 ` Re: Pagination of search results Cstdenis <cstdenis@voicio.com>
@ 2005-11-27 19:33 ` Damián Culotta <dculotta@fibertel.com.ar>
0 siblings, 0 replies; 5+ messages in thread
From: Damián Culotta @ 2005-11-27 19:33 UTC (permalink / raw)
To: Cstdenis <cstdenis@voicio.com>; pgsql-php
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" <cstdenis@voicio.com>
To: "Neil Saunders" <n.j.saunders@gmail.com>; <pgsql-php@postgresql.org>
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" <n.j.saunders@gmail.com>
> To: <pgsql-php@postgresql.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
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
>
>
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Pagination of search results
@ 2005-11-23 16:34 dculotta@fibertel.com.ar
0 siblings, 0 replies; 5+ messages in thread
From: dculotta@fibertel.com.ar @ 2005-11-23 16:34 UTC (permalink / raw)
To: Neil Saunders <n.j.saunders@gmail.com>; +Cc: pgsql-php
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 <n.j.saunders@gmail.com>
Fecha: Miércoles, Noviembre 23, 2005 1:14 pm
Asunto: [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
>
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2005-11-27 19:33 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-11-23 16:14 Pagination of search results Neil Saunders <n.j.saunders@gmail.com>
2005-11-23 21:06 ` Keary Suska <hierophant@pcisys.net>
2005-11-26 08:59 ` Cstdenis <cstdenis@voicio.com>
2005-11-27 19:33 ` Damián Culotta <dculotta@fibertel.com.ar>
2005-11-23 16:34 Re: Pagination of search results dculotta@fibertel.com.ar
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox