src/backend/utils/adt/xid8funcs.c
Datum
pg_current_snapshot(PG_FUNCTION_ARGS)
{
	pg_snapshot *snap;
	uint32		nxip,
				i;
	Snapshot	cur;
	FullTransactionId next_fxid = ReadNextFullTransactionId();

	cur = GetActiveSnapshot();
	if (cur == NULL)
		elog(ERROR, "no active snapshot set");

	/*
	 * Compile-time limits on the procarray (MAX_BACKENDS processes plus
	 * MAX_BACKENDS prepared transactions) guarantee nxip won't be too large.
	 */
	StaticAssertStmt(MAX_BACKENDS * 2 <= PG_SNAPSHOT_MAX_NXIP,
					 "possible overflow in pg_current_snapshot()");

	/* allocate */
	nxip = cur->xcnt;
	snap = palloc(PG_SNAPSHOT_SIZE(nxip));

	/* fill */
	snap->xmin = widen_snapshot_xid(cur->xmin, next_fxid);
	snap->xmax = widen_snapshot_xid(cur->xmax, next_fxid);
	snap->nxip = nxip;
	for (i = 0; i < nxip; i++)
		snap->xip[i] = widen_snapshot_xid(cur->xip[i], next_fxid);

	/*
	 * We want them guaranteed to be in ascending order.  This also removes
	 * any duplicate xids.  Normally, an XID can only be assigned to one
	 * backend, but when preparing a transaction for two-phase commit, there
	 * is a transient state when both the original backend and the dummy
	 * PGPROC entry reserved for the prepared transaction hold the same XID.
	 */
	sort_snapshot(snap);

	/* set size after sorting, because it may have removed duplicate xips */
	SET_VARSIZE(snap, PG_SNAPSHOT_SIZE(snap->nxip));

	PG_RETURN_POINTER(snap);
}
/*
 * pg_current_snapshot() returns pg_snapshot
 *
 *		Return current snapshot
 *
 * Note that only top-transaction XIDs are included in the snapshot.
 */


Note that only top-transaction XIDs are included in the snapshot.
Note that only top - transaction XIDs are included in the snapshot .
Datum
pg_current_snapshot(PG_FUNCTION_ARGS)
{
	pg_snapshot *snap;
	uint32		nxip,
				i;
	Snapshot	cur;
	FullTransactionId next_fxid = ReadNextFullTransactionId();
	cur = GetActiveSnapshot();
	if (cur == NULL)
		elog(ERROR, "no active snapshot set");
	StaticAssertStmt(MAX_BACKENDS * 2 <= PG_SNAPSHOT_MAX_NXIP,
					 "possible overflow in pg_current_snapshot()");
	nxip = cur->xcnt;
	snap = palloc(PG_SNAPSHOT_SIZE(nxip));
	snap->xmin = widen_snapshot_xid(cur->xmin, next_fxid);
	snap->xmax = widen_snapshot_xid(cur->xmax, next_fxid);
	snap->nxip = nxip;
	for (i = 0; i < nxip; i++)
		snap->xip[i] = widen_snapshot_xid(cur->xip[i], next_fxid);
	sort_snapshot(snap);
	SET_VARSIZE(snap, PG_SNAPSHOT_SIZE(snap->nxip));
	PG_RETURN_POINTER(snap);
}
Datum pg_current_snapshot ( PG_FUNCTION_ARGS ) { pg_snapshot * snap ; uint32 nxip , i ; Snapshot cur ; FullTransactionId next_fxid = ReadNextFullTransactionId ( ) ; cur = GetActiveSnapshot ( ) ; if ( cur == NULL ) elog ( ERROR , " " ) ; StaticAssertStmt ( MAX_BACKENDS * 2 <= PG_SNAPSHOT_MAX_NXIP , " " ) ; nxip = cur -> xcnt ; snap = palloc ( PG_SNAPSHOT_SIZE ( nxip ) ) ; snap -> xmin = widen_snapshot_xid ( cur -> xmin , next_fxid ) ; snap -> xmax = widen_snapshot_xid ( cur -> xmax , next_fxid ) ; snap -> nxip = nxip ; for ( i = 0 ; i < nxip ; i ++ ) snap -> xip [ i ] = widen_snapshot_xid ( cur -> xip [ i ] , next_fxid ) ; sort_snapshot ( snap ) ; SET_VARSIZE ( snap , PG_SNAPSHOT_SIZE ( snap -> nxip ) ) ; PG_RETURN_POINTER ( snap ) ; }
pg_current_snapshot() returns pg_snapshot
              Return current snapshot
pg_current_snapshot () returns pg_snapshot Return current snapshot
/*
	 * Compile-time limits on the procarray (MAX_BACKENDS processes plus
	 * MAX_BACKENDS prepared transactions) guarantee nxip won't be too large.
	 */ /* allocate */ /* fill */ /*
	 * We want them guaranteed to be in ascending order.  This also removes
	 * any duplicate xids.  Normally, an XID can only be assigned to one
	 * backend, but when preparing a transaction for two-phase commit, there
	 * is a transient state when both the original backend and the dummy
	 * PGPROC entry reserved for the prepared transaction hold the same XID.
	 */ /* set size after sorting, because it may have removed duplicate xips */