Re: BUG #1756: PQexec eats huge amounts of memory

From: Denis Vlasenko <vda(at)ilport(dot)com(dot)ua>
To: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, John R Pierce <pierce(at)hogranch(dot)com>
Cc: Neil Conway <neilc(at)samurai(dot)com>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #1756: PQexec eats huge amounts of memory
Date: 2005-07-10 10:05:10
Message-ID: 200507101305.10878.vda@ilport.com.ua
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Thursday 07 July 2005 20:43, Alvaro Herrera wrote:
> On Thu, Jul 07, 2005 at 08:17:23AM -0700, John R Pierce wrote:
> > Neil Conway wrote:
> > >Denis Vlasenko wrote:
> > >
> > >>The same php script but done against Oracle does not have this
> > >>behaviour.
> > >
> > >
> > >Perhaps; presumably Oracle is essentially creating a cursor for you
> > >behind the scenes. libpq does not attempt to do this automatically; if
> > >you need a cursor, you can create one by hand.
> >
> > I do not understand how a cursor could be autocreated by a query like
> >
> > $result = pg_query($db, "SELECT * FROM big_table");
> >
> > php will expect $result to contain the entire table (yuck!).
>
> Really? I thought what really happened is you had to get the results
> one at a time using the pg_fetch family of functions. If that is true,
> then it's possible to make the driver fake having the whole table by
> using a cursor. (Even if PHP doesn't do it, it's possible for OCI to do
> it behind the scenes.)

Even without cursor, result can be read incrementally.

I mean, query result is transferred over network, right?
We just can stop read()'ing before we reached the end of result set,
and continue at pg_fetch as needed.

This way server does not need to do any of cursor
creation/destruction work. Not a big win, but combined with
reduced memory usage at client side, it is a win-win situation.
--
vda

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Sivaraman K.G 2005-07-10 18:28:01 Re: [BUGS] BUG #1744: Directory Missing
Previous Message Michael Fuhr 2005-07-09 13:29:33 Re: BUG #1762: Integer multiplication error