Re: Space management for PGresult - Mailing list pgsql-patches

From Atsushi Ogawa
Subject Re: Space management for PGresult
Date
Msg-id 613787150511240448l5f159206n@mail.gmail.com
Whole thread Raw
In response to Re: Space management for PGresult  (Alvaro Herrera <alvherre@commandprompt.com>)
Responses Re: Space management for PGresult
List pgsql-patches
Alvaro Herrera wrote:
> Tom Lane wrote:
> > Atsushi Ogawa <atsushi.ogawa@gmail.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

pgsql-patches by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Space management for PGresult
Next
From: Peter Eisentraut
Date:
Subject: Re: [PATCH] Formatting patch for psql