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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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 Content-Type Size
libpq_memusage.patch application/octet-stream 2.0 KB

In response to

Responses

Browse pgsql-patches by date

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