aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/creatinh.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>1999-09-18 19:08:25 +0000
committerTom Lane <tgl@sss.pgh.pa.us>1999-09-18 19:08:25 +0000
commitbd272cace63effa23d68a6b344a07e326b6a41e2 (patch)
tree3026c545c238bd38eadc7fb1fac89d636cf51673 /src/backend/commands/creatinh.c
parent6c86fd5ba49bc03949ea1c788023f39da9c0b9fe (diff)
downloadpostgresql-bd272cace63effa23d68a6b344a07e326b6a41e2.tar.gz
postgresql-bd272cace63effa23d68a6b344a07e326b6a41e2.zip
Mega-commit to make heap_open/heap_openr/heap_close take an
additional argument specifying the kind of lock to acquire/release (or 'NoLock' to do no lock processing). Ensure that all relations are locked with some appropriate lock level before being examined --- this ensures that relevant shared-inval messages have been processed and should prevent problems caused by concurrent VACUUM. Fix several bugs having to do with mismatched increment/decrement of relation ref count and mismatched heap_open/close (which amounts to the same thing). A bogus ref count on a relation doesn't matter much *unless* a SI Inval message happens to arrive at the wrong time, which is probably why we got away with this sloppiness for so long. Repair missing grab of AccessExclusiveLock in DROP TABLE, ALTER/RENAME TABLE, etc, as noted by Hiroshi. Recommend 'make clean all' after pulling this update; I modified the Relation struct layout slightly. Will post further discussion to pghackers list shortly.
Diffstat (limited to 'src/backend/commands/creatinh.c')
-rw-r--r--src/backend/commands/creatinh.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/src/backend/commands/creatinh.c b/src/backend/commands/creatinh.c
index b93a40e7ba3..c1069dd41e6 100644
--- a/src/backend/commands/creatinh.c
+++ b/src/backend/commands/creatinh.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.45 1999/07/17 20:16:52 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.46 1999/09/18 19:06:40 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -202,14 +202,13 @@ MergeAttributes(List *schema, List *supers, List **supconstr)
*/
foreach(entry, schema)
{
- List *rest;
ColumnDef *coldef = lfirst(entry);
+ List *rest;
foreach(rest, lnext(entry))
{
-
/*
- * check for duplicated relation names
+ * check for duplicated names within the new relation
*/
ColumnDef *restdef = lfirst(rest);
@@ -246,17 +245,14 @@ MergeAttributes(List *schema, List *supers, List **supconstr)
TupleDesc tupleDesc;
TupleConstr *constr;
- relation = heap_openr(name);
- if (relation == NULL)
- {
- elog(ERROR,
- "MergeAttr: Can't inherit from non-existent superclass '%s'", name);
- }
- if (relation->rd_rel->relkind == 'S')
- elog(ERROR, "MergeAttr: Can't inherit from sequence superclass '%s'", name);
+ relation = heap_openr(name, AccessShareLock);
tupleDesc = RelationGetDescr(relation);
constr = tupleDesc->constr;
+ /* XXX shouldn't this test be stricter? No indexes, for example? */
+ if (relation->rd_rel->relkind == 'S')
+ elog(ERROR, "MergeAttr: Can't inherit from sequence superclass '%s'", name);
+
for (attrno = relation->rd_rel->relnatts - 1; attrno >= 0; attrno--)
{
Form_pg_attribute attribute = tupleDesc->attrs[attrno];
@@ -340,9 +336,11 @@ MergeAttributes(List *schema, List *supers, List **supconstr)
}
/*
- * iteration cleanup and result collection
+ * Close the parent rel, but keep our AccessShareLock on it until
+ * xact commit. That will prevent someone else from deleting or
+ * ALTERing the parent before the child is committed.
*/
- heap_close(relation);
+ heap_close(relation, NoLock);
/*
* wants the inherited schema to appear in the order they are
@@ -386,7 +384,7 @@ StoreCatalogInheritance(Oid relationId, List *supers)
* Catalog INHERITS information.
* ----------------
*/
- relation = heap_openr(InheritsRelationName);
+ relation = heap_openr(InheritsRelationName, RowExclusiveLock);
desc = RelationGetDescr(relation);
seqNumber = 1;
@@ -422,7 +420,7 @@ StoreCatalogInheritance(Oid relationId, List *supers)
seqNumber += 1;
}
- heap_close(relation);
+ heap_close(relation, RowExclusiveLock);
/* ----------------
* Catalog IPL information.
@@ -510,7 +508,7 @@ again:
* 3.
* ----------------
*/
- relation = heap_openr(InheritancePrecidenceListRelationName);
+ relation = heap_openr(InheritancePrecidenceListRelationName, RowExclusiveLock);
desc = RelationGetDescr(relation);
seqNumber = 1;
@@ -537,7 +535,7 @@ again:
seqNumber += 1;
}
- heap_close(relation);
+ heap_close(relation, RowExclusiveLock);
}
/*