Commit 959e61e9 authored by Tom Lane's avatar Tom Lane

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.
parent 0a268244
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.134 2002/05/20 23:51:41 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.135 2002/05/21 22:05:53 tgl Exp $
* *
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
...@@ -1059,15 +1059,14 @@ heap_get_latest_tid(Relation relation, ...@@ -1059,15 +1059,14 @@ heap_get_latest_tid(Relation relation,
return tid; return tid;
} }
/* ---------------- /*
* heap_insert - insert tuple into a heap * heap_insert - insert tuple into a heap
* *
* The assignment of t_min (and thus the others) should be * The new tuple is stamped with current transaction ID and the specified
* removed eventually. * command ID.
* ----------------
*/ */
Oid Oid
heap_insert(Relation relation, HeapTuple tup) heap_insert(Relation relation, HeapTuple tup, CommandId cid)
{ {
Buffer buffer; Buffer buffer;
...@@ -1093,8 +1092,9 @@ heap_insert(Relation relation, HeapTuple tup) ...@@ -1093,8 +1092,9 @@ heap_insert(Relation relation, HeapTuple tup)
} }
TransactionIdStore(GetCurrentTransactionId(), &(tup->t_data->t_xmin)); TransactionIdStore(GetCurrentTransactionId(), &(tup->t_data->t_xmin));
tup->t_data->t_cmin = GetCurrentCommandId(); tup->t_data->t_cmin = cid;
StoreInvalidTransactionId(&(tup->t_data->t_xmax)); StoreInvalidTransactionId(&(tup->t_data->t_xmax));
tup->t_data->t_cmax = FirstCommandId;
tup->t_data->t_infomask &= ~(HEAP_XACT_MASK); tup->t_data->t_infomask &= ~(HEAP_XACT_MASK);
tup->t_data->t_infomask |= HEAP_XMAX_INVALID; tup->t_data->t_infomask |= HEAP_XMAX_INVALID;
tup->t_tableOid = relation->rd_id; tup->t_tableOid = relation->rd_id;
...@@ -1178,6 +1178,19 @@ heap_insert(Relation relation, HeapTuple tup) ...@@ -1178,6 +1178,19 @@ heap_insert(Relation relation, HeapTuple tup)
return tup->t_data->t_oid; return tup->t_data->t_oid;
} }
/*
* simple_heap_insert - insert a tuple
*
* Currently, this routine differs from heap_insert only in supplying
* a default command ID. But it should be used rather than using
* heap_insert directly in most places where we are modifying system catalogs.
*/
Oid
simple_heap_insert(Relation relation, HeapTuple tup)
{
return heap_insert(relation, tup, GetCurrentCommandId());
}
/* /*
* heap_delete - delete a tuple * heap_delete - delete a tuple
* *
...@@ -1185,7 +1198,8 @@ heap_insert(Relation relation, HeapTuple tup) ...@@ -1185,7 +1198,8 @@ heap_insert(Relation relation, HeapTuple tup)
* concurrent-update conditions. Use simple_heap_delete instead. * concurrent-update conditions. Use simple_heap_delete instead.
*/ */
int int
heap_delete(Relation relation, ItemPointer tid, ItemPointer ctid) heap_delete(Relation relation, ItemPointer tid,
ItemPointer ctid, CommandId cid)
{ {
ItemId lp; ItemId lp;
HeapTupleData tp; HeapTupleData tp;
...@@ -1215,7 +1229,7 @@ heap_delete(Relation relation, ItemPointer tid, ItemPointer ctid) ...@@ -1215,7 +1229,7 @@ heap_delete(Relation relation, ItemPointer tid, ItemPointer ctid)
tp.t_tableOid = relation->rd_id; tp.t_tableOid = relation->rd_id;
l1: l1:
result = HeapTupleSatisfiesUpdate(&tp); result = HeapTupleSatisfiesUpdate(&tp, cid);
if (result == HeapTupleInvisible) if (result == HeapTupleInvisible)
{ {
...@@ -1265,7 +1279,7 @@ l1: ...@@ -1265,7 +1279,7 @@ l1:
START_CRIT_SECTION(); START_CRIT_SECTION();
/* store transaction information of xact deleting the tuple */ /* store transaction information of xact deleting the tuple */
TransactionIdStore(GetCurrentTransactionId(), &(tp.t_data->t_xmax)); TransactionIdStore(GetCurrentTransactionId(), &(tp.t_data->t_xmax));
tp.t_data->t_cmax = GetCurrentCommandId(); tp.t_data->t_cmax = cid;
tp.t_data->t_infomask &= ~(HEAP_XMAX_COMMITTED | tp.t_data->t_infomask &= ~(HEAP_XMAX_COMMITTED |
HEAP_XMAX_INVALID | HEAP_MARKED_FOR_UPDATE); HEAP_XMAX_INVALID | HEAP_MARKED_FOR_UPDATE);
/* XLOG stuff */ /* XLOG stuff */
...@@ -1336,7 +1350,7 @@ simple_heap_delete(Relation relation, ItemPointer tid) ...@@ -1336,7 +1350,7 @@ simple_heap_delete(Relation relation, ItemPointer tid)
ItemPointerData ctid; ItemPointerData ctid;
int result; int result;
result = heap_delete(relation, tid, &ctid); result = heap_delete(relation, tid, &ctid, GetCurrentCommandId());
switch (result) switch (result)
{ {
case HeapTupleSelfUpdated: case HeapTupleSelfUpdated:
...@@ -1356,7 +1370,6 @@ simple_heap_delete(Relation relation, ItemPointer tid) ...@@ -1356,7 +1370,6 @@ simple_heap_delete(Relation relation, ItemPointer tid)
elog(ERROR, "Unknown status %u from heap_delete", result); elog(ERROR, "Unknown status %u from heap_delete", result);
break; break;
} }
} }
/* /*
...@@ -1367,7 +1380,7 @@ simple_heap_delete(Relation relation, ItemPointer tid) ...@@ -1367,7 +1380,7 @@ simple_heap_delete(Relation relation, ItemPointer tid)
*/ */
int int
heap_update(Relation relation, ItemPointer otid, HeapTuple newtup, heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
ItemPointer ctid) ItemPointer ctid, CommandId cid)
{ {
ItemId lp; ItemId lp;
HeapTupleData oldtup; HeapTupleData oldtup;
...@@ -1407,7 +1420,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup, ...@@ -1407,7 +1420,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
*/ */
l2: l2:
result = HeapTupleSatisfiesUpdate(&oldtup); result = HeapTupleSatisfiesUpdate(&oldtup, cid);
if (result == HeapTupleInvisible) if (result == HeapTupleInvisible)
{ {
...@@ -1457,7 +1470,7 @@ l2: ...@@ -1457,7 +1470,7 @@ l2:
/* Fill in OID and transaction status data for newtup */ /* Fill in OID and transaction status data for newtup */
newtup->t_data->t_oid = oldtup.t_data->t_oid; newtup->t_data->t_oid = oldtup.t_data->t_oid;
TransactionIdStore(GetCurrentTransactionId(), &(newtup->t_data->t_xmin)); TransactionIdStore(GetCurrentTransactionId(), &(newtup->t_data->t_xmin));
newtup->t_data->t_cmin = GetCurrentCommandId(); newtup->t_data->t_cmin = cid;
StoreInvalidTransactionId(&(newtup->t_data->t_xmax)); StoreInvalidTransactionId(&(newtup->t_data->t_xmax));
newtup->t_data->t_infomask &= ~(HEAP_XACT_MASK); newtup->t_data->t_infomask &= ~(HEAP_XACT_MASK);
newtup->t_data->t_infomask |= (HEAP_XMAX_INVALID | HEAP_UPDATED); newtup->t_data->t_infomask |= (HEAP_XMAX_INVALID | HEAP_UPDATED);
...@@ -1496,7 +1509,7 @@ l2: ...@@ -1496,7 +1509,7 @@ l2:
TransactionIdStore(GetCurrentTransactionId(), TransactionIdStore(GetCurrentTransactionId(),
&(oldtup.t_data->t_xmax)); &(oldtup.t_data->t_xmax));
oldtup.t_data->t_cmax = GetCurrentCommandId(); oldtup.t_data->t_cmax = cid;
oldtup.t_data->t_infomask &= ~(HEAP_XMAX_COMMITTED | oldtup.t_data->t_infomask &= ~(HEAP_XMAX_COMMITTED |
HEAP_XMAX_INVALID | HEAP_XMAX_INVALID |
HEAP_MARKED_FOR_UPDATE); HEAP_MARKED_FOR_UPDATE);
...@@ -1588,7 +1601,7 @@ l2: ...@@ -1588,7 +1601,7 @@ l2:
{ {
TransactionIdStore(GetCurrentTransactionId(), TransactionIdStore(GetCurrentTransactionId(),
&(oldtup.t_data->t_xmax)); &(oldtup.t_data->t_xmax));
oldtup.t_data->t_cmax = GetCurrentCommandId(); oldtup.t_data->t_cmax = cid;
oldtup.t_data->t_infomask &= ~(HEAP_XMAX_COMMITTED | oldtup.t_data->t_infomask &= ~(HEAP_XMAX_COMMITTED |
HEAP_XMAX_INVALID | HEAP_XMAX_INVALID |
HEAP_MARKED_FOR_UPDATE); HEAP_MARKED_FOR_UPDATE);
...@@ -1653,7 +1666,7 @@ simple_heap_update(Relation relation, ItemPointer otid, HeapTuple tup) ...@@ -1653,7 +1666,7 @@ simple_heap_update(Relation relation, ItemPointer otid, HeapTuple tup)
ItemPointerData ctid; ItemPointerData ctid;
int result; int result;
result = heap_update(relation, otid, tup, &ctid); result = heap_update(relation, otid, tup, &ctid, GetCurrentCommandId());
switch (result) switch (result)
{ {
case HeapTupleSelfUpdated: case HeapTupleSelfUpdated:
...@@ -1679,7 +1692,8 @@ simple_heap_update(Relation relation, ItemPointer otid, HeapTuple tup) ...@@ -1679,7 +1692,8 @@ simple_heap_update(Relation relation, ItemPointer otid, HeapTuple tup)
* heap_mark4update - mark a tuple for update * heap_mark4update - mark a tuple for update
*/ */
int int
heap_mark4update(Relation relation, HeapTuple tuple, Buffer *buffer) heap_mark4update(Relation relation, HeapTuple tuple, Buffer *buffer,
CommandId cid)
{ {
ItemPointer tid = &(tuple->t_self); ItemPointer tid = &(tuple->t_self);
ItemId lp; ItemId lp;
...@@ -1704,7 +1718,7 @@ heap_mark4update(Relation relation, HeapTuple tuple, Buffer *buffer) ...@@ -1704,7 +1718,7 @@ heap_mark4update(Relation relation, HeapTuple tuple, Buffer *buffer)
tuple->t_len = ItemIdGetLength(lp); tuple->t_len = ItemIdGetLength(lp);
l3: l3:
result = HeapTupleSatisfiesUpdate(tuple); result = HeapTupleSatisfiesUpdate(tuple, cid);
if (result == HeapTupleInvisible) if (result == HeapTupleInvisible)
{ {
...@@ -1758,7 +1772,7 @@ l3: ...@@ -1758,7 +1772,7 @@ l3:
/* store transaction information of xact marking the tuple */ /* store transaction information of xact marking the tuple */
TransactionIdStore(GetCurrentTransactionId(), &(tuple->t_data->t_xmax)); TransactionIdStore(GetCurrentTransactionId(), &(tuple->t_data->t_xmax));
tuple->t_data->t_cmax = GetCurrentCommandId(); tuple->t_data->t_cmax = cid;
tuple->t_data->t_infomask &= ~(HEAP_XMAX_COMMITTED | HEAP_XMAX_INVALID); tuple->t_data->t_infomask &= ~(HEAP_XMAX_COMMITTED | HEAP_XMAX_INVALID);
tuple->t_data->t_infomask |= HEAP_MARKED_FOR_UPDATE; tuple->t_data->t_infomask |= HEAP_MARKED_FOR_UPDATE;
...@@ -2400,9 +2414,8 @@ _heap_unlock_tuple(void *data) ...@@ -2400,9 +2414,8 @@ _heap_unlock_tuple(void *data)
htup = (HeapTupleHeader) PageGetItem(page, lp); htup = (HeapTupleHeader) PageGetItem(page, lp);
if (!TransactionIdEquals(htup->t_xmax, GetCurrentTransactionId()) || if (!TransactionIdEquals(htup->t_xmax, GetCurrentTransactionId()))
htup->t_cmax != GetCurrentCommandId()) elog(PANIC, "_heap_unlock_tuple: invalid xmax in rollback");
elog(PANIC, "_heap_unlock_tuple: invalid xmax/cmax in rollback");
htup->t_infomask &= ~HEAP_XMAX_UNLOGGED; htup->t_infomask &= ~HEAP_XMAX_UNLOGGED;
htup->t_infomask |= HEAP_XMAX_INVALID; htup->t_infomask |= HEAP_XMAX_INVALID;
UnlockAndWriteBuffer(buffer); UnlockAndWriteBuffer(buffer);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/heap/tuptoaster.c,v 1.29 2002/05/20 23:51:41 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/access/heap/tuptoaster.c,v 1.30 2002/05/21 22:05:53 tgl Exp $
* *
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
...@@ -911,7 +911,7 @@ toast_save_datum(Relation rel, Datum value) ...@@ -911,7 +911,7 @@ toast_save_datum(Relation rel, Datum value)
if (!HeapTupleIsValid(toasttup)) if (!HeapTupleIsValid(toasttup))
elog(ERROR, "Failed to build TOAST tuple"); elog(ERROR, "Failed to build TOAST tuple");
heap_insert(toastrel, toasttup); simple_heap_insert(toastrel, toasttup);
/* /*
* Create the index entry. We cheat a little here by not using * Create the index entry. We cheat a little here by not using
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.122 2002/05/17 20:53:33 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.123 2002/05/21 22:05:53 tgl Exp $
* *
* NOTES * NOTES
* Transaction aborts can now occur two ways: * Transaction aborts can now occur two ways:
...@@ -350,14 +350,6 @@ GetCurrentCommandId(void) ...@@ -350,14 +350,6 @@ GetCurrentCommandId(void)
return s->commandId; return s->commandId;
} }
CommandId
GetScanCommandId(void)
{
TransactionState s = CurrentTransactionState;
return s->scanCommandId;
}
/* -------------------------------- /* --------------------------------
* GetCurrentTransactionStartTime * GetCurrentTransactionStartTime
...@@ -418,17 +410,6 @@ CommandIdIsCurrentCommandId(CommandId cid) ...@@ -418,17 +410,6 @@ CommandIdIsCurrentCommandId(CommandId cid)
return (cid == s->commandId) ? true : false; return (cid == s->commandId) ? true : false;
} }
bool
CommandIdGEScanCommandId(CommandId cid)
{
TransactionState s = CurrentTransactionState;
if (AMI_OVERRIDE)
return false;
return (cid >= s->scanCommandId) ? true : false;
}
/* -------------------------------- /* --------------------------------
* CommandCounterIncrement * CommandCounterIncrement
...@@ -437,11 +418,17 @@ CommandIdGEScanCommandId(CommandId cid) ...@@ -437,11 +418,17 @@ CommandIdGEScanCommandId(CommandId cid)
void void
CommandCounterIncrement(void) CommandCounterIncrement(void)
{ {
CurrentTransactionStateData.commandId += 1; TransactionState s = CurrentTransactionState;
if (CurrentTransactionStateData.commandId == FirstCommandId)
s->commandId += 1;
if (s->commandId == FirstCommandId) /* check for overflow */
elog(ERROR, "You may only have 2^32-1 commands per transaction"); elog(ERROR, "You may only have 2^32-1 commands per transaction");
CurrentTransactionStateData.scanCommandId = CurrentTransactionStateData.commandId; /* Propagate new command ID into query snapshots, if set */
if (QuerySnapshot)
QuerySnapshot->curcid = s->commandId;
if (SerializableSnapshot)
SerializableSnapshot->curcid = s->commandId;
/* /*
* make cache changes visible to me. AtCommit_LocalCache() instead of * make cache changes visible to me. AtCommit_LocalCache() instead of
...@@ -451,11 +438,6 @@ CommandCounterIncrement(void) ...@@ -451,11 +438,6 @@ CommandCounterIncrement(void)
AtStart_Cache(); AtStart_Cache();
} }
void
SetScanCommandId(CommandId savedId)
{
CurrentTransactionStateData.scanCommandId = savedId;
}
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------
* StartTransaction stuff * StartTransaction stuff
...@@ -889,10 +871,6 @@ StartTransaction(void) ...@@ -889,10 +871,6 @@ StartTransaction(void)
* initialize current transaction state fields * initialize current transaction state fields
*/ */
s->commandId = FirstCommandId; s->commandId = FirstCommandId;
s->scanCommandId = FirstCommandId;
#if NOT_USED
s->startTime = GetCurrentAbsoluteTime();
#endif
s->startTime = GetCurrentAbsoluteTimeUsec(&(s->startTimeUsec)); s->startTime = GetCurrentAbsoluteTimeUsec(&(s->startTimeUsec));
/* /*
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.130 2002/05/20 23:51:41 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.131 2002/05/21 22:05:53 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -680,7 +680,7 @@ InsertOneTuple(Oid objectid) ...@@ -680,7 +680,7 @@ InsertOneTuple(Oid objectid)
if (objectid != (Oid) 0) if (objectid != (Oid) 0)
tuple->t_data->t_oid = objectid; tuple->t_data->t_oid = objectid;
heap_insert(boot_reldesc, tuple); simple_heap_insert(boot_reldesc, tuple);
heap_freetuple(tuple); heap_freetuple(tuple);
elog(DEBUG3, "row inserted"); elog(DEBUG3, "row inserted");
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.200 2002/05/20 23:51:41 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.201 2002/05/21 22:05:53 tgl Exp $
* *
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
...@@ -440,7 +440,7 @@ AddNewAttributeTuples(Oid new_rel_oid, ...@@ -440,7 +440,7 @@ AddNewAttributeTuples(Oid new_rel_oid,
ATTRIBUTE_TUPLE_SIZE, ATTRIBUTE_TUPLE_SIZE,
(void *) *dpp); (void *) *dpp);
heap_insert(rel, tup); simple_heap_insert(rel, tup);
if (hasindex) if (hasindex)
CatalogIndexInsert(idescs, Num_pg_attr_indices, rel, tup); CatalogIndexInsert(idescs, Num_pg_attr_indices, rel, tup);
...@@ -474,7 +474,7 @@ AddNewAttributeTuples(Oid new_rel_oid, ...@@ -474,7 +474,7 @@ AddNewAttributeTuples(Oid new_rel_oid,
/* attStruct->attstattarget = 0; */ /* attStruct->attstattarget = 0; */
/* attStruct->attcacheoff = -1; */ /* attStruct->attcacheoff = -1; */
heap_insert(rel, tup); simple_heap_insert(rel, tup);
if (hasindex) if (hasindex)
CatalogIndexInsert(idescs, Num_pg_attr_indices, rel, tup); CatalogIndexInsert(idescs, Num_pg_attr_indices, rel, tup);
...@@ -574,7 +574,7 @@ AddNewRelationTuple(Relation pg_class_desc, ...@@ -574,7 +574,7 @@ AddNewRelationTuple(Relation pg_class_desc,
/* /*
* finally insert the new tuple and free it. * finally insert the new tuple and free it.
*/ */
heap_insert(pg_class_desc, tup); simple_heap_insert(pg_class_desc, tup);
if (!IsIgnoringSystemIndexes()) if (!IsIgnoringSystemIndexes())
{ {
...@@ -1308,7 +1308,7 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin) ...@@ -1308,7 +1308,7 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin)
CStringGetDatum(adsrc)); CStringGetDatum(adsrc));
adrel = heap_openr(AttrDefaultRelationName, RowExclusiveLock); adrel = heap_openr(AttrDefaultRelationName, RowExclusiveLock);
tuple = heap_formtuple(adrel->rd_att, values, nulls); tuple = heap_formtuple(adrel->rd_att, values, nulls);
heap_insert(adrel, tuple); simple_heap_insert(adrel, tuple);
CatalogOpenIndices(Num_pg_attrdef_indices, Name_pg_attrdef_indices, CatalogOpenIndices(Num_pg_attrdef_indices, Name_pg_attrdef_indices,
idescs); idescs);
CatalogIndexInsert(idescs, Num_pg_attrdef_indices, adrel, tuple); CatalogIndexInsert(idescs, Num_pg_attrdef_indices, adrel, tuple);
...@@ -1388,7 +1388,7 @@ StoreRelCheck(Relation rel, char *ccname, char *ccbin) ...@@ -1388,7 +1388,7 @@ StoreRelCheck(Relation rel, char *ccname, char *ccbin)
CStringGetDatum(ccsrc)); CStringGetDatum(ccsrc));
rcrel = heap_openr(RelCheckRelationName, RowExclusiveLock); rcrel = heap_openr(RelCheckRelationName, RowExclusiveLock);
tuple = heap_formtuple(rcrel->rd_att, values, nulls); tuple = heap_formtuple(rcrel->rd_att, values, nulls);
heap_insert(rcrel, tuple); simple_heap_insert(rcrel, tuple);
CatalogOpenIndices(Num_pg_relcheck_indices, Name_pg_relcheck_indices, CatalogOpenIndices(Num_pg_relcheck_indices, Name_pg_relcheck_indices,
idescs); idescs);
CatalogIndexInsert(idescs, Num_pg_relcheck_indices, rcrel, tuple); CatalogIndexInsert(idescs, Num_pg_relcheck_indices, rcrel, tuple);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.178 2002/05/20 23:51:41 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.179 2002/05/21 22:05:53 tgl Exp $
* *
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
...@@ -327,7 +327,7 @@ UpdateRelationRelation(Relation indexRelation) ...@@ -327,7 +327,7 @@ UpdateRelationRelation(Relation indexRelation)
* sure would be embarrassing to do this sort of thing in polite company. * sure would be embarrassing to do this sort of thing in polite company.
*/ */
tuple->t_data->t_oid = RelationGetRelid(indexRelation); tuple->t_data->t_oid = RelationGetRelid(indexRelation);
heap_insert(pg_class, tuple); simple_heap_insert(pg_class, tuple);
/* /*
* During normal processing, we need to make sure that the system * During normal processing, we need to make sure that the system
...@@ -408,7 +408,7 @@ AppendAttributeTuples(Relation indexRelation, int numatts) ...@@ -408,7 +408,7 @@ AppendAttributeTuples(Relation indexRelation, int numatts)
ATTRIBUTE_TUPLE_SIZE, ATTRIBUTE_TUPLE_SIZE,
(void *) indexTupDesc->attrs[i]); (void *) indexTupDesc->attrs[i]);
heap_insert(pg_attribute, new_tuple); simple_heap_insert(pg_attribute, new_tuple);
if (hasind) if (hasind)
CatalogIndexInsert(idescs, Num_pg_attr_indices, pg_attribute, new_tuple); CatalogIndexInsert(idescs, Num_pg_attr_indices, pg_attribute, new_tuple);
...@@ -500,7 +500,7 @@ UpdateIndexRelation(Oid indexoid, ...@@ -500,7 +500,7 @@ UpdateIndexRelation(Oid indexoid,
/* /*
* insert the tuple into the pg_index * insert the tuple into the pg_index
*/ */
heap_insert(pg_index, tuple); simple_heap_insert(pg_index, tuple);
/* /*
* add index tuples for it * add index tuples for it
...@@ -1010,7 +1010,8 @@ LockClassinfoForUpdate(Oid relid, HeapTuple rtup, ...@@ -1010,7 +1010,8 @@ LockClassinfoForUpdate(Oid relid, HeapTuple rtup,
ItemPointerData tidsave; ItemPointerData tidsave;
ItemPointerCopy(&(rtup->t_self), &tidsave); ItemPointerCopy(&(rtup->t_self), &tidsave);
test = heap_mark4update(relationRelation, rtup, buffer); test = heap_mark4update(relationRelation, rtup, buffer,
GetCurrentCommandId());
switch (test) switch (test)
{ {
case HeapTupleSelfUpdated: case HeapTupleSelfUpdated:
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_aggregate.c,v 1.46 2002/05/18 13:47:59 petere Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_aggregate.c,v 1.47 2002/05/21 22:05:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -174,7 +174,7 @@ AggregateCreate(const char *aggName, ...@@ -174,7 +174,7 @@ AggregateCreate(const char *aggName,
tupDesc = aggdesc->rd_att; tupDesc = aggdesc->rd_att;
tup = heap_formtuple(tupDesc, values, nulls); tup = heap_formtuple(tupDesc, values, nulls);
heap_insert(aggdesc, tup); simple_heap_insert(aggdesc, tup);
if (RelationGetForm(aggdesc)->relhasindex) if (RelationGetForm(aggdesc)->relhasindex)
{ {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_largeobject.c,v 1.11 2002/05/20 23:51:42 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_largeobject.c,v 1.12 2002/05/21 22:05:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -63,7 +63,7 @@ LargeObjectCreate(Oid loid) ...@@ -63,7 +63,7 @@ LargeObjectCreate(Oid loid)
/* /*
* Insert it * Insert it
*/ */
heap_insert(pg_largeobject, ntup); simple_heap_insert(pg_largeobject, ntup);
/* /*
* Update indices * Update indices
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_namespace.c,v 1.2 2002/03/31 06:26:30 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_namespace.c,v 1.3 2002/05/21 22:05:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -61,13 +61,10 @@ NamespaceCreate(const char *nspName, int32 ownerSysId) ...@@ -61,13 +61,10 @@ NamespaceCreate(const char *nspName, int32 ownerSysId)
nspdesc = heap_openr(NamespaceRelationName, RowExclusiveLock); nspdesc = heap_openr(NamespaceRelationName, RowExclusiveLock);
tupDesc = nspdesc->rd_att; tupDesc = nspdesc->rd_att;
if (!HeapTupleIsValid(tup = heap_formtuple(tupDesc,
values, tup = heap_formtuple(tupDesc, values, nulls);
nulls))) nspoid = simple_heap_insert(nspdesc, tup);
elog(ERROR, "NamespaceCreate: heap_formtuple failed"); Assert(OidIsValid(nspoid));
nspoid = heap_insert(nspdesc, tup);
if (!OidIsValid(nspoid))
elog(ERROR, "NamespaceCreate: heap_insert failed");
if (RelationGetForm(nspdesc)->relhasindex) if (RelationGetForm(nspdesc)->relhasindex)
{ {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_operator.c,v 1.68 2002/04/27 03:45:00 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_operator.c,v 1.69 2002/05/21 22:05:54 tgl Exp $
* *
* NOTES * NOTES
* these routines moved here from commands/define.c and somewhat cleaned up. * these routines moved here from commands/define.c and somewhat cleaned up.
...@@ -260,8 +260,7 @@ OperatorShellMake(const char *operatorName, ...@@ -260,8 +260,7 @@ OperatorShellMake(const char *operatorName,
/* /*
* insert our "shell" operator tuple * insert our "shell" operator tuple
*/ */
heap_insert(pg_operator_desc, tup); operatorObjectId = simple_heap_insert(pg_operator_desc, tup);
operatorObjectId = tup->t_data->t_oid;
if (RelationGetForm(pg_operator_desc)->relhasindex) if (RelationGetForm(pg_operator_desc)->relhasindex)
{ {
...@@ -360,7 +359,7 @@ OperatorShellMake(const char *operatorName, ...@@ -360,7 +359,7 @@ OperatorShellMake(const char *operatorName,
* get the t_self from the modified tuple and call RelationReplaceHeapTuple * get the t_self from the modified tuple and call RelationReplaceHeapTuple
* else if a new operator is being created * else if a new operator is being created
* create a tuple using heap_formtuple * create a tuple using heap_formtuple
* call heap_insert * call simple_heap_insert
*/ */
void void
OperatorCreate(const char *operatorName, OperatorCreate(const char *operatorName,
...@@ -647,8 +646,7 @@ OperatorCreate(const char *operatorName, ...@@ -647,8 +646,7 @@ OperatorCreate(const char *operatorName,
tupDesc = pg_operator_desc->rd_att; tupDesc = pg_operator_desc->rd_att;
tup = heap_formtuple(tupDesc, values, nulls); tup = heap_formtuple(tupDesc, values, nulls);
heap_insert(pg_operator_desc, tup); operatorObjectId = simple_heap_insert(pg_operator_desc, tup);
operatorObjectId = tup->t_data->t_oid;
} }
/* Must update the indexes in either case */ /* Must update the indexes in either case */
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.72 2002/05/18 13:47:59 petere Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.73 2002/05/21 22:05:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -298,7 +298,7 @@ ProcedureCreate(const char *procedureName, ...@@ -298,7 +298,7 @@ ProcedureCreate(const char *procedureName,
nulls[Anum_pg_proc_proacl-1] = 'n'; nulls[Anum_pg_proc_proacl-1] = 'n';
tup = heap_formtuple(tupDesc, values, nulls); tup = heap_formtuple(tupDesc, values, nulls);
heap_insert(rel, tup); simple_heap_insert(rel, tup);
} }
/* Need to update indices for either the insert or update case */ /* Need to update indices for either the insert or update case */
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.70 2002/03/29 19:06:02 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.71 2002/05/21 22:05:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -102,8 +102,7 @@ TypeShellMake(const char *typeName, Oid typeNamespace) ...@@ -102,8 +102,7 @@ TypeShellMake(const char *typeName, Oid typeNamespace)
/* /*
* insert the tuple in the relation and get the tuple's oid. * insert the tuple in the relation and get the tuple's oid.
*/ */
heap_insert(pg_type_desc, tup); typoid = simple_heap_insert(pg_type_desc, tup);
typoid = tup->t_data->t_oid;
if (RelationGetForm(pg_type_desc)->relhasindex) if (RelationGetForm(pg_type_desc)->relhasindex)
{ {
...@@ -286,9 +285,7 @@ TypeCreate(const char *typeName, ...@@ -286,9 +285,7 @@ TypeCreate(const char *typeName,
/* preassign tuple Oid, if one was given */ /* preassign tuple Oid, if one was given */
tup->t_data->t_oid = assignedTypeOid; tup->t_data->t_oid = assignedTypeOid;
heap_insert(pg_type_desc, tup); typeObjectId = simple_heap_insert(pg_type_desc, tup);
typeObjectId = tup->t_data->t_oid;
} }
/* Update indices (not necessary if bootstrapping) */ /* Update indices (not necessary if bootstrapping) */
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.33 2002/05/20 23:51:42 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.34 2002/05/21 22:05:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1787,7 +1787,7 @@ update_attstats(Oid relid, int natts, VacAttrStats **vacattrstats) ...@@ -1787,7 +1787,7 @@ update_attstats(Oid relid, int natts, VacAttrStats **vacattrstats)
{ {
/* No, insert new tuple */ /* No, insert new tuple */
stup = heap_formtuple(sd->rd_att, values, nulls); stup = heap_formtuple(sd->rd_att, values, nulls);
heap_insert(sd, stup); simple_heap_insert(sd, stup);
} }
/* update indices too */ /* update indices too */
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.85 2002/05/20 23:51:42 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.86 2002/05/21 22:05:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -242,7 +242,7 @@ Async_Listen(char *relname, int pid) ...@@ -242,7 +242,7 @@ Async_Listen(char *relname, int pid)
values[i++] = (Datum) 0; /* no notifies pending */ values[i++] = (Datum) 0; /* no notifies pending */
tuple = heap_formtuple(RelationGetDescr(lRel), values, nulls); tuple = heap_formtuple(RelationGetDescr(lRel), values, nulls);
heap_insert(lRel, tuple); simple_heap_insert(lRel, tuple);
#ifdef NOT_USED /* currently there are no indexes */ #ifdef NOT_USED /* currently there are no indexes */
if (RelationGetForm(lRel)->relhasindex) if (RelationGetForm(lRel)->relhasindex)
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.80 2002/05/20 23:51:42 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.81 2002/05/21 22:05:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -241,7 +241,7 @@ rebuildheap(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex) ...@@ -241,7 +241,7 @@ rebuildheap(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex)
*/ */
HeapTuple copiedTuple = heap_copytuple(LocalHeapTuple); HeapTuple copiedTuple = heap_copytuple(LocalHeapTuple);
heap_insert(LocalNewHeap, copiedTuple); simple_heap_insert(LocalNewHeap, copiedTuple);
heap_freetuple(copiedTuple); heap_freetuple(copiedTuple);
CHECK_FOR_INTERRUPTS(); CHECK_FOR_INTERRUPTS();
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Copyright (c) 1999-2001, PostgreSQL Global Development Group * Copyright (c) 1999-2001, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.47 2002/05/20 23:51:42 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.48 2002/05/21 22:05:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -199,7 +199,7 @@ CreateComments(Oid oid, Oid classoid, int32 subid, char *comment) ...@@ -199,7 +199,7 @@ CreateComments(Oid oid, Oid classoid, int32 subid, char *comment)
{ {
newtuple = heap_formtuple(RelationGetDescr(description), newtuple = heap_formtuple(RelationGetDescr(description),
values, nulls); values, nulls);
heap_insert(description, newtuple); simple_heap_insert(description, newtuple);
} }
/* Update indexes, if necessary */ /* Update indexes, if necessary */
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.154 2002/05/20 23:51:42 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.155 2002/05/21 22:05:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -947,7 +947,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, ...@@ -947,7 +947,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp,
/* /*
* OK, store the tuple and create index entries for it * OK, store the tuple and create index entries for it
*/ */
heap_insert(rel, tuple); simple_heap_insert(rel, tuple);
if (resultRelInfo->ri_NumIndices > 0) if (resultRelInfo->ri_NumIndices > 0)
ExecInsertIndexTuples(slot, &(tuple->t_self), estate, false); ExecInsertIndexTuples(slot, &(tuple->t_self), estate, false);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.90 2002/05/20 23:51:42 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.91 2002/05/21 22:05:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -293,7 +293,7 @@ createdb(const char *dbname, const char *dbowner, ...@@ -293,7 +293,7 @@ createdb(const char *dbname, const char *dbowner,
tuple->t_data->t_oid = dboid; /* override heap_insert's OID tuple->t_data->t_oid = dboid; /* override heap_insert's OID
* selection */ * selection */
heap_insert(pg_database_rel, tuple); simple_heap_insert(pg_database_rel, tuple);
/* /*
* Update indexes * Update indexes
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/portalcmds.c,v 1.1 2002/04/15 05:22:03 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/portalcmds.c,v 1.2 2002/05/21 22:05:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -74,7 +74,6 @@ PerformPortalFetch(char *name, ...@@ -74,7 +74,6 @@ PerformPortalFetch(char *name,
EState *estate; EState *estate;
MemoryContext oldcontext; MemoryContext oldcontext;
ScanDirection direction; ScanDirection direction;
CommandId savedId;
bool temp_desc = false; bool temp_desc = false;
/* initialize completion status in case of early exit */ /* initialize completion status in case of early exit */
...@@ -131,14 +130,6 @@ PerformPortalFetch(char *name, ...@@ -131,14 +130,6 @@ PerformPortalFetch(char *name,
temp_desc = true; temp_desc = true;
} }
/*
* 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));
/* /*
* Determine which direction to go in, and check to see if we're * Determine which direction to go in, and check to see if we're
* already at the end of the available tuples in that direction. If * already at the end of the available tuples in that direction. If
...@@ -185,11 +176,6 @@ PerformPortalFetch(char *name, ...@@ -185,11 +176,6 @@ PerformPortalFetch(char *name,
(dest == None) ? "MOVE" : "FETCH", (dest == None) ? "MOVE" : "FETCH",
estate->es_processed); estate->es_processed);
/*
* Restore outer command ID.
*/
SetScanCommandId(savedId);
/* /*
* Clean up and switch back to old context. * Clean up and switch back to old context.
*/ */
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/proclang.c,v 1.31 2002/04/15 05:22:03 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/proclang.c,v 1.32 2002/05/21 22:05:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -102,7 +102,7 @@ CreateProceduralLanguage(CreatePLangStmt *stmt) ...@@ -102,7 +102,7 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
tupDesc = rel->rd_att; tupDesc = rel->rd_att;
tup = heap_formtuple(tupDesc, values, nulls); tup = heap_formtuple(tupDesc, values, nulls);
heap_insert(rel, tup); simple_heap_insert(rel, tup);
if (RelationGetForm(rel)->relhasindex) if (RelationGetForm(rel)->relhasindex)
{ {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.77 2002/04/15 05:22:03 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.78 2002/05/21 22:05:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -197,7 +197,7 @@ DefineSequence(CreateSeqStmt *seq) ...@@ -197,7 +197,7 @@ DefineSequence(CreateSeqStmt *seq)
/* Now form & insert sequence tuple */ /* Now form & insert sequence tuple */
tuple = heap_formtuple(tupDesc, value, null); tuple = heap_formtuple(tupDesc, value, null);
heap_insert(rel, tuple); simple_heap_insert(rel, tuple);
Assert(ItemPointerGetOffsetNumber(&(tuple->t_self)) == FirstOffsetNumber); Assert(ItemPointerGetOffsetNumber(&(tuple->t_self)) == FirstOffsetNumber);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.15 2002/05/20 23:51:42 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.16 2002/05/21 22:05:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -821,7 +821,7 @@ StoreCatalogInheritance(Oid relationId, List *supers) ...@@ -821,7 +821,7 @@ StoreCatalogInheritance(Oid relationId, List *supers)
tuple = heap_formtuple(desc, datum, nullarr); tuple = heap_formtuple(desc, datum, nullarr);
heap_insert(relation, tuple); simple_heap_insert(relation, tuple);
if (RelationGetForm(relation)->relhasindex) if (RelationGetForm(relation)->relhasindex)
{ {
...@@ -1673,7 +1673,7 @@ AlterTableAddColumn(Oid myrelid, ...@@ -1673,7 +1673,7 @@ AlterTableAddColumn(Oid myrelid,
ReleaseSysCache(typeTuple); ReleaseSysCache(typeTuple);
heap_insert(attrdesc, attributeTuple); simple_heap_insert(attrdesc, attributeTuple);
/* Update indexes on pg_attribute */ /* Update indexes on pg_attribute */
if (RelationGetForm(attrdesc)->relhasindex) if (RelationGetForm(attrdesc)->relhasindex)
...@@ -2890,7 +2890,8 @@ AlterTableCreateToastTable(Oid relOid, bool silent) ...@@ -2890,7 +2890,8 @@ AlterTableCreateToastTable(Oid relOid, bool silent)
classtuple.t_self = reltup->t_self; classtuple.t_self = reltup->t_self;
ReleaseSysCache(reltup); ReleaseSysCache(reltup);
switch (heap_mark4update(class_rel, &classtuple, &buffer)) switch (heap_mark4update(class_rel, &classtuple, &buffer,
GetCurrentCommandId()))
{ {
case HeapTupleSelfUpdated: case HeapTupleSelfUpdated:
case HeapTupleMayBeUpdated: case HeapTupleMayBeUpdated:
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.117 2002/04/30 01:24:57 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.118 2002/05/21 22:05:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -270,7 +270,7 @@ CreateTrigger(CreateTrigStmt *stmt) ...@@ -270,7 +270,7 @@ CreateTrigger(CreateTrigStmt *stmt)
/* /*
* Insert tuple into pg_trigger. * Insert tuple into pg_trigger.
*/ */
heap_insert(tgrel, tuple); simple_heap_insert(tgrel, tuple);
CatalogOpenIndices(Num_pg_trigger_indices, Name_pg_trigger_indices, idescs); CatalogOpenIndices(Num_pg_trigger_indices, Name_pg_trigger_indices, idescs);
CatalogIndexInsert(idescs, Num_pg_trigger_indices, tgrel, tuple); CatalogIndexInsert(idescs, Num_pg_trigger_indices, tgrel, tuple);
CatalogCloseIndices(Num_pg_trigger_indices, idescs); CatalogCloseIndices(Num_pg_trigger_indices, idescs);
...@@ -1183,7 +1183,8 @@ GetTupleForTrigger(EState *estate, ResultRelInfo *relinfo, ...@@ -1183,7 +1183,8 @@ GetTupleForTrigger(EState *estate, ResultRelInfo *relinfo,
*newSlot = NULL; *newSlot = NULL;
tuple.t_self = *tid; tuple.t_self = *tid;
ltrmark:; ltrmark:;
test = heap_mark4update(relation, &tuple, &buffer); test = heap_mark4update(relation, &tuple, &buffer,
GetCurrentCommandId());
switch (test) switch (test)
{ {
case HeapTupleSelfUpdated: case HeapTupleSelfUpdated:
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.102 2002/05/20 23:51:42 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.103 2002/05/21 22:05:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -596,7 +596,7 @@ CreateUser(CreateUserStmt *stmt) ...@@ -596,7 +596,7 @@ CreateUser(CreateUserStmt *stmt)
/* /*
* Insert new record in the pg_shadow table * Insert new record in the pg_shadow table
*/ */
heap_insert(pg_shadow_rel, tuple); simple_heap_insert(pg_shadow_rel, tuple);
/* /*
* Update indexes * Update indexes
...@@ -1213,9 +1213,9 @@ CreateGroup(CreateGroupStmt *stmt) ...@@ -1213,9 +1213,9 @@ CreateGroup(CreateGroupStmt *stmt)
tuple = heap_formtuple(pg_group_dsc, new_record, new_record_nulls); tuple = heap_formtuple(pg_group_dsc, new_record, new_record_nulls);
/* /*
* Insert a new record in the pg_group_table * Insert a new record in the pg_group table
*/ */
heap_insert(pg_group_rel, tuple); simple_heap_insert(pg_group_rel, tuple);
/* /*
* Update indexes * Update indexes
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
* *
* *
* IDENTIFICATION * 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 ...@@ -101,6 +101,7 @@ TupleDesc
ExecutorStart(QueryDesc *queryDesc, EState *estate) ExecutorStart(QueryDesc *queryDesc, EState *estate)
{ {
TupleDesc result; TupleDesc result;
Snapshot es_snapshot;
/* sanity checks */ /* sanity checks */
Assert(queryDesc != NULL); Assert(queryDesc != NULL);
...@@ -114,22 +115,28 @@ ExecutorStart(QueryDesc *queryDesc, EState *estate) ...@@ -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) if (QuerySnapshot == NULL) /* should be set already, but... */
estate->es_snapshot = NULL; SetQuerySnapshot();
else
{ es_snapshot = (Snapshot) palloc(sizeof(SnapshotData));
estate->es_snapshot = (Snapshot) palloc(sizeof(SnapshotData)); memcpy(es_snapshot, QuerySnapshot, sizeof(SnapshotData));
memcpy(estate->es_snapshot, QuerySnapshot, sizeof(SnapshotData)); if (es_snapshot->xcnt > 0)
if (estate->es_snapshot->xcnt > 0)
{ {
estate->es_snapshot->xip = (TransactionId *) es_snapshot->xip = (TransactionId *)
palloc(estate->es_snapshot->xcnt * sizeof(TransactionId)); palloc(es_snapshot->xcnt * sizeof(TransactionId));
memcpy(estate->es_snapshot->xip, QuerySnapshot->xip, memcpy(es_snapshot->xip, QuerySnapshot->xip,
estate->es_snapshot->xcnt * sizeof(TransactionId)); es_snapshot->xcnt * sizeof(TransactionId));
}
} }
else
es_snapshot->xip = NULL;
estate->es_snapshot = es_snapshot;
/* /*
* Initialize the plan * Initialize the plan
...@@ -1031,7 +1038,8 @@ lnext: ; ...@@ -1031,7 +1038,8 @@ lnext: ;
erm->resname); erm->resname);
tuple.t_self = *((ItemPointer) DatumGetPointer(datum)); 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); ReleaseBuffer(buffer);
switch (test) switch (test)
{ {
...@@ -1163,7 +1171,8 @@ ExecRetrieve(TupleTableSlot *slot, ...@@ -1163,7 +1171,8 @@ ExecRetrieve(TupleTableSlot *slot,
*/ */
if (estate->es_into_relation_descriptor != NULL) 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(); IncrAppended();
} }
...@@ -1239,7 +1248,8 @@ ExecAppend(TupleTableSlot *slot, ...@@ -1239,7 +1248,8 @@ ExecAppend(TupleTableSlot *slot,
/* /*
* insert the tuple * insert the tuple
*/ */
newId = heap_insert(resultRelationDesc, tuple); newId = heap_insert(resultRelationDesc, tuple,
estate->es_snapshot->curcid);
IncrAppended(); IncrAppended();
(estate->es_processed)++; (estate->es_processed)++;
...@@ -1301,7 +1311,9 @@ ExecDelete(TupleTableSlot *slot, ...@@ -1301,7 +1311,9 @@ ExecDelete(TupleTableSlot *slot,
* delete the tuple * delete the tuple
*/ */
ldelete:; ldelete:;
result = heap_delete(resultRelationDesc, tupleid, &ctid); result = heap_delete(resultRelationDesc, tupleid,
&ctid,
estate->es_snapshot->curcid);
switch (result) switch (result)
{ {
case HeapTupleSelfUpdated: case HeapTupleSelfUpdated:
...@@ -1433,7 +1445,9 @@ lreplace:; ...@@ -1433,7 +1445,9 @@ lreplace:;
/* /*
* replace the heap tuple * replace the heap tuple
*/ */
result = heap_update(resultRelationDesc, tupleid, tuple, &ctid); result = heap_update(resultRelationDesc, tupleid, tuple,
&ctid,
estate->es_snapshot->curcid);
switch (result) switch (result)
{ {
case HeapTupleSelfUpdated: case HeapTupleSelfUpdated:
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -465,7 +465,6 @@ fmgr_sql(PG_FUNCTION_ARGS)
SQLFunctionCachePtr fcache; SQLFunctionCachePtr fcache;
execution_state *es; execution_state *es;
Datum result = 0; Datum result = 0;
CommandId savedId;
/* /*
* Switch to context in which the fcache lives. This ensures that * Switch to context in which the fcache lives. This ensures that
...@@ -474,14 +473,6 @@ fmgr_sql(PG_FUNCTION_ARGS) ...@@ -474,14 +473,6 @@ fmgr_sql(PG_FUNCTION_ARGS)
*/ */
oldcontext = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt); 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. * Initialize fcache and execution state if first time through.
*/ */
...@@ -515,11 +506,6 @@ fmgr_sql(PG_FUNCTION_ARGS) ...@@ -515,11 +506,6 @@ fmgr_sql(PG_FUNCTION_ARGS)
es = es->next; es = es->next;
} }
/*
* Restore outer command ID.
*/
SetScanCommandId(savedId);
/* /*
* If we've gone through every command in this function, we are done. * If we've gone through every command in this function, we are done.
*/ */
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -106,11 +106,7 @@ SPI_connect(void)
/* ... and switch to procedure's context */ /* ... and switch to procedure's context */
_SPI_current->savedcxt = MemoryContextSwitchTo(_SPI_current->procCxt); _SPI_current->savedcxt = MemoryContextSwitchTo(_SPI_current->procCxt);
_SPI_current->savedId = GetScanCommandId();
SetScanCommandId(GetCurrentCommandId());
return SPI_OK_CONNECT; return SPI_OK_CONNECT;
} }
int int
...@@ -129,8 +125,6 @@ SPI_finish(void) ...@@ -129,8 +125,6 @@ SPI_finish(void)
MemoryContextDelete(_SPI_current->execCxt); MemoryContextDelete(_SPI_current->execCxt);
MemoryContextDelete(_SPI_current->procCxt); MemoryContextDelete(_SPI_current->procCxt);
SetScanCommandId(_SPI_current->savedId);
/* /*
* After _SPI_begin_call _SPI_connected == _SPI_curid. Now we are * After _SPI_begin_call _SPI_connected == _SPI_curid. Now we are
* closing connection to SPI and returning to upper Executor and so * closing connection to SPI and returning to upper Executor and so
...@@ -1233,7 +1227,6 @@ _SPI_cursor_operation(Portal portal, bool forward, int count, ...@@ -1233,7 +1227,6 @@ _SPI_cursor_operation(Portal portal, bool forward, int count,
EState *estate; EState *estate;
MemoryContext oldcontext; MemoryContext oldcontext;
ScanDirection direction; ScanDirection direction;
CommandId savedId;
CommandDest olddest; CommandDest olddest;
/* Check that the portal is valid */ /* Check that the portal is valid */
...@@ -1260,14 +1253,6 @@ _SPI_cursor_operation(Portal portal, bool forward, int count, ...@@ -1260,14 +1253,6 @@ _SPI_cursor_operation(Portal portal, bool forward, int count,
olddest = querydesc->dest; olddest = querydesc->dest;
querydesc->dest = 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 */ /* Run the executor like PerformPortalFetch and remember states */
if (forward) if (forward)
{ {
...@@ -1300,11 +1285,6 @@ _SPI_cursor_operation(Portal portal, bool forward, int count, ...@@ -1300,11 +1285,6 @@ _SPI_cursor_operation(Portal portal, bool forward, int count,
_SPI_current->processed = estate->es_processed; _SPI_current->processed = estate->es_processed;
/*
* Restore outer command ID.
*/
SetScanCommandId(savedId);
/* Restore the old command destination and switch back to callers */ /* Restore the old command destination and switch back to callers */
/* memory context */ /* memory context */
querydesc->dest = olddest; querydesc->dest = olddest;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.71 2002/05/20 23:51:43 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.72 2002/05/21 22:05:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -88,9 +88,7 @@ InsertRule(char *rulname, ...@@ -88,9 +88,7 @@ InsertRule(char *rulname,
values, values,
nulls); nulls);
heap_insert(pg_rewrite_desc, tup); rewriteObjectId = simple_heap_insert(pg_rewrite_desc, tup);
rewriteObjectId = tup->t_data->t_oid;
if (RelationGetForm(pg_rewrite_desc)->relhasindex) if (RelationGetForm(pg_rewrite_desc)->relhasindex)
{ {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.45 2002/03/02 23:35:57 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.46 2002/05/21 22:05:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -397,6 +397,9 @@ GetSnapshotData(bool serializable) ...@@ -397,6 +397,9 @@ GetSnapshotData(bool serializable)
Assert(TransactionIdIsValid(MyProc->xmin)); Assert(TransactionIdIsValid(MyProc->xmin));
snapshot->xcnt = count; snapshot->xcnt = count;
snapshot->curcid = GetCurrentCommandId();
return snapshot; return snapshot;
} }
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.91 2002/05/20 23:51:43 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.92 2002/05/21 22:05:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -555,7 +555,7 @@ inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes) ...@@ -555,7 +555,7 @@ inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes)
values[Anum_pg_largeobject_pageno - 1] = Int32GetDatum(pageno); values[Anum_pg_largeobject_pageno - 1] = Int32GetDatum(pageno);
values[Anum_pg_largeobject_data - 1] = PointerGetDatum(&workbuf); values[Anum_pg_largeobject_data - 1] = PointerGetDatum(&workbuf);
newtup = heap_formtuple(obj_desc->heap_r->rd_att, values, nulls); newtup = heap_formtuple(obj_desc->heap_r->rd_att, values, nulls);
heap_insert(obj_desc->heap_r, newtup); simple_heap_insert(obj_desc->heap_r, newtup);
if (write_indices) if (write_indices)
CatalogIndexInsert(idescs, Num_pg_largeobject_indices, CatalogIndexInsert(idescs, Num_pg_largeobject_indices,
obj_desc->heap_r, newtup); obj_desc->heap_r, newtup);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mmgr/portalmem.c,v 1.47 2002/03/06 06:10:29 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/portalmem.c,v 1.48 2002/05/21 22:05:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -168,7 +168,6 @@ PortalSetQuery(Portal portal, ...@@ -168,7 +168,6 @@ PortalSetQuery(Portal portal,
portal->queryDesc = queryDesc; portal->queryDesc = queryDesc;
portal->attinfo = attinfo; portal->attinfo = attinfo;
portal->commandId = GetScanCommandId();
portal->state = state; portal->state = state;
portal->atStart = true; /* Allow fetch forward only */ portal->atStart = true; /* Allow fetch forward only */
portal->atEnd = false; portal->atEnd = false;
...@@ -214,7 +213,6 @@ CreatePortal(char *name) ...@@ -214,7 +213,6 @@ CreatePortal(char *name)
/* initialize portal query */ /* initialize portal query */
portal->queryDesc = NULL; portal->queryDesc = NULL;
portal->attinfo = NULL; portal->attinfo = NULL;
portal->commandId = 0;
portal->state = NULL; portal->state = NULL;
portal->atStart = true; /* disallow fetches until query is set */ portal->atStart = true; /* disallow fetches until query is set */
portal->atEnd = true; portal->atEnd = true;
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.50 2002/05/06 02:39:01 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.51 2002/05/21 22:05:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -238,7 +238,7 @@ HeapTupleSatisfiesNow(HeapTupleHeader tuple) ...@@ -238,7 +238,7 @@ HeapTupleSatisfiesNow(HeapTupleHeader tuple)
} }
else if (TransactionIdIsCurrentTransactionId(tuple->t_xmin)) else if (TransactionIdIsCurrentTransactionId(tuple->t_xmin))
{ {
if (CommandIdGEScanCommandId(tuple->t_cmin)) if (tuple->t_cmin >= GetCurrentCommandId())
return false; /* inserted after scan started */ return false; /* inserted after scan started */
if (tuple->t_infomask & HEAP_XMAX_INVALID) /* xid invalid */ if (tuple->t_infomask & HEAP_XMAX_INVALID) /* xid invalid */
...@@ -249,7 +249,7 @@ HeapTupleSatisfiesNow(HeapTupleHeader tuple) ...@@ -249,7 +249,7 @@ HeapTupleSatisfiesNow(HeapTupleHeader tuple)
if (tuple->t_infomask & HEAP_MARKED_FOR_UPDATE) if (tuple->t_infomask & HEAP_MARKED_FOR_UPDATE)
return true; return true;
if (CommandIdGEScanCommandId(tuple->t_cmax)) if (tuple->t_cmax >= GetCurrentCommandId())
return true; /* deleted after scan started */ return true; /* deleted after scan started */
else else
return false; /* deleted before scan started */ return false; /* deleted before scan started */
...@@ -280,7 +280,7 @@ HeapTupleSatisfiesNow(HeapTupleHeader tuple) ...@@ -280,7 +280,7 @@ HeapTupleSatisfiesNow(HeapTupleHeader tuple)
{ {
if (tuple->t_infomask & HEAP_MARKED_FOR_UPDATE) if (tuple->t_infomask & HEAP_MARKED_FOR_UPDATE)
return true; return true;
if (CommandIdGEScanCommandId(tuple->t_cmax)) if (tuple->t_cmax >= GetCurrentCommandId())
return true; /* deleted after scan started */ return true; /* deleted after scan started */
else else
return false; /* deleted before scan started */ return false; /* deleted before scan started */
...@@ -363,10 +363,12 @@ HeapTupleSatisfiesToast(HeapTupleHeader tuple) ...@@ -363,10 +363,12 @@ HeapTupleSatisfiesToast(HeapTupleHeader tuple)
* HeapTupleSatisfiesUpdate * HeapTupleSatisfiesUpdate
* *
* Same logic as HeapTupleSatisfiesNow, but returns a more detailed result * Same logic as HeapTupleSatisfiesNow, but returns a more detailed result
* code, since UPDATE needs to know more than "is it visible?". * code, since UPDATE needs to know more than "is it visible?". Also,
* tuples of my own xact are tested against the passed CommandId not
* CurrentCommandId.
*/ */
int int
HeapTupleSatisfiesUpdate(HeapTuple htuple) HeapTupleSatisfiesUpdate(HeapTuple htuple, CommandId curcid)
{ {
HeapTupleHeader tuple = htuple->t_data; HeapTupleHeader tuple = htuple->t_data;
...@@ -409,7 +411,7 @@ HeapTupleSatisfiesUpdate(HeapTuple htuple) ...@@ -409,7 +411,7 @@ HeapTupleSatisfiesUpdate(HeapTuple htuple)
} }
else if (TransactionIdIsCurrentTransactionId(tuple->t_xmin)) else if (TransactionIdIsCurrentTransactionId(tuple->t_xmin))
{ {
if (CommandIdGEScanCommandId(tuple->t_cmin)) if (tuple->t_cmin >= curcid)
return HeapTupleInvisible; /* inserted after scan return HeapTupleInvisible; /* inserted after scan
* started */ * started */
...@@ -421,7 +423,7 @@ HeapTupleSatisfiesUpdate(HeapTuple htuple) ...@@ -421,7 +423,7 @@ HeapTupleSatisfiesUpdate(HeapTuple htuple)
if (tuple->t_infomask & HEAP_MARKED_FOR_UPDATE) if (tuple->t_infomask & HEAP_MARKED_FOR_UPDATE)
return HeapTupleMayBeUpdated; return HeapTupleMayBeUpdated;
if (CommandIdGEScanCommandId(tuple->t_cmax)) if (tuple->t_cmax >= curcid)
return HeapTupleSelfUpdated; /* updated after scan return HeapTupleSelfUpdated; /* updated after scan
* started */ * started */
else else
...@@ -454,7 +456,7 @@ HeapTupleSatisfiesUpdate(HeapTuple htuple) ...@@ -454,7 +456,7 @@ HeapTupleSatisfiesUpdate(HeapTuple htuple)
{ {
if (tuple->t_infomask & HEAP_MARKED_FOR_UPDATE) if (tuple->t_infomask & HEAP_MARKED_FOR_UPDATE)
return HeapTupleMayBeUpdated; return HeapTupleMayBeUpdated;
if (CommandIdGEScanCommandId(tuple->t_cmax)) if (tuple->t_cmax >= curcid)
return HeapTupleSelfUpdated; /* updated after scan return HeapTupleSelfUpdated; /* updated after scan
* started */ * started */
else else
...@@ -677,7 +679,7 @@ HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple, Snapshot snapshot) ...@@ -677,7 +679,7 @@ HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple, Snapshot snapshot)
} }
else if (TransactionIdIsCurrentTransactionId(tuple->t_xmin)) else if (TransactionIdIsCurrentTransactionId(tuple->t_xmin))
{ {
if (CommandIdGEScanCommandId(tuple->t_cmin)) if (tuple->t_cmin >= snapshot->curcid)
return false; /* inserted after scan started */ return false; /* inserted after scan started */
if (tuple->t_infomask & HEAP_XMAX_INVALID) /* xid invalid */ if (tuple->t_infomask & HEAP_XMAX_INVALID) /* xid invalid */
...@@ -688,7 +690,7 @@ HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple, Snapshot snapshot) ...@@ -688,7 +690,7 @@ HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple, Snapshot snapshot)
if (tuple->t_infomask & HEAP_MARKED_FOR_UPDATE) if (tuple->t_infomask & HEAP_MARKED_FOR_UPDATE)
return true; return true;
if (CommandIdGEScanCommandId(tuple->t_cmax)) if (tuple->t_cmax >= snapshot->curcid)
return true; /* deleted after scan started */ return true; /* deleted after scan started */
else else
return false; /* deleted before scan started */ return false; /* deleted before scan started */
...@@ -730,7 +732,7 @@ HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple, Snapshot snapshot) ...@@ -730,7 +732,7 @@ HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple, Snapshot snapshot)
{ {
if (TransactionIdIsCurrentTransactionId(tuple->t_xmax)) if (TransactionIdIsCurrentTransactionId(tuple->t_xmax))
{ {
if (CommandIdGEScanCommandId(tuple->t_cmax)) if (tuple->t_cmax >= snapshot->curcid)
return true; /* deleted after scan started */ return true; /* deleted after scan started */
else else
return false; /* deleted before scan started */ return false; /* deleted before scan started */
...@@ -950,6 +952,7 @@ SetQuerySnapshot(void) ...@@ -950,6 +952,7 @@ SetQuerySnapshot(void)
{ {
free(QuerySnapshot->xip); free(QuerySnapshot->xip);
free(QuerySnapshot); free(QuerySnapshot);
QuerySnapshot = NULL;
} }
if (XactIsoLevel == XACT_SERIALIZABLE) if (XactIsoLevel == XACT_SERIALIZABLE)
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: heapam.h,v 1.74 2002/05/20 23:51:43 tgl Exp $ * $Id: heapam.h,v 1.75 2002/05/21 22:05:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -156,16 +156,23 @@ extern void heap_fetch(Relation relation, Snapshot snapshot, ...@@ -156,16 +156,23 @@ extern void heap_fetch(Relation relation, Snapshot snapshot,
HeapTuple tuple, Buffer *userbuf, HeapTuple tuple, Buffer *userbuf,
PgStat_Info *pgstat_info); PgStat_Info *pgstat_info);
extern ItemPointer heap_get_latest_tid(Relation relation, Snapshot snapshot, ItemPointer tid); extern ItemPointer heap_get_latest_tid(Relation relation, Snapshot snapshot,
ItemPointer tid);
extern void setLastTid(const ItemPointer tid); extern void setLastTid(const ItemPointer tid);
extern Oid heap_insert(Relation relation, HeapTuple tup);
extern int heap_delete(Relation relation, ItemPointer tid, ItemPointer ctid); extern Oid heap_insert(Relation relation, HeapTuple tup, CommandId cid);
extern int heap_delete(Relation relation, ItemPointer tid, ItemPointer ctid,
CommandId cid);
extern int heap_update(Relation relation, ItemPointer otid, HeapTuple tup, extern int heap_update(Relation relation, ItemPointer otid, HeapTuple tup,
ItemPointer ctid); ItemPointer ctid, CommandId cid);
extern int heap_mark4update(Relation relation, HeapTuple tup, Buffer *userbuf); extern int heap_mark4update(Relation relation, HeapTuple tup,
Buffer *userbuf, CommandId cid);
extern Oid simple_heap_insert(Relation relation, HeapTuple tup);
extern void simple_heap_delete(Relation relation, ItemPointer tid); extern void simple_heap_delete(Relation relation, ItemPointer tid);
extern void simple_heap_update(Relation relation, ItemPointer otid, extern void simple_heap_update(Relation relation, ItemPointer otid,
HeapTuple tup); HeapTuple tup);
extern void heap_markpos(HeapScanDesc scan); extern void heap_markpos(HeapScanDesc scan);
extern void heap_restrpos(HeapScanDesc scan); extern void heap_restrpos(HeapScanDesc scan);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: xact.h,v 1.42 2002/04/01 03:34:27 tgl Exp $ * $Id: xact.h,v 1.43 2002/05/21 22:05:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -38,7 +38,6 @@ typedef struct TransactionStateData ...@@ -38,7 +38,6 @@ typedef struct TransactionStateData
{ {
TransactionId transactionIdData; TransactionId transactionIdData;
CommandId commandId; CommandId commandId;
CommandId scanCommandId;
AbsoluteTime startTime; AbsoluteTime startTime;
int startTimeUsec; int startTimeUsec;
int state; int state;
...@@ -101,13 +100,10 @@ extern bool IsTransactionState(void); ...@@ -101,13 +100,10 @@ extern bool IsTransactionState(void);
extern bool IsAbortedTransactionBlockState(void); extern bool IsAbortedTransactionBlockState(void);
extern TransactionId GetCurrentTransactionId(void); extern TransactionId GetCurrentTransactionId(void);
extern CommandId GetCurrentCommandId(void); extern CommandId GetCurrentCommandId(void);
extern CommandId GetScanCommandId(void);
extern void SetScanCommandId(CommandId);
extern AbsoluteTime GetCurrentTransactionStartTime(void); extern AbsoluteTime GetCurrentTransactionStartTime(void);
extern AbsoluteTime GetCurrentTransactionStartTimeUsec(int *usec); extern AbsoluteTime GetCurrentTransactionStartTimeUsec(int *usec);
extern bool TransactionIdIsCurrentTransactionId(TransactionId xid); extern bool TransactionIdIsCurrentTransactionId(TransactionId xid);
extern bool CommandIdIsCurrentCommandId(CommandId cid); extern bool CommandIdIsCurrentCommandId(CommandId cid);
extern bool CommandIdGEScanCommandId(CommandId cid);
extern void CommandCounterIncrement(void); extern void CommandCounterIncrement(void);
extern void StartTransactionCommand(void); extern void StartTransactionCommand(void);
extern void CommitTransactionCommand(void); extern void CommitTransactionCommand(void);
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* spi.c * spi.c
* Server Programming Interface private declarations * Server Programming Interface private declarations
* *
* $Header: /cvsroot/pgsql/src/include/executor/spi_priv.h,v 1.11 2001/11/05 17:46:33 momjian Exp $ * $Header: /cvsroot/pgsql/src/include/executor/spi_priv.h,v 1.12 2002/05/21 22:05:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -20,7 +20,6 @@ typedef struct ...@@ -20,7 +20,6 @@ typedef struct
MemoryContext procCxt; /* procedure context */ MemoryContext procCxt; /* procedure context */
MemoryContext execCxt; /* executor context */ MemoryContext execCxt; /* executor context */
MemoryContext savedcxt; MemoryContext savedcxt;
CommandId savedId;
} _SPI_connection; } _SPI_connection;
typedef struct typedef struct
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: portal.h,v 1.32 2002/02/14 15:24:10 tgl Exp $ * $Id: portal.h,v 1.33 2002/05/21 22:05:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -31,7 +31,6 @@ typedef struct PortalData ...@@ -31,7 +31,6 @@ typedef struct PortalData
MemoryContext heap; /* subsidiary memory */ MemoryContext heap; /* subsidiary memory */
QueryDesc *queryDesc; /* Info about query associated with portal */ QueryDesc *queryDesc; /* Info about query associated with portal */
TupleDesc attinfo; TupleDesc attinfo;
CommandId commandId; /* Command counter value for query */
EState *state; /* Execution state of query */ EState *state; /* Execution state of query */
bool atStart; /* T => fetch backwards is not allowed */ bool atStart; /* T => fetch backwards is not allowed */
bool atEnd; /* T => fetch forwards is not allowed */ bool atEnd; /* T => fetch forwards is not allowed */
...@@ -49,7 +48,6 @@ typedef struct PortalData ...@@ -49,7 +48,6 @@ typedef struct PortalData
*/ */
#define PortalGetQueryDesc(portal) ((portal)->queryDesc) #define PortalGetQueryDesc(portal) ((portal)->queryDesc)
#define PortalGetTupleDesc(portal) ((portal)->attinfo) #define PortalGetTupleDesc(portal) ((portal)->attinfo)
#define PortalGetCommandId(portal) ((portal)->commandId)
#define PortalGetState(portal) ((portal)->state) #define PortalGetState(portal) ((portal)->state)
#define PortalGetHeapMemory(portal) ((portal)->heap) #define PortalGetHeapMemory(portal) ((portal)->heap)
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: tqual.h,v 1.38 2002/01/16 20:29:02 tgl Exp $ * $Id: tqual.h,v 1.39 2002/05/21 22:05:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -26,6 +26,7 @@ typedef struct SnapshotData ...@@ -26,6 +26,7 @@ typedef struct SnapshotData
uint32 xcnt; /* # of xact ids in xip[] */ uint32 xcnt; /* # of xact ids in xip[] */
TransactionId *xip; /* array of xact IDs in progress */ TransactionId *xip; /* array of xact IDs in progress */
/* note: all ids in xip[] satisfy xmin <= xip[i] < xmax */ /* note: all ids in xip[] satisfy xmin <= xip[i] < xmax */
CommandId curcid; /* in my xact, CID < curcid are visible */
ItemPointerData tid; /* required for Dirty snapshot -:( */ ItemPointerData tid; /* required for Dirty snapshot -:( */
} SnapshotData; } SnapshotData;
...@@ -104,7 +105,8 @@ extern bool HeapTupleSatisfiesDirty(HeapTupleHeader tuple); ...@@ -104,7 +105,8 @@ extern bool HeapTupleSatisfiesDirty(HeapTupleHeader tuple);
extern bool HeapTupleSatisfiesToast(HeapTupleHeader tuple); extern bool HeapTupleSatisfiesToast(HeapTupleHeader tuple);
extern bool HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple, extern bool HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple,
Snapshot snapshot); Snapshot snapshot);
extern int HeapTupleSatisfiesUpdate(HeapTuple tuple); extern int HeapTupleSatisfiesUpdate(HeapTuple tuple,
CommandId curcid);
extern HTSV_Result HeapTupleSatisfiesVacuum(HeapTupleHeader tuple, extern HTSV_Result HeapTupleSatisfiesVacuum(HeapTupleHeader tuple,
TransactionId OldestXmin); TransactionId OldestXmin);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment