diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 1999-09-18 19:08:25 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 1999-09-18 19:08:25 +0000 |
| commit | bd272cace63effa23d68a6b344a07e326b6a41e2 (patch) | |
| tree | 3026c545c238bd38eadc7fb1fac89d636cf51673 /src/backend/tcop/utility.c | |
| parent | 6c86fd5ba49bc03949ea1c788023f39da9c0b9fe (diff) | |
| download | postgresql-bd272cace63effa23d68a6b344a07e326b6a41e2.tar.gz | |
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/tcop/utility.c')
| -rw-r--r-- | src/backend/tcop/utility.c | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index 8c1ac55614..29b4fb527c 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.64 1999/07/16 04:59:55 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.65 1999/09/18 19:07:44 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -165,38 +165,39 @@ ProcessUtility(Node *parsetree, case T_DestroyStmt: { DestroyStmt *stmt = (DestroyStmt *) parsetree; - List *arg; List *args = stmt->relNames; - Relation rel; + List *arg; PS_SET_STATUS(commandTag = "DROP"); CHECK_IF_ABORTED(); + /* check as much as we can before we start dropping ... */ foreach(arg, args) { + Relation rel; + relname = strVal(lfirst(arg)); if (!allowSystemTableMods && IsSystemRelationName(relname)) elog(ERROR, "class \"%s\" is a system catalog", relname); - rel = heap_openr(relname); - if (RelationIsValid(rel)) - { - if (stmt->sequence && - rel->rd_rel->relkind != RELKIND_SEQUENCE) - elog(ERROR, "Use DROP TABLE to drop table '%s'", - relname); - if (!(stmt->sequence) && - rel->rd_rel->relkind == RELKIND_SEQUENCE) - elog(ERROR, "Use DROP SEQUENCE to drop sequence '%s'", - relname); - heap_close(rel); - } + rel = heap_openr(relname, AccessExclusiveLock); + if (stmt->sequence && + rel->rd_rel->relkind != RELKIND_SEQUENCE) + elog(ERROR, "Use DROP TABLE to drop table '%s'", + relname); + if (!(stmt->sequence) && + rel->rd_rel->relkind == RELKIND_SEQUENCE) + elog(ERROR, "Use DROP SEQUENCE to drop sequence '%s'", + relname); + /* close rel, but keep lock until end of xact */ + heap_close(rel, NoLock); #ifndef NO_SECURITY if (!pg_ownercheck(userName, relname, RELNAME)) elog(ERROR, "you do not own class \"%s\"", relname); #endif } + /* OK, terminate 'em all */ foreach(arg, args) { relname = strVal(lfirst(arg)); |
