1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-27 23:21:58 +03:00

Remove global variable scanCommandId in favor of storing a command ID

in snapshots, per my proposal of a few days ago.  Also, tweak heapam.c
routines (heap_insert, heap_update, heap_delete, heap_mark4update) to
be passed the command ID to use, instead of doing GetCurrentCommandID.
For catalog updates they'll still get passed current command ID, but
for updates generated from the main executor they'll get passed the
command ID saved in the snapshot the query is using.  This should fix
some corner cases associated with functions and triggers that advance
current command ID while an outer query is still in progress.
This commit is contained in:
Tom Lane
2002-05-21 22:05:55 +00:00
parent 0a2682445e
commit 959e61e917
37 changed files with 191 additions and 235 deletions

View File

@ -27,7 +27,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.161 2002/05/12 20:10:02 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.162 2002/05/21 22:05:55 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -101,6 +101,7 @@ TupleDesc
ExecutorStart(QueryDesc *queryDesc, EState *estate)
{
TupleDesc result;
Snapshot es_snapshot;
/* sanity checks */
Assert(queryDesc != NULL);
@ -114,22 +115,28 @@ ExecutorStart(QueryDesc *queryDesc, EState *estate)
}
/*
* Make our own private copy of the current queries snapshot data
* Make our own private copy of the current query snapshot data.
*
* This "freezes" our idea of which tuples are good and which are not
* for the life of this query, even if it outlives the current command
* and current snapshot.
*/
if (QuerySnapshot == NULL)
estate->es_snapshot = NULL;
else
if (QuerySnapshot == NULL) /* should be set already, but... */
SetQuerySnapshot();
es_snapshot = (Snapshot) palloc(sizeof(SnapshotData));
memcpy(es_snapshot, QuerySnapshot, sizeof(SnapshotData));
if (es_snapshot->xcnt > 0)
{
estate->es_snapshot = (Snapshot) palloc(sizeof(SnapshotData));
memcpy(estate->es_snapshot, QuerySnapshot, sizeof(SnapshotData));
if (estate->es_snapshot->xcnt > 0)
{
estate->es_snapshot->xip = (TransactionId *)
palloc(estate->es_snapshot->xcnt * sizeof(TransactionId));
memcpy(estate->es_snapshot->xip, QuerySnapshot->xip,
estate->es_snapshot->xcnt * sizeof(TransactionId));
}
es_snapshot->xip = (TransactionId *)
palloc(es_snapshot->xcnt * sizeof(TransactionId));
memcpy(es_snapshot->xip, QuerySnapshot->xip,
es_snapshot->xcnt * sizeof(TransactionId));
}
else
es_snapshot->xip = NULL;
estate->es_snapshot = es_snapshot;
/*
* Initialize the plan
@ -1031,7 +1038,8 @@ lnext: ;
erm->resname);
tuple.t_self = *((ItemPointer) DatumGetPointer(datum));
test = heap_mark4update(erm->relation, &tuple, &buffer);
test = heap_mark4update(erm->relation, &tuple, &buffer,
estate->es_snapshot->curcid);
ReleaseBuffer(buffer);
switch (test)
{
@ -1163,7 +1171,8 @@ ExecRetrieve(TupleTableSlot *slot,
*/
if (estate->es_into_relation_descriptor != NULL)
{
heap_insert(estate->es_into_relation_descriptor, tuple);
heap_insert(estate->es_into_relation_descriptor, tuple,
estate->es_snapshot->curcid);
IncrAppended();
}
@ -1239,7 +1248,8 @@ ExecAppend(TupleTableSlot *slot,
/*
* insert the tuple
*/
newId = heap_insert(resultRelationDesc, tuple);
newId = heap_insert(resultRelationDesc, tuple,
estate->es_snapshot->curcid);
IncrAppended();
(estate->es_processed)++;
@ -1301,7 +1311,9 @@ ExecDelete(TupleTableSlot *slot,
* delete the tuple
*/
ldelete:;
result = heap_delete(resultRelationDesc, tupleid, &ctid);
result = heap_delete(resultRelationDesc, tupleid,
&ctid,
estate->es_snapshot->curcid);
switch (result)
{
case HeapTupleSelfUpdated:
@ -1433,7 +1445,9 @@ lreplace:;
/*
* replace the heap tuple
*/
result = heap_update(resultRelationDesc, tupleid, tuple, &ctid);
result = heap_update(resultRelationDesc, tupleid, tuple,
&ctid,
estate->es_snapshot->curcid);
switch (result)
{
case HeapTupleSelfUpdated: