Index: src/backend/commands/vacuumlazy.c
===================================================================
RCS file: /home/alvherre/Code/cvs/pgsql/src/backend/commands/vacuumlazy.c,v
retrieving revision 1.90
diff -c -p -r1.90 vacuumlazy.c
*** src/backend/commands/vacuumlazy.c	30 May 2007 20:11:57 -0000	1.90
--- src/backend/commands/vacuumlazy.c	29 Aug 2007 18:36:18 -0000
*************** static int lazy_vacuum_page(Relation one
*** 120,126 ****
  static void lazy_truncate_heap(Relation onerel, LVRelStats *vacrelstats);
  static BlockNumber count_nondeletable_pages(Relation onerel,
  						 LVRelStats *vacrelstats);
! static void lazy_space_alloc(LVRelStats *vacrelstats, BlockNumber relblocks);
  static void lazy_record_dead_tuple(LVRelStats *vacrelstats,
  					   ItemPointer itemptr);
  static void lazy_record_free_space(LVRelStats *vacrelstats,
--- 121,128 ----
  static void lazy_truncate_heap(Relation onerel, LVRelStats *vacrelstats);
  static BlockNumber count_nondeletable_pages(Relation onerel,
  						 LVRelStats *vacrelstats);
! static void lazy_space_alloc(Relation onerel, LVRelStats *vacrelstats,
! 				 BlockNumber relblocks);
  static void lazy_record_dead_tuple(LVRelStats *vacrelstats,
  					   ItemPointer itemptr);
  static void lazy_record_free_space(LVRelStats *vacrelstats,
*************** lazy_scan_heap(Relation onerel, LVRelSta
*** 289,295 ****
  	vacrelstats->rel_pages = nblocks;
  	vacrelstats->nonempty_pages = 0;
  
! 	lazy_space_alloc(vacrelstats, nblocks);
  
  	for (blkno = 0; blkno < nblocks; blkno++)
  	{
--- 291,297 ----
  	vacrelstats->rel_pages = nblocks;
  	vacrelstats->nonempty_pages = 0;
  
! 	lazy_space_alloc(onerel, vacrelstats, nblocks);
  
  	for (blkno = 0; blkno < nblocks; blkno++)
  	{
*************** count_nondeletable_pages(Relation onerel
*** 964,979 ****
   * See the comments at the head of this file for rationale.
   */
  static void
! lazy_space_alloc(LVRelStats *vacrelstats, BlockNumber relblocks)
  {
  	long		maxtuples;
  	int			maxpages;
  
  	if (vacrelstats->hasindex)
  	{
! 		maxtuples = (maintenance_work_mem * 1024L) / sizeof(ItemPointerData);
  		maxtuples = Min(maxtuples, INT_MAX);
  		maxtuples = Min(maxtuples, MaxAllocSize / sizeof(ItemPointerData));
  		/* stay sane if small maintenance_work_mem */
  		maxtuples = Max(maxtuples, MaxHeapTuplesPerPage);
  	}
--- 966,999 ----
   * See the comments at the head of this file for rationale.
   */
  static void
! lazy_space_alloc(Relation onerel, LVRelStats *vacrelstats, BlockNumber relblocks)
  {
  	long		maxtuples;
  	int			maxpages;
  
  	if (vacrelstats->hasindex)
  	{
! 		BlockNumber	relpages;
! 		double		reltuples;
! 
! 		/* coerce values in pg_class to more desirable types */
! 		relpages = (BlockNumber) onerel->rd_rel->relpages;
! 		reltuples = (double) onerel->rd_rel->reltuples;
! 
! 		/*
! 		 * If the relation has never been vacuumed, assume worst-case
! 		 * number of tuples.  Otherwise, use the density from pg_class to
! 		 * estimate it.
! 		 */
! 		if (relpages > 0)
! 			maxtuples = (long) (reltuples / (double) relpages * (double) relblocks);
! 		else
! 			maxtuples = MaxHeapTuplesPerPage * relblocks;
! 
! 		maxtuples = Min(maxtuples, (maintenance_work_mem * 1024L) / sizeof(ItemPointerData));
  		maxtuples = Min(maxtuples, INT_MAX);
  		maxtuples = Min(maxtuples, MaxAllocSize / sizeof(ItemPointerData));
+ 
  		/* stay sane if small maintenance_work_mem */
  		maxtuples = Max(maxtuples, MaxHeapTuplesPerPage);
  	}
*************** lazy_space_alloc(LVRelStats *vacrelstats
*** 987,992 ****
--- 1007,1014 ----
  	vacrelstats->dead_tuples = (ItemPointer)
  		palloc(maxtuples * sizeof(ItemPointerData));
  
+ 	elog(NOTICE, "alloc'ed %ld bytes for %ld tuples", maxtuples * sizeof(ItemPointerData), maxtuples);
+ 
  	maxpages = MaxFSMPages;
  	maxpages = Min(maxpages, MaxAllocSize / sizeof(PageFreeSpaceInfo));
  	/* No need to allocate more pages than the relation has blocks */
