aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/executor')
-rw-r--r--src/backend/executor/execMain.c52
-rw-r--r--src/backend/executor/functions.c16
-rw-r--r--src/backend/executor/spi.c22
3 files changed, 35 insertions, 55 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:
diff --git a/src/backend/executor/functions.c b/src/backend/executor/functions.c
index 938f7e17f93..1265bc78d4b 100644
--- a/src/backend/executor/functions.c
+++ b/src/backend/executor/functions.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/executor/functions.c,v 1.50 2002/05/12 20:10:02 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/executor/functions.c,v 1.51 2002/05/21 22:05:55 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -465,7 +465,6 @@ fmgr_sql(PG_FUNCTION_ARGS)
SQLFunctionCachePtr fcache;
execution_state *es;
Datum result = 0;
- CommandId savedId;
/*
* Switch to context in which the fcache lives. This ensures that
@@ -475,14 +474,6 @@ fmgr_sql(PG_FUNCTION_ARGS)
oldcontext = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
/*
- * Before we start do anything we must save CurrentScanCommandId to
- * restore it before return to upper Executor. Also, we have to set
- * CurrentScanCommandId equal to CurrentCommandId. - vadim 08/29/97
- */
- savedId = GetScanCommandId();
- SetScanCommandId(GetCurrentCommandId());
-
- /*
* Initialize fcache and execution state if first time through.
*/
fcache = (SQLFunctionCachePtr) fcinfo->flinfo->fn_extra;
@@ -516,11 +507,6 @@ fmgr_sql(PG_FUNCTION_ARGS)
}
/*
- * Restore outer command ID.
- */
- SetScanCommandId(savedId);
-
- /*
* If we've gone through every command in this function, we are done.
*/
if (es == (execution_state *) NULL)
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c
index b9bcce30e29..9c445650e54 100644
--- a/src/backend/executor/spi.c
+++ b/src/backend/executor/spi.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.69 2002/04/15 05:22:04 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.70 2002/05/21 22:05:55 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -106,11 +106,7 @@ SPI_connect(void)
/* ... and switch to procedure's context */
_SPI_current->savedcxt = MemoryContextSwitchTo(_SPI_current->procCxt);
- _SPI_current->savedId = GetScanCommandId();
- SetScanCommandId(GetCurrentCommandId());
-
return SPI_OK_CONNECT;
-
}
int
@@ -129,8 +125,6 @@ SPI_finish(void)
MemoryContextDelete(_SPI_current->execCxt);
MemoryContextDelete(_SPI_current->procCxt);
- SetScanCommandId(_SPI_current->savedId);
-
/*
* After _SPI_begin_call _SPI_connected == _SPI_curid. Now we are
* closing connection to SPI and returning to upper Executor and so
@@ -1233,7 +1227,6 @@ _SPI_cursor_operation(Portal portal, bool forward, int count,
EState *estate;
MemoryContext oldcontext;
ScanDirection direction;
- CommandId savedId;
CommandDest olddest;
/* Check that the portal is valid */
@@ -1260,14 +1253,6 @@ _SPI_cursor_operation(Portal portal, bool forward, int count,
olddest = querydesc->dest;
querydesc->dest = dest;
- /*
- * Restore the scanCommandId that was current when the cursor was
- * opened. This ensures that we see the same tuples throughout the
- * execution of the cursor.
- */
- savedId = GetScanCommandId();
- SetScanCommandId(PortalGetCommandId(portal));
-
/* Run the executor like PerformPortalFetch and remember states */
if (forward)
{
@@ -1300,11 +1285,6 @@ _SPI_cursor_operation(Portal portal, bool forward, int count,
_SPI_current->processed = estate->es_processed;
- /*
- * Restore outer command ID.
- */
- SetScanCommandId(savedId);
-
/* Restore the old command destination and switch back to callers */
/* memory context */
querydesc->dest = olddest;