pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Scott Marlowe <smarlowe@qwest.net>
To: ljb <ljb220@mindspring.com>
Cc: pgsql-php@postgresql.org
Subject: Re: pg_fetch_array
Date: Mon, 14 Jun 2004 22:51:26 -0600
Message-ID: <1087275086.1582.1.camel@localhost.localdomain> (raw)
In-Reply-To: <calef8$2qr$1@news.hub.org>
References: <cajbi8$1qrd$1@news.hub.org>
	<calef8$2qr$1@news.hub.org>

On Mon, 2004-06-14 at 18:04, ljb wrote:
> Thanks@verymuch.com wrote:
> > Hello....
> >
> > I would like to know the performance of pg_fetch_array.  Cosider the code:
> >
> > $query = "select * from foo";
> > $result = pg_query( $db, $query );
> >
> > while ($row = pg_fetch_array($result))
> > {
> >    $a = $row["a"];
> >    $b = $row["b"];
> >    $c = $row["c"];
> >    $d = $row["d"];
> > }
> >
> > Does php need to read database everytime when pg_fetch_array is executed in
> > the while loop or all the rows have been in the memory after pg_query?
> 
> The whole result query is stored in memory when pg_query returns, and
> pg_fetch_array just gets the next row.
> 
> > If read database is needed, is there any method to copy all the things into
> > memory by using other command? (because I have a application which needs
> > large amount database update/retrieval and I wish the performance of the
> > overall applications run faster.)
> >
> > or other method you would like to recommend in order to make the faster
> > response time?
> 
> Actually, bringing the whole result into memory before processing any rows
> can be slower, since the web server has to wait for the database server to
> finish before it can start working on the data. So you can't get any
> overlap of database and web server processing.  As far as I know, there
> isn't any alternative currently in the PHP PostgreSQL interface; there are
> asynchronous queries but you still can't process any rows until they all
> come back.

Yes, operating on the whole set in memory at one time is not the best
job for PHP, but maybe for PostgreSQL.  

And there is a way to retrieve some small percentage at a time, use a
cursor.  See declare and fetch in the manual.  Works a charm in PHP.




view thread (12+ messages)  latest in thread

Message-ID: <1087275086.1582.1.camel@localhost.localdomain>
Permalink:  ../1087275086.1582.1.camel@localhost.localdomain/
Also on:    postgresql.org/message-id/1087275086.1582.1.camel@localhost.localdomain

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: smarlowe@qwest.net, ljb220@mindspring.com
  Subject: Re: pg_fetch_array
  In-Reply-To: <1087275086.1582.1.camel@localhost.localdomain>
  References: <cajbi8$1qrd$1@news.hub.org> <calef8$2qr$1@news.hub.org> <1087275086.1582.1.camel@localhost.localdomain>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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