1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-06 07:49:08 +03:00

Since COPY fires triggers, it seems like a good idea for it to use

a frozen (copied) snapshot too.  Move execMain's snapshot copying code
out into a subroutine in case we find other places that need it.
This commit is contained in:
Tom Lane
2002-05-21 22:59:01 +00:00
parent 26fcd25c57
commit 6c6f395a8a
4 changed files with 44 additions and 22 deletions

View File

@@ -16,7 +16,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.51 2002/05/21 22:05:55 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.52 2002/05/21 22:59:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -963,6 +963,40 @@ SetQuerySnapshot(void)
Assert(QuerySnapshot != NULL);
}
/*
* CopyQuerySnapshot
* Copy the current query snapshot.
*
* Copying the snapshot is done so that a query is guaranteed to use a
* consistent snapshot for its entire execution life, even if the command
* counter is incremented or SetQuerySnapshot() is called while it runs
* (as could easily happen, due to triggers etc. executing queries).
*
* The copy is palloc'd in the current memory context.
*/
Snapshot
CopyQuerySnapshot(void)
{
Snapshot snapshot;
if (QuerySnapshot == NULL) /* should be set already, but... */
SetQuerySnapshot();
snapshot = (Snapshot) palloc(sizeof(SnapshotData));
memcpy(snapshot, QuerySnapshot, sizeof(SnapshotData));
if (snapshot->xcnt > 0)
{
snapshot->xip = (TransactionId *)
palloc(snapshot->xcnt * sizeof(TransactionId));
memcpy(snapshot->xip, QuerySnapshot->xip,
snapshot->xcnt * sizeof(TransactionId));
}
else
snapshot->xip = NULL;
return snapshot;
}
/*
* FreeXactSnapshot
* Free snapshot(s) at end of transaction.