提交 786f1a59 编写于 作者: T Tom Lane

Fix all the places that called heap_update() and heap_delete() without

bothering to check the return value --- which meant that in case the
update or delete failed because of a concurrent update, you'd not find
out about it, except by observing later that the transaction produced
the wrong outcome.  There are now subroutines simple_heap_update and
simple_heap_delete that should be used anyplace that you're not prepared
to do the full nine yards of coping with concurrent updates.  In
practice, that seems to mean absolutely everywhere but the executor,
because *noplace* else was checking.
上级 7a2a1acd
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.108 2001/01/15 05:29:19 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.109 2001/01/23 04:32:20 tgl Exp $
*
*
* INTERFACE ROUTINES
......@@ -1423,6 +1423,9 @@ heap_insert(Relation relation, HeapTuple tup)
/*
* heap_delete - delete a tuple
*
* NB: do not call this directly unless you are prepared to deal with
* concurrent-update conditions. Use simple_heap_delete instead.
*/
int
heap_delete(Relation relation, ItemPointer tid, ItemPointer ctid)
......@@ -1496,8 +1499,7 @@ l1:
if (result != HeapTupleMayBeUpdated)
{
Assert(result == HeapTupleSelfUpdated || result == HeapTupleUpdated);
if (ctid != NULL)
*ctid = tp.t_data->t_ctid;
*ctid = tp.t_data->t_ctid;
LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
ReleaseBuffer(buffer);
return result;
......@@ -1560,8 +1562,48 @@ l1:
return HeapTupleMayBeUpdated;
}
/*
* simple_heap_delete - delete a tuple
*
* This routine may be used to delete a tuple when concurrent updates of
* the target tuple are not expected (for example, because we have a lock
* on the relation associated with the tuple). Any failure is reported
* via elog().
*/
void
simple_heap_delete(Relation relation, ItemPointer tid)
{
ItemPointerData ctid;
int result;
result = heap_delete(relation, tid, &ctid);
switch (result)
{
case HeapTupleSelfUpdated:
/* Tuple was already updated in current command? */
elog(ERROR, "simple_heap_delete: tuple already updated by self");
break;
case HeapTupleMayBeUpdated:
/* done successfully */
break;
case HeapTupleUpdated:
elog(ERROR, "simple_heap_delete: tuple concurrently updated");
break;
default:
elog(ERROR, "Unknown status %u from heap_delete", result);
break;
}
}
/*
* heap_update - replace a tuple
*
* NB: do not call this directly unless you are prepared to deal with
* concurrent-update conditions. Use simple_heap_update instead.
*/
int
heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
......@@ -1643,8 +1685,7 @@ l2:
if (result != HeapTupleMayBeUpdated)
{
Assert(result == HeapTupleSelfUpdated || result == HeapTupleUpdated);
if (ctid != NULL)
*ctid = oldtup.t_data->t_ctid;
*ctid = oldtup.t_data->t_ctid;
LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
ReleaseBuffer(buffer);
return result;
......@@ -1783,6 +1824,42 @@ l2:
return HeapTupleMayBeUpdated;
}
/*
* simple_heap_update - replace a tuple
*
* This routine may be used to update a tuple when concurrent updates of
* the target tuple are not expected (for example, because we have a lock
* on the relation associated with the tuple). Any failure is reported
* via elog().
*/
void
simple_heap_update(Relation relation, ItemPointer otid, HeapTuple tup)
{
ItemPointerData ctid;
int result;
result = heap_update(relation, otid, tup, &ctid);
switch (result)
{
case HeapTupleSelfUpdated:
/* Tuple was already updated in current command? */
elog(ERROR, "simple_heap_update: tuple already updated by self");
break;
case HeapTupleMayBeUpdated:
/* done successfully */
break;
case HeapTupleUpdated:
elog(ERROR, "simple_heap_update: tuple concurrently updated");
break;
default:
elog(ERROR, "Unknown status %u from heap_update", result);
break;
}
}
/*
* heap_mark4update - mark a tuple for update
*/
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/heap/tuptoaster.c,v 1.14 2001/01/15 05:29:19 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/access/heap/tuptoaster.c,v 1.15 2001/01/23 04:32:20 tgl Exp $
*
*
* INTERFACE ROUTINES
......@@ -937,7 +937,7 @@ toast_delete_datum(Relation rel, Datum value)
* Have a chunk, delete it
* ----------
*/
heap_delete(toastrel, &toasttup.t_self, NULL);
simple_heap_delete(toastrel, &toasttup.t_self);
ReleaseBuffer(buffer);
}
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.44 2000/11/28 23:42:31 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.45 2001/01/23 04:32:21 tgl Exp $
*
* NOTES
* See acl.h.
......@@ -139,7 +139,7 @@ ChangeAcl(char *relname,
ReleaseSysCache(tuple);
heap_update(relation, &newtuple->t_self, newtuple, NULL);
simple_heap_update(relation, &newtuple->t_self, newtuple);
/* keep the catalog indices up to date */
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices,
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.156 2001/01/01 21:33:31 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.157 2001/01/23 04:32:21 tgl Exp $
*
*
* INTERFACE ROUTINES
......@@ -1000,7 +1000,7 @@ RelationRemoveInheritance(Relation relation)
while (HeapTupleIsValid(tuple = heap_getnext(scan, 0)))
{
heap_delete(catalogRelation, &tuple->t_self, NULL);
simple_heap_delete(catalogRelation, &tuple->t_self);
found = true;
}
......@@ -1023,7 +1023,9 @@ RelationRemoveInheritance(Relation relation)
&entry);
while (HeapTupleIsValid(tuple = heap_getnext(scan, 0)))
heap_delete(catalogRelation, &tuple->t_self, NULL);
{
simple_heap_delete(catalogRelation, &tuple->t_self);
}
heap_endscan(scan);
heap_close(catalogRelation, RowExclusiveLock);
......@@ -1093,7 +1095,7 @@ DeleteRelationTuple(Relation rel)
* delete the relation tuple from pg_class, and finish up.
* ----------------
*/
heap_delete(pg_class_desc, &tup->t_self, NULL);
simple_heap_delete(pg_class_desc, &tup->t_self);
heap_freetuple(tup);
heap_close(pg_class_desc, RowExclusiveLock);
......@@ -1267,7 +1269,7 @@ DeleteAttributeTuples(Relation rel)
/*** Delete any comments associated with this attribute ***/
DeleteComments(tup->t_data->t_oid);
heap_delete(pg_attribute_desc, &tup->t_self, NULL);
simple_heap_delete(pg_attribute_desc, &tup->t_self);
heap_freetuple(tup);
}
}
......@@ -1382,12 +1384,10 @@ DeleteTypeTuple(Relation rel)
/* ----------------
* Ok, it's safe so we delete the relation tuple
* from pg_type and finish up. But first end the scan so that
* we release the read lock on pg_type. -mer 13 Aug 1991
* from pg_type and finish up.
* ----------------
*/
heap_delete(pg_type_desc, &tup->t_self, NULL);
simple_heap_delete(pg_type_desc, &tup->t_self);
heap_endscan(pg_type_scan);
heap_close(pg_type_desc, RowExclusiveLock);
......@@ -1595,7 +1595,7 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin,
if (!attStruct->atthasdef)
{
attStruct->atthasdef = true;
heap_update(attrrel, &atttup->t_self, atttup, NULL);
simple_heap_update(attrrel, &atttup->t_self, atttup);
/* keep catalog indices current */
CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices,
attridescs);
......@@ -1962,7 +1962,7 @@ AddRelationRawConstraints(Relation rel,
relStruct->relchecks = numchecks;
heap_update(relrel, &reltup->t_self, reltup, NULL);
simple_heap_update(relrel, &reltup->t_self, reltup);
/* keep catalog indices current */
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices,
......@@ -1990,7 +1990,9 @@ RemoveAttrDefault(Relation rel)
adscan = heap_beginscan(adrel, 0, SnapshotNow, 1, &key);
while (HeapTupleIsValid(tup = heap_getnext(adscan, 0)))
heap_delete(adrel, &tup->t_self, NULL);
{
simple_heap_delete(adrel, &tup->t_self);
}
heap_endscan(adscan);
heap_close(adrel, RowExclusiveLock);
......@@ -2012,7 +2014,9 @@ RemoveRelCheck(Relation rel)
rcscan = heap_beginscan(rcrel, 0, SnapshotNow, 1, &key);
while (HeapTupleIsValid(tup = heap_getnext(rcscan, 0)))
heap_delete(rcrel, &tup->t_self, NULL);
{
simple_heap_delete(rcrel, &tup->t_self);
}
heap_endscan(rcscan);
heap_close(rcrel, RowExclusiveLock);
......@@ -2049,7 +2053,9 @@ RemoveStatistics(Relation rel)
scan = heap_beginscan(pgstatistic, false, SnapshotNow, 1, &key);
while (HeapTupleIsValid(tuple = heap_getnext(scan, 0)))
heap_delete(pgstatistic, &tuple->t_self, NULL);
{
simple_heap_delete(pgstatistic, &tuple->t_self);
}
heap_endscan(scan);
heap_close(pgstatistic, RowExclusiveLock);
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.135 2001/01/18 07:29:04 inoue Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.136 2001/01/23 04:32:21 tgl Exp $
*
*
* INTERFACE ROUTINES
......@@ -783,7 +783,7 @@ UpdateIndexPredicate(Oid indexoid, Node *oldPred, Node *predicate)
newtup = heap_modifytuple(tuple, pg_index, values, nulls, replace);
heap_update(pg_index, &newtup->t_self, newtup, NULL);
simple_heap_update(pg_index, &newtup->t_self, newtup);
heap_freetuple(newtup);
ReleaseSysCache(tuple);
......@@ -1085,7 +1085,7 @@ index_drop(Oid indexId)
elog(ERROR, "index_drop: cache lookup failed for index %u",
indexId);
heap_delete(relationRelation, &tuple->t_self, NULL);
simple_heap_delete(relationRelation, &tuple->t_self);
heap_freetuple(tuple);
/*
......@@ -1113,7 +1113,7 @@ index_drop(Oid indexId)
Int16GetDatum(attnum),
0, 0)))
{
heap_delete(attributeRelation, &tuple->t_self, NULL);
simple_heap_delete(attributeRelation, &tuple->t_self);
heap_freetuple(tuple);
attnum++;
}
......@@ -1132,7 +1132,7 @@ index_drop(Oid indexId)
elog(ERROR, "index_drop: cache lookup failed for index %u",
indexId);
heap_delete(indexRelation, &tuple->t_self, NULL);
simple_heap_delete(indexRelation, &tuple->t_self);
heap_freetuple(tuple);
heap_close(indexRelation, RowExclusiveLock);
......@@ -1495,7 +1495,7 @@ setRelhasindex(Oid relid, bool hasindex)
}
else
{
heap_update(pg_class, &tuple->t_self, tuple, NULL);
simple_heap_update(pg_class, &tuple->t_self, tuple);
/* Keep the catalog indices up to date */
if (!IsIgnoringSystemIndexes())
......@@ -1545,7 +1545,7 @@ setNewRelfilenode(Relation relation)
classTuple = heap_copytuple(&lockTupleData);
ReleaseBuffer(buffer);
((Form_pg_class) GETSTRUCT(classTuple))->relfilenode = newrelfilenode;
heap_update(pg_class, &classTuple->t_self, classTuple, NULL);
simple_heap_update(pg_class, &classTuple->t_self, classTuple);
}
/* unlink old relfilenode */
DropRelationBuffers(relation);
......@@ -1751,7 +1751,7 @@ UpdateStats(Oid relid, long reltuples)
replace[Anum_pg_class_reltuples - 1] = 'r';
values[Anum_pg_class_reltuples - 1] = (Datum) reltuples;
newtup = heap_modifytuple(tuple, pg_class, values, nulls, replace);
heap_update(pg_class, &tuple->t_self, newtup, NULL);
simple_heap_update(pg_class, &tuple->t_self, newtup);
if (!IsIgnoringSystemIndexes())
{
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs);
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_largeobject.c,v 1.5 2000/10/24 01:38:23 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_largeobject.c,v 1.6 2001/01/23 04:32:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -118,7 +118,7 @@ LargeObjectDrop(Oid loid)
pfree(indexRes);
if (tuple.t_data != NULL)
{
heap_delete(pg_largeobject, &tuple.t_self, NULL);
simple_heap_delete(pg_largeobject, &tuple.t_self);
ReleaseBuffer(buffer);
found = true;
}
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_operator.c,v 1.53 2000/11/16 22:30:17 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_operator.c,v 1.54 2001/01/23 04:32:21 tgl Exp $
*
* NOTES
* these routines moved here from commands/define.c and somewhat cleaned up.
......@@ -801,7 +801,7 @@ OperatorDef(char *operatorName,
nulls,
replaces);
heap_update(pg_operator_desc, &tup->t_self, tup, NULL);
simple_heap_update(pg_operator_desc, &tup->t_self, tup);
}
else
elog(ERROR, "OperatorDef: no operator %u", operatorObjectId);
......@@ -935,7 +935,7 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId)
nulls,
replaces);
heap_update(pg_operator_desc, &tup->t_self, tup, NULL);
simple_heap_update(pg_operator_desc, &tup->t_self, tup);
if (RelationGetForm(pg_operator_desc)->relhasindex)
{
......@@ -967,7 +967,7 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId)
nulls,
replaces);
heap_update(pg_operator_desc, &tup->t_self, tup, NULL);
simple_heap_update(pg_operator_desc, &tup->t_self, tup);
if (RelationGetForm(pg_operator_desc)->relhasindex)
{
......@@ -1005,7 +1005,7 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId)
nulls,
replaces);
heap_update(pg_operator_desc, &tup->t_self, tup, NULL);
simple_heap_update(pg_operator_desc, &tup->t_self, tup);
if (RelationGetForm(pg_operator_desc)->relhasindex)
{
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.56 2000/11/16 22:30:17 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.57 2001/01/23 04:32:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -490,7 +490,7 @@ TypeCreate(char *typeName,
nulls,
replaces);
heap_update(pg_type_desc, &tup->t_self, tup, NULL);
simple_heap_update(pg_type_desc, &tup->t_self, tup);
typeObjectId = tup->t_data->t_oid;
}
......@@ -555,7 +555,7 @@ TypeRename(const char *oldTypeName, const char *newTypeName)
namestrcpy(&(((Form_pg_type) GETSTRUCT(tuple))->typname), newTypeName);
heap_update(pg_type_desc, &tuple->t_self, tuple, NULL);
simple_heap_update(pg_type_desc, &tuple->t_self, tuple);
/* update the system catalog indices */
CatalogOpenIndices(Num_pg_type_indices, Name_pg_type_indices, idescs);
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.11 2001/01/14 05:08:15 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.12 2001/01/23 04:32:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -664,7 +664,7 @@ del_stats(Oid relid, int attcnt, int *attnums)
if (i >= attcnt)
continue; /* don't delete it */
}
heap_delete(pgstatistic, &tuple->t_self, NULL);
simple_heap_delete(pgstatistic, &tuple->t_self);
}
heap_endscan(scan);
......
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.74 2000/12/18 17:33:40 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.75 2001/01/23 04:32:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -299,7 +299,7 @@ Async_Unlisten(char *relname, int pid)
0, 0);
if (HeapTupleIsValid(lTuple))
{
heap_delete(lRel, &lTuple->t_self, NULL);
simple_heap_delete(lRel, &lTuple->t_self);
ReleaseSysCache(lTuple);
}
heap_close(lRel, AccessExclusiveLock);
......@@ -349,7 +349,9 @@ Async_UnlistenAll()
sRel = heap_beginscan(lRel, 0, SnapshotNow, 1, key);
while (HeapTupleIsValid(lTuple = heap_getnext(sRel, 0)))
heap_delete(lRel, &lTuple->t_self, NULL);
{
simple_heap_delete(lRel, &lTuple->t_self);
}
heap_endscan(sRel);
heap_close(lRel, AccessExclusiveLock);
......@@ -506,7 +508,7 @@ AtCommit_Notify()
* just do it for any failure (certainly at least for
* EPERM too...)
*/
heap_delete(lRel, &lTuple->t_self, NULL);
simple_heap_delete(lRel, &lTuple->t_self);
}
else
{
......@@ -516,7 +518,7 @@ AtCommit_Notify()
{
rTuple = heap_modifytuple(lTuple, lRel,
value, nulls, repl);
heap_update(lRel, &lTuple->t_self, rTuple, NULL);
simple_heap_update(lRel, &lTuple->t_self, rTuple);
if (RelationGetForm(lRel)->relhasindex)
{
Relation idescs[Num_pg_listener_indices];
......@@ -797,7 +799,7 @@ ProcessIncomingNotify(void)
NotifyMyFrontEnd(relname, sourcePID);
/* Rewrite the tuple with 0 in notification column */
rTuple = heap_modifytuple(lTuple, lRel, value, nulls, repl);
heap_update(lRel, &lTuple->t_self, rTuple, NULL);
simple_heap_update(lRel, &lTuple->t_self, rTuple);
if (RelationGetForm(lRel)->relhasindex)
{
Relation idescs[Num_pg_listener_indices];
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.117 2001/01/23 01:48:16 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.118 2001/01/23 04:32:22 tgl Exp $
*
* NOTES
* The PerformAddAttribute() code, like most of the relation
......@@ -467,7 +467,7 @@ AlterTableAddColumn(const char *relationName,
newreltup = heap_copytuple(reltup);
((Form_pg_class) GETSTRUCT(newreltup))->relnatts = maxatts;
heap_update(rel, &newreltup->t_self, newreltup, NULL);
simple_heap_update(rel, &newreltup->t_self, newreltup);
/* keep catalog indices current */
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs);
......@@ -620,7 +620,7 @@ AlterTableAlterColumn(const char *relationName,
/* update to false */
newtuple = heap_copytuple(tuple);
((Form_pg_attribute) GETSTRUCT(newtuple))->atthasdef = FALSE;
heap_update(attr_rel, &tuple->t_self, newtuple, NULL);
simple_heap_update(attr_rel, &tuple->t_self, newtuple);
/* keep the system catalog indices current */
CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, irelations);
......@@ -657,10 +657,9 @@ drop_default(Oid relid, int16 attnum)
Int16GetDatum(attnum));
scan = heap_beginscan(attrdef_rel, false, SnapshotNow, 2, scankeys);
AssertState(scan != NULL);
if (HeapTupleIsValid(tuple = heap_getnext(scan, 0)))
heap_delete(attrdef_rel, &tuple->t_self, NULL);
simple_heap_delete(attrdef_rel, &tuple->t_self);
heap_endscan(scan);
......@@ -833,7 +832,7 @@ RemoveColumnReferences(Oid reloid, int attnum, bool checkonly, HeapTuple reltup)
}
else
{
heap_delete(rcrel, &htup->t_self, NULL);
simple_heap_delete(rcrel, &htup->t_self);
pgcform->relchecks--;
}
}
......@@ -1008,7 +1007,7 @@ AlterTableDropColumn(const char *relationName,
namestrcpy(&(attribute->attname), dropColname);
ATTRIBUTE_DROP_COLUMN(attribute);
heap_update(attrdesc, &tup->t_self, tup, NULL);
simple_heap_update(attrdesc, &tup->t_self, tup);
hasindex = (!IsIgnoringSystemIndexes() && RelationGetForm(attrdesc)->relhasindex);
if (hasindex)
{
......@@ -1038,7 +1037,7 @@ AlterTableDropColumn(const char *relationName,
{
if (((Form_pg_attrdef) GETSTRUCT(tup))->adnum == attnum)
{
heap_delete(adrel, &tup->t_self, NULL);
simple_heap_delete(adrel, &tup->t_self);
break;
}
}
......@@ -1054,7 +1053,7 @@ AlterTableDropColumn(const char *relationName,
RemoveColumnReferences(myrelid, attnum, false, reltup);
/* update pg_class tuple */
heap_update(rel, &reltup->t_self, reltup, NULL);
simple_heap_update(rel, &reltup->t_self, reltup);
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs);
CatalogIndexInsert(ridescs, Num_pg_class_indices, rel, reltup);
CatalogCloseIndices(Num_pg_class_indices, ridescs);
......@@ -1496,7 +1495,7 @@ AlterTableOwner(const char *relationName, const char *newOwnerName)
*/
((Form_pg_class) GETSTRUCT(tuple))->relowner = newOwnerSysid;
heap_update(class_rel, &tuple->t_self, tuple, NULL);
simple_heap_update(class_rel, &tuple->t_self, tuple);
/* Keep the catalog indices up to date */
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs);
......@@ -1692,7 +1691,7 @@ AlterTableCreateToastTable(const char *relationName, bool silent)
*/
((Form_pg_class) GETSTRUCT(reltup))->reltoastrelid = toast_relid;
((Form_pg_class) GETSTRUCT(reltup))->reltoastidxid = toast_idxid;
heap_update(class_rel, &reltup->t_self, reltup, NULL);
simple_heap_update(class_rel, &reltup->t_self, reltup);
/*
* Keep catalog indices current
......
......@@ -6,6 +6,9 @@
*
* Copyright (c) 1999, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.26 2001/01/23 04:32:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -169,15 +172,15 @@ CreateComments(Oid oid, char *comment)
if (HeapTupleIsValid(searchtuple))
{
/*** If the comment is blank, call heap_delete, else heap_update ***/
/*** If the comment is blank, delete old entry, else update it ***/
if ((comment == NULL) || (strlen(comment) == 0))
heap_delete(description, &searchtuple->t_self, NULL);
simple_heap_delete(description, &searchtuple->t_self);
else
{
desctuple = heap_modifytuple(searchtuple, description, values,
nulls, replaces);
heap_update(description, &searchtuple->t_self, desctuple, NULL);
simple_heap_update(description, &searchtuple->t_self, desctuple);
modified = TRUE;
}
......@@ -253,7 +256,7 @@ DeleteComments(Oid oid)
/*** If a previous tuple exists, delete it ***/
if (HeapTupleIsValid(searchtuple))
heap_delete(description, &searchtuple->t_self, NULL);
simple_heap_delete(description, &searchtuple->t_self);
/*** Complete the scan, update indices, if necessary ***/
......@@ -395,7 +398,7 @@ CommentDatabase(char *database, char *comment)
Oid oid;
bool superuser;
int32 dba;
Oid userid;
Oid userid;
/*** First find the tuple in pg_database for the database ***/
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.70 2001/01/05 02:58:16 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.71 2001/01/23 04:32:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -771,7 +771,7 @@ setRelhassubclassInRelation(Oid relationId, bool relhassubclass)
elog(ERROR, "setRelhassubclassInRelation: cache lookup failed for relation %u", relationId);
((Form_pg_class) GETSTRUCT(tuple))->relhassubclass = relhassubclass;
heap_update(relationRelation, &tuple->t_self, tuple, NULL);
simple_heap_update(relationRelation, &tuple->t_self, tuple);
/* keep the catalog indices up to date */
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs);
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.71 2001/01/14 22:14:10 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.72 2001/01/23 04:32:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -347,7 +347,7 @@ dropdb(const char *dbname)
}
/* Remove the database's tuple from pg_database */
heap_delete(pgdbrel, &tup->t_self, NULL);
simple_heap_delete(pgdbrel, &tup->t_self);
heap_endscan(pgdbscan);
......
......@@ -179,7 +179,7 @@ DropProceduralLanguage(DropPLangStmt *stmt)
elog(ERROR, "Language %s isn't a created procedural language",
languageName);
heap_delete(rel, &langTup->t_self, NULL);
simple_heap_delete(rel, &langTup->t_self);
heap_freetuple(langTup);
heap_close(rel, RowExclusiveLock);
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/remove.c,v 1.57 2000/12/15 04:08:15 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/remove.c,v 1.58 2001/01/23 04:32:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -91,7 +91,7 @@ RemoveOperator(char *operatorName, /* operator name */
DeleteComments(tup->t_data->t_oid);
heap_delete(relation, &tup->t_self, NULL);
simple_heap_delete(relation, &tup->t_self);
}
else
......@@ -154,8 +154,7 @@ SingleOpOperatorRemove(Oid typeOid)
DeleteComments(tup->t_data->t_oid);
heap_delete(rel, &tup->t_self, NULL);
simple_heap_delete(rel, &tup->t_self);
}
heap_endscan(scan);
......@@ -266,7 +265,7 @@ RemoveType(char *typeName) /* type name to be removed */
DeleteComments(typeOid);
heap_delete(relation, &tup->t_self, NULL);
simple_heap_delete(relation, &tup->t_self);
ReleaseSysCache(tup);
......@@ -278,7 +277,7 @@ RemoveType(char *typeName) /* type name to be removed */
if (!HeapTupleIsValid(tup))
elog(ERROR, "RemoveType: type '%s' does not exist", shadow_type);
heap_delete(relation, &tup->t_self, NULL);
simple_heap_delete(relation, &tup->t_self);
ReleaseSysCache(tup);
......@@ -354,7 +353,7 @@ RemoveFunction(char *functionName, /* function name to be removed */
DeleteComments(tup->t_data->t_oid);
heap_delete(relation, &tup->t_self, NULL);
simple_heap_delete(relation, &tup->t_self);
ReleaseSysCache(tup);
......@@ -428,7 +427,7 @@ RemoveAggregate(char *aggName, char *aggType)
DeleteComments(tup->t_data->t_oid);
heap_delete(relation, &tup->t_self, NULL);
simple_heap_delete(relation, &tup->t_self);
ReleaseSysCache(tup);
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.53 2000/11/16 22:30:18 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.54 2001/01/23 04:32:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -152,7 +152,7 @@ renameatt(char *relname,
StrNCpy(NameStr(((Form_pg_attribute) GETSTRUCT(atttup))->attname),
newattname, NAMEDATALEN);
heap_update(attrelation, &atttup->t_self, atttup, NULL);
simple_heap_update(attrelation, &atttup->t_self, atttup);
/* keep system catalog indices current */
{
......@@ -250,7 +250,7 @@ renamerel(const char *oldrelname, const char *newrelname)
StrNCpy(NameStr(((Form_pg_class) GETSTRUCT(reltup))->relname),
newrelname, NAMEDATALEN);
heap_update(relrelation, &reltup->t_self, reltup, NULL);
simple_heap_update(relrelation, &reltup->t_self, reltup);
/* keep the system catalog indices current */
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, irelations);
......
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.83 2001/01/22 00:50:07 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.84 2001/01/23 04:32:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -277,7 +277,7 @@ CreateTrigger(CreateTrigStmt *stmt)
stmt->relname);
((Form_pg_class) GETSTRUCT(tuple))->reltriggers = found + 1;
heap_update(pgrel, &tuple->t_self, tuple, NULL);
simple_heap_update(pgrel, &tuple->t_self, tuple);
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs);
CatalogIndexInsert(ridescs, Num_pg_class_indices, pgrel, tuple);
CatalogCloseIndices(Num_pg_class_indices, ridescs);
......@@ -333,7 +333,7 @@ DropTrigger(DropTrigStmt *stmt)
DeleteComments(tuple->t_data->t_oid);
heap_delete(tgrel, &tuple->t_self, NULL);
simple_heap_delete(tgrel, &tuple->t_self);
tgfound++;
}
else
......@@ -362,7 +362,7 @@ DropTrigger(DropTrigStmt *stmt)
stmt->relname);
((Form_pg_class) GETSTRUCT(tuple))->reltriggers = found;
heap_update(pgrel, &tuple->t_self, tuple, NULL);
simple_heap_update(pgrel, &tuple->t_self, tuple);
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs);
CatalogIndexInsert(ridescs, Num_pg_class_indices, pgrel, tuple);
CatalogCloseIndices(Num_pg_class_indices, ridescs);
......@@ -404,7 +404,7 @@ RelationRemoveTriggers(Relation rel)
DeleteComments(tup->t_data->t_oid);
heap_delete(tgrel, &tup->t_self, NULL);
simple_heap_delete(tgrel, &tup->t_self);
found = true;
}
......@@ -435,7 +435,7 @@ RelationRemoveTriggers(Relation rel)
RelationGetRelid(rel));
((Form_pg_class) GETSTRUCT(tup))->reltriggers = 0;
heap_update(pgrel, &tup->t_self, tup, NULL);
simple_heap_update(pgrel, &tup->t_self, tup);
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs);
CatalogIndexInsert(ridescs, Num_pg_class_indices, pgrel, tup);
CatalogCloseIndices(Num_pg_class_indices, ridescs);
......
......@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.71 2001/01/17 17:26:44 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.72 2001/01/23 04:32:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -458,10 +458,7 @@ AlterUser(AlterUserStmt *stmt)
}
new_tuple = heap_formtuple(pg_shadow_dsc, new_record, new_record_nulls);
Assert(new_tuple);
/* XXX check return value of this? */
heap_update(pg_shadow_rel, &tuple->t_self, new_tuple, NULL);
simple_heap_update(pg_shadow_rel, &tuple->t_self, new_tuple);
/* Update indexes */
if (RelationGetForm(pg_shadow_rel)->relhasindex)
......@@ -581,7 +578,7 @@ DropUser(DropUserStmt *stmt)
/*
* Remove the user from the pg_shadow table
*/
heap_delete(pg_shadow_rel, &tuple->t_self, NULL);
simple_heap_delete(pg_shadow_rel, &tuple->t_self);
ReleaseSysCache(tuple);
......@@ -929,7 +926,7 @@ AlterGroup(AlterGroupStmt *stmt, const char *tag)
new_record[Anum_pg_group_grolist - 1] = PointerGetDatum(newarray);
tuple = heap_formtuple(pg_group_dsc, new_record, new_record_nulls);
heap_update(pg_group_rel, &group_tuple->t_self, tuple, NULL);
simple_heap_update(pg_group_rel, &group_tuple->t_self, tuple);
/* Update indexes */
if (RelationGetForm(pg_group_rel)->relhasindex)
......@@ -1035,7 +1032,7 @@ AlterGroup(AlterGroupStmt *stmt, const char *tag)
new_record[Anum_pg_group_grolist - 1] = PointerGetDatum(newarray);
tuple = heap_formtuple(pg_group_dsc, new_record, new_record_nulls);
heap_update(pg_group_rel, &group_tuple->t_self, tuple, NULL);
simple_heap_update(pg_group_rel, &group_tuple->t_self, tuple);
/* Update indexes */
if (RelationGetForm(pg_group_rel)->relhasindex)
......@@ -1093,7 +1090,7 @@ DropGroup(DropGroupStmt *stmt)
if (datum && !null && strcmp((char *) datum, stmt->name) == 0)
{
gro_exists = true;
heap_delete(pg_group_rel, &tuple->t_self, NULL);
simple_heap_delete(pg_group_rel, &tuple->t_self);
}
}
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteRemove.c,v 1.41 2000/11/16 22:30:29 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteRemove.c,v 1.42 2001/01/23 04:32:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -124,7 +124,7 @@ RemoveRewriteRule(char *ruleName)
/*
* Now delete the pg_rewrite tuple for the rule
*/
heap_delete(RewriteRelation, &tuple->t_self, NULL);
simple_heap_delete(RewriteRelation, &tuple->t_self);
heap_freetuple(tuple);
......@@ -181,8 +181,7 @@ RelationRemoveRules(Oid relid)
DeleteComments(tuple->t_data->t_oid);
heap_delete(RewriteRelation, &tuple->t_self, NULL);
simple_heap_delete(RewriteRelation, &tuple->t_self);
}
heap_endscan(scanDesc);
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.45 2000/11/16 22:30:29 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.46 2001/01/23 04:32:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -66,7 +66,7 @@ SetRelationRuleStatus(Oid relationId, bool relHasRules,
if (relIsBecomingView)
((Form_pg_class) GETSTRUCT(tuple))->relkind = RELKIND_VIEW;
heap_update(relationRelation, &tuple->t_self, tuple, NULL);
simple_heap_update(relationRelation, &tuple->t_self, tuple);
/* Keep the catalog indices up to date */
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs);
......
......@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.82 2001/01/21 03:50:25 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.83 2001/01/23 04:32:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -522,7 +522,7 @@ inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes)
replace[Anum_pg_largeobject_data - 1] = 'r';
newtup = heap_modifytuple(&oldtuple, obj_desc->heap_r,
values, nulls, replace);
heap_update(obj_desc->heap_r, &newtup->t_self, newtup, NULL);
simple_heap_update(obj_desc->heap_r, &newtup->t_self, newtup);
if (write_indices)
CatalogIndexInsert(idescs, Num_pg_largeobject_indices,
obj_desc->heap_r, newtup);
......
......@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.34 2000/11/16 22:30:31 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.35 2001/01/23 04:32:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -113,7 +113,7 @@ SetDefine(char *querystr, char *typename)
replNull,
repl);
heap_update(procrel, &newtup->t_self, newtup, NULL);
simple_heap_update(procrel, &newtup->t_self, newtup);
setoid = newtup->t_data->t_oid;
......
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: heapam.h,v 1.60 2000/12/27 23:59:13 tgl Exp $
* $Id: heapam.h,v 1.61 2001/01/23 04:32:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -209,6 +209,9 @@ extern int heap_delete(Relation relation, ItemPointer tid, ItemPointer ctid);
extern int heap_update(Relation relation, ItemPointer otid, HeapTuple tup,
ItemPointer ctid);
extern int heap_mark4update(Relation relation, HeapTuple tup, Buffer *userbuf);
extern void simple_heap_delete(Relation relation, ItemPointer tid);
extern void simple_heap_update(Relation relation, ItemPointer otid,
HeapTuple tup);
extern void heap_markpos(HeapScanDesc scan);
extern void heap_restrpos(HeapScanDesc scan);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册