Re: 8.4devel out of memory - Mailing list pgsql-hackers

From Tom Lane
Subject Re: 8.4devel out of memory
Date
Msg-id 12081.1223592933@sss.pgh.pa.us
Whole thread Raw
In response to 8.4devel out of memory  ("Kevin Grittner" <Kevin.Grittner@wicourts.gov>)
Responses Re: 8.4devel out of memory  ("Kevin Grittner" <Kevin.Grittner@wicourts.gov>)
List pgsql-hackers
Hah, got it.  The reason the leak only manifests on 32-bit is that it
only manifests if int8 is a pass-by-reference datatype.  The new API
for amgetbitmap causes a query-lifespan leak of one palloc(sizeof(int8))
per bitmap index scan.  The distinguishing feature of your query seems
to be just that it does enough repeated bitmapscans to notice ...

The attached patch cures the leak for me, but I find it a tad ugly.
I'm tempted to think that it would be better if we changed the call
signature for amgetbitmap so that it returned the count through an
"int64 *" output parameter.  Thoughts anyone?
        regards, tom lane


Index: src/backend/access/index/indexam.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/access/index/indexam.c,v
retrieving revision 1.110
diff -c -r1.110 indexam.c
*** src/backend/access/index/indexam.c    11 Sep 2008 14:01:09 -0000    1.110
--- src/backend/access/index/indexam.c    9 Oct 2008 22:47:54 -0000
***************
*** 655,660 ****
--- 655,661 ---- {     FmgrInfo   *procedure;     int64        ntids;
+     Datum        d;      SCAN_CHECKS;     GET_SCAN_PROCEDURE(amgetbitmap);
***************
*** 665,673 ****     /*      * have the am's getbitmap proc do all the work.      */
!     ntids = DatumGetInt64(FunctionCall2(procedure,
!                                         PointerGetDatum(scan),
!                                         PointerGetDatum(bitmap)));
pgstat_count_index_tuples(scan->indexRelation,ntids); 
 
--- 666,680 ----     /*      * have the am's getbitmap proc do all the work.      */
!     d = FunctionCall2(procedure,
!                       PointerGetDatum(scan),
!                       PointerGetDatum(bitmap));
! 
!     ntids = DatumGetInt64(d);
! 
! #ifndef USE_FLOAT8_BYVAL
!     pfree(DatumGetPointer(d));
! #endif      pgstat_count_index_tuples(scan->indexRelation, ntids); 



pgsql-hackers by date:

Previous
From: "Jaime Casanova"
Date:
Subject: avoid create a tablespace in pg_tblspc
Next
From: Tom Lane
Date:
Subject: Re: autovacuum and TOAST tables