Index: src/backend/access/heap/heapam.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/access/heap/heapam.c,v
retrieving revision 1.225
diff -c -r1.225 heapam.c
*** src/backend/access/heap/heapam.c	25 Jan 2007 02:17:25 -0000	1.225
--- src/backend/access/heap/heapam.c	29 Jan 2007 05:10:19 -0000
***************
*** 1248,1253 ****
--- 1248,1254 ----
  	BlockNumber blk;
  	ItemPointerData ctid;
  	TransactionId priorXmax;
+ 	Buffer buffer;
  
  	/* this is to avoid Assert failures on bad input */
  	if (!ItemPointerIsValid(tid))
***************
*** 1275,1283 ****
  	 */
  	ctid = *tid;
  	priorXmax = InvalidTransactionId;	/* cannot check first XMIN */
  	for (;;)
  	{
- 		Buffer		buffer;
  		PageHeader	dp;
  		OffsetNumber offnum;
  		ItemId		lp;
--- 1276,1284 ----
  	 */
  	ctid = *tid;
  	priorXmax = InvalidTransactionId;	/* cannot check first XMIN */
+ 	buffer = InvalidBuffer;
  	for (;;)
  	{
  		PageHeader	dp;
  		OffsetNumber offnum;
  		ItemId		lp;
***************
*** 1287,1293 ****
  		/*
  		 * Read, pin, and lock the page.
  		 */
! 		buffer = ReadBuffer(relation, ItemPointerGetBlockNumber(&ctid));
  		LockBuffer(buffer, BUFFER_LOCK_SHARE);
  		dp = (PageHeader) BufferGetPage(buffer);
  
--- 1288,1295 ----
  		/*
  		 * Read, pin, and lock the page.
  		 */
! 		buffer = ReleaseAndReadBuffer(buffer, relation,
! 									  ItemPointerGetBlockNumber(&ctid));
  		LockBuffer(buffer, BUFFER_LOCK_SHARE);
  		dp = (PageHeader) BufferGetPage(buffer);
  
***************
*** 1298,1313 ****
  		 */
  		offnum = ItemPointerGetOffsetNumber(&ctid);
  		if (offnum < FirstOffsetNumber || offnum > PageGetMaxOffsetNumber(dp))
- 		{
- 			UnlockReleaseBuffer(buffer);
  			break;
! 		}
  		lp = PageGetItemId(dp, offnum);
  		if (!ItemIdIsUsed(lp))
- 		{
- 			UnlockReleaseBuffer(buffer);
  			break;
- 		}
  
  		/* OK to access the tuple */
  		tp.t_self = ctid;
--- 1300,1310 ----
  		 */
  		offnum = ItemPointerGetOffsetNumber(&ctid);
  		if (offnum < FirstOffsetNumber || offnum > PageGetMaxOffsetNumber(dp))
  			break;
! 
  		lp = PageGetItemId(dp, offnum);
  		if (!ItemIdIsUsed(lp))
  			break;
  
  		/* OK to access the tuple */
  		tp.t_self = ctid;
***************
*** 1320,1329 ****
  		 */
  		if (TransactionIdIsValid(priorXmax) &&
  		  !TransactionIdEquals(priorXmax, HeapTupleHeaderGetXmin(tp.t_data)))
- 		{
- 			UnlockReleaseBuffer(buffer);
  			break;
- 		}
  
  		/*
  		 * Check time qualification of tuple; if visible, set it as the new
--- 1317,1323 ----
***************
*** 1338,1352 ****
  		 */
  		if ((tp.t_data->t_infomask & (HEAP_XMAX_INVALID | HEAP_IS_LOCKED)) ||
  			ItemPointerEquals(&tp.t_self, &tp.t_data->t_ctid))
- 		{
- 			UnlockReleaseBuffer(buffer);
  			break;
- 		}
  
  		ctid = tp.t_data->t_ctid;
  		priorXmax = HeapTupleHeaderGetXmax(tp.t_data);
! 		UnlockReleaseBuffer(buffer);
  	}							/* end of loop */
  }
  
  /*
--- 1332,1344 ----
  		 */
  		if ((tp.t_data->t_infomask & (HEAP_XMAX_INVALID | HEAP_IS_LOCKED)) ||
  			ItemPointerEquals(&tp.t_self, &tp.t_data->t_ctid))
  			break;
  
  		ctid = tp.t_data->t_ctid;
  		priorXmax = HeapTupleHeaderGetXmax(tp.t_data);
! 		LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
  	}							/* end of loop */
+ 	UnlockReleaseBuffer(buffer);
  }
  
  /*
Index: src/backend/executor/execMain.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/executor/execMain.c,v
retrieving revision 1.285
diff -c -r1.285 execMain.c
*** src/backend/executor/execMain.c	25 Jan 2007 04:35:10 -0000	1.285
--- src/backend/executor/execMain.c	29 Jan 2007 05:10:19 -0000
***************
*** 1895,1900 ****
--- 1895,1901 ----
  	HeapTupleData tuple;
  	HeapTuple	copyTuple = NULL;
  	bool		endNode;
+ 	Buffer		buffer = InvalidBuffer;
  
  	Assert(rti != 0);
  
***************
*** 1929,1937 ****
  	tuple.t_self = *tid;
  	for (;;)
  	{
! 		Buffer		buffer;
! 
! 		if (heap_fetch(relation, SnapshotDirty, &tuple, &buffer, true, NULL))
  		{
  			/*
  			 * If xmin isn't what we're expecting, the slot must have been
--- 1930,1937 ----
  	tuple.t_self = *tid;
  	for (;;)
  	{
! 		if (heap_release_fetch(relation, SnapshotDirty, &tuple, &buffer,
! 							   true, NULL))
  		{
  			/*
  			 * If xmin isn't what we're expecting, the slot must have been
***************
*** 1960,1965 ****
--- 1960,1966 ----
  			{
  				ReleaseBuffer(buffer);
  				XactLockTableWait(SnapshotDirty->xmax);
+ 				buffer = InvalidBuffer;
  				continue;		/* loop back to repeat heap_fetch */
  			}
  
***************
*** 2032,2038 ****
  		tuple.t_self = tuple.t_data->t_ctid;
  		/* updated row should have xmin matching this xmax */
  		priorXmax = HeapTupleHeaderGetXmax(tuple.t_data);
- 		ReleaseBuffer(buffer);
  		/* loop back to fetch next in chain */
  	}
  
--- 2033,2038 ----