Alvaro Herrera wrote:
> Tom Lane wrote:
> > Atsushi Ogawa <[EMAIL PROTECTED]> 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: Binary data

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Reply via email to