Index: src/backend/storage/ipc/procarray.c
===================================================================
RCS file: /home/sriggs/pg/REPOSITORY/pgsql/src/backend/storage/ipc/procarray.c,v
retrieving revision 1.49
diff -c -r1.49 procarray.c
*** src/backend/storage/ipc/procarray.c	4 Apr 2009 17:40:36 -0000	1.49
--- src/backend/storage/ipc/procarray.c	17 May 2009 19:46:05 -0000
***************
*** 729,804 ****
  	/* initialize xmin calculation with xmax */
  	globalxmin = xmin = xmax;
  
! 	/*
! 	 * Spin over procArray checking xid, xmin, and subxids.  The goal is to
! 	 * gather all active xids, find the lowest xmin, and try to record
! 	 * subxids.
! 	 */
! 	for (index = 0; index < arrayP->numProcs; index++)
  	{
- 		volatile PGPROC *proc = arrayP->procs[index];
- 		TransactionId xid;
- 
- 		/* Ignore procs running LAZY VACUUM */
- 		if (proc->vacuumFlags & PROC_IN_VACUUM)
- 			continue;
- 
- 		/* Update globalxmin to be the smallest valid xmin */
- 		xid = proc->xmin;		/* fetch just once */
- 		if (TransactionIdIsNormal(xid) &&
- 			TransactionIdPrecedes(xid, globalxmin))
- 			globalxmin = xid;
- 
- 		/* Fetch xid just once - see GetNewTransactionId */
- 		xid = proc->xid;
- 
  		/*
! 		 * If the transaction has been assigned an xid < xmax we add it to the
! 		 * snapshot, and update xmin if necessary.	There's no need to store
! 		 * XIDs >= xmax, since we'll treat them as running anyway.  We don't
! 		 * bother to examine their subxids either.
! 		 *
! 		 * We don't include our own XID (if any) in the snapshot, but we must
! 		 * include it into xmin.
  		 */
! 		if (TransactionIdIsNormal(xid))
  		{
! 			if (TransactionIdFollowsOrEquals(xid, xmax))
  				continue;
- 			if (proc != MyProc)
- 				snapshot->xip[count++] = xid;
- 			if (TransactionIdPrecedes(xid, xmin))
- 				xmin = xid;
- 		}
  
! 		/*
! 		 * Save subtransaction XIDs if possible (if we've already overflowed,
! 		 * there's no point).  Note that the subxact XIDs must be later than
! 		 * their parent, so no need to check them against xmin.  We could
! 		 * filter against xmax, but it seems better not to do that much work
! 		 * while holding the ProcArrayLock.
! 		 *
! 		 * The other backend can add more subxids concurrently, but cannot
! 		 * remove any.	Hence it's important to fetch nxids just once. Should
! 		 * be safe to use memcpy, though.  (We needn't worry about missing any
! 		 * xids added concurrently, because they must postdate xmax.)
! 		 *
! 		 * Again, our own XIDs are not included in the snapshot.
! 		 */
! 		if (subcount >= 0 && proc != MyProc)
! 		{
! 			if (proc->subxids.overflowed)
! 				subcount = -1;	/* overflowed */
! 			else
  			{
! 				int			nxids = proc->subxids.nxids;
  
! 				if (nxids > 0)
  				{
! 					memcpy(snapshot->subxip + subcount,
! 						   (void *) proc->subxids.xids,
! 						   nxids * sizeof(TransactionId));
! 					subcount += nxids;
  				}
  			}
  		}
--- 729,808 ----
  	/* initialize xmin calculation with xmax */
  	globalxmin = xmin = xmax;
  
! 	/* If our snapshot is new, or snapshot has changed, re-calculate */
! 	if (snapshot->xmax != xmax || snapshot->xmin != snapshot->xmax)
  	{
  		/*
! 		 * Spin over procArray checking xid, xmin, and subxids.  The goal is to
! 		 * gather all active xids, find the lowest xmin, and try to record
! 		 * subxids.
  		 */
! 		for (index = 0; index < arrayP->numProcs; index++)
  		{
! 			volatile PGPROC *proc = arrayP->procs[index];
! 			TransactionId xid;
! 
! 			/* Ignore procs running LAZY VACUUM */
! 			if (proc->vacuumFlags & PROC_IN_VACUUM)
  				continue;
  
! 			/* Update globalxmin to be the smallest valid xmin */
! 			xid = proc->xmin;		/* fetch just once */
! 			if (TransactionIdIsNormal(xid) &&
! 				TransactionIdPrecedes(xid, globalxmin))
! 				globalxmin = xid;
! 
! 			/* Fetch xid just once - see GetNewTransactionId */
! 			xid = proc->xid;
! 
! 			/*
! 			 * If the transaction has been assigned an xid < xmax we add it to the
! 			 * snapshot, and update xmin if necessary.	There's no need to store
! 			 * XIDs >= xmax, since we'll treat them as running anyway.  We don't
! 			 * bother to examine their subxids either.
! 			 *
! 			 * We don't include our own XID (if any) in the snapshot, but we must
! 			 * include it into xmin.
! 			 */
! 			if (TransactionIdIsNormal(xid))
  			{
! 				if (TransactionIdFollowsOrEquals(xid, xmax))
! 					continue;
! 				if (proc != MyProc)
! 					snapshot->xip[count++] = xid;
! 				if (TransactionIdPrecedes(xid, xmin))
! 					xmin = xid;
! 			}
  
! 			/*
! 			 * Save subtransaction XIDs if possible (if we've already overflowed,
! 			 * there's no point).  Note that the subxact XIDs must be later than
! 			 * their parent, so no need to check them against xmin.  We could
! 			 * filter against xmax, but it seems better not to do that much work
! 			 * while holding the ProcArrayLock.
! 			 *
! 			 * The other backend can add more subxids concurrently, but cannot
! 			 * remove any.	Hence it's important to fetch nxids just once. Should
! 			 * be safe to use memcpy, though.  (We needn't worry about missing any
! 			 * xids added concurrently, because they must postdate xmax.)
! 			 *
! 			 * Again, our own XIDs are not included in the snapshot.
! 			 */
! 			if (subcount >= 0 && proc != MyProc)
! 			{
! 				if (proc->subxids.overflowed)
! 					subcount = -1;	/* overflowed */
! 				else
  				{
! 					int			nxids = proc->subxids.nxids;
! 
! 					if (nxids > 0)
! 					{
! 						memcpy(snapshot->subxip + subcount,
! 							   (void *) proc->subxids.xids,
! 							   nxids * sizeof(TransactionId));
! 						subcount += nxids;
! 					}
  				}
  			}
  		}
