diff options
Diffstat (limited to 'src/backend/executor/execMain.c')
-rw-r--r-- | src/backend/executor/execMain.c | 52 |
1 files changed, 33 insertions, 19 deletions
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index a2c43bc0359..a8c776bab2c 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -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: |