1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-07 19:06:32 +03:00

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.
This commit is contained in:
Tom Lane
2001-01-23 04:32:23 +00:00
parent 7a2a1acd52
commit 786f1a59cd
24 changed files with 192 additions and 107 deletions

View File

@@ -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);

View File

@@ -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];

View File

@@ -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

View File

@@ -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 ***/

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);
}
}