Skip site navigation (1) Skip section navigation (2)

Re: Space management for PGresult

From: Atsushi Ogawa <atsushi(dot)ogawa(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Alvaro Herrera <alvherre(at)commandprompt(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: Space management for PGresult
Date: 2005-11-24 12:48:21
Message-ID: 613787150511240448l5f159206n@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-patches
Alvaro Herrera wrote:
> Tom Lane wrote:
> > Atsushi Ogawa <atsushi(dot)ogawa(at)gmail(dot)com> writes:
> > > The number of malloc calls at pqResultAlloc:
> > >  8.1.0  : 80542
> > >  patched:    86
> >
> > > Execution time:
> > >  8.1.0  : 6.80 sec
> > >  patched: 6.73 sec
> >
> > This hardly seems worth adding any complexity for ...
>
> What about memory usage?  Is there a notorious difference?

Well, I measured memory usage by attached patch. An allocated(bytes)
is total amounts of allocated memory by pqResultAlloc. An unused(bytes)
is total amounts of PGresult->spaceLeft.

(1)accounts table (4 columns, 1,000,000 tuples)
          malloc calls   allocated(bytes)   unused(bytes)  execution time
--------------------------------------------------------------------------
8.1.0           80,542        164,950,016       2,946,402       6.80 sec.
patched             86        161,478,656         177,650       6.73 sec.

(2)another teble (50 columns, 100,000 tuples)
          malloc calls   allocated(bytes)   unused(bytes)  execution time
--------------------------------------------------------------------------
8.1.0           55,557        113,780,736       8,561,518       6.26 sec.
patched             86        104,855,552          83,307       6.21 sec.

The unused memory increases when the number of columns increases. The
tuple size of PGresult is proportional to the number of columns.

getAnotherTuple() at fe-protocol3.c:
--------------------------------------------------------------------------
        conn->curTuple = (PGresAttValue *)
            pqResultAlloc(result, nfields * sizeof(PGresAttValue), TRUE);
--------------------------------------------------------------------------

regards,

--- Atsushi Ogawa

Attachment: libpq_memusage.patch
Description: application/octet-stream (2.0 KB)

In response to

Responses

pgsql-patches by date

Next:From: Peter EisentrautDate: 2005-11-24 14:45:12
Subject: Re: [PATCH] Formatting patch for psql
Previous:From: Bruce MomjianDate: 2005-11-24 04:40:55
Subject: Re: [PATCHES] drop database if exists

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group