aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/rename.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2001-11-02 16:30:29 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2001-11-02 16:30:29 +0000
commit7d05310828aae801fd1483e638771a4034cbecd7 (patch)
tree6362bc6eb2738bcd93c7ecffa6e3a4e94dad75be /src/backend/commands/rename.c
parent5d4b94085eda499b090dc019b821607065ce5745 (diff)
downloadpostgresql-7d05310828aae801fd1483e638771a4034cbecd7.tar.gz
postgresql-7d05310828aae801fd1483e638771a4034cbecd7.zip
Fix problem reported by Alex Korn: if a relation has been dropped and
recreated since the start of our transaction, our first reference to it errored out because we'd try to reuse our old relcache entry for it. Do this by accepting SI inval messages just before relcache search in heap_openr, so that dead relcache entries will be flushed before we search. Also, break heap_open/openr into two pairs of routines, relation_open(r) and heap_open(r). The relation_open routines make no tests on relkind and so can be used to open anything that has a pg_class entry. The heap_open routines are wrappers that add a relkind test to preserve their established behavior. Use the relation_open routines in several places that had various kluge solutions for opening rels that might be either heap or index rels. Also, remove the old 'heap stats' code that's been superseded by Jan's stats collector, and clean up some inconsistencies in error reporting between the different types of ALTER TABLE.
Diffstat (limited to 'src/backend/commands/rename.c')
-rw-r--r--src/backend/commands/rename.c17
1 files changed, 4 insertions, 13 deletions
diff --git a/src/backend/commands/rename.c b/src/backend/commands/rename.c
index c65cfcc5519..42abe24f138 100644
--- a/src/backend/commands/rename.c
+++ b/src/backend/commands/rename.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.59 2001/10/25 05:49:25 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.60 2001/11/02 16:30:29 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -258,19 +258,10 @@ renamerel(const char *oldrelname, const char *newrelname)
return; /* all done... */
/*
- * Instead of using heap_openr(), do it the hard way, so that we can
- * rename indexes as well as regular relations.
- */
- targetrelation = RelationNameGetRelation(oldrelname);
-
- if (!RelationIsValid(targetrelation))
- elog(ERROR, "Relation \"%s\" does not exist", oldrelname);
-
- /*
- * Grab an exclusive lock on the target table, which we will NOT
+ * Grab an exclusive lock on the target table or index, which we will NOT
* release until end of transaction.
*/
- LockRelation(targetrelation, AccessExclusiveLock);
+ targetrelation = relation_openr(oldrelname, AccessExclusiveLock);
reloid = RelationGetRelid(targetrelation);
relkind = targetrelation->rd_rel->relkind;
@@ -278,7 +269,7 @@ renamerel(const char *oldrelname, const char *newrelname)
/*
* Close rel, but keep exclusive lock!
*/
- heap_close(targetrelation, NoLock);
+ relation_close(targetrelation, NoLock);
/*
* Flush the relcache entry (easier than trying to change it at