aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-08-25 19:08:44 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-08-25 19:08:44 +0000
commit5a94a5fd0b026f5503eac244bdff5c408e82834c (patch)
treea28f031f0a5edfe5b082cd2760f9ecaa55ffb436
parent08e72a644af745cd01314f8440e6d5f0334b1917 (diff)
downloadpostgresql-5a94a5fd0b026f5503eac244bdff5c408e82834c.tar.gz
postgresql-5a94a5fd0b026f5503eac244bdff5c408e82834c.zip
Fix brain fade in DefineIndex(): it was continuing to access the table's
relcache entry after having heap_close'd it. This could lead to misbehavior if a relcache flush wiped out the cache entry meanwhile. In 8.2 there is a very real risk of CREATE INDEX CONCURRENTLY using the wrong relid for locking and waiting purposes. I think the bug is only cosmetic in 8.0 and 8.1, because their transgression is limited to using RelationGetRelationName(rel) in an ereport message immediately after heap_close, and there's no way (except with special debugging options) for a cache flush to occur in that interval. Not quite sure that it's cosmetic in 7.4, but seems best to patch anyway. Found by trying to run the regression tests with CLOBBER_CACHE_ALWAYS enabled. Maybe we should try to do that on a regular basis --- it's awfully slow, but perhaps some fast buildfarm machine could do it once in awhile.
-rw-r--r--src/backend/commands/indexcmds.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index dbbbc376e00..5408eda8ee1 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.114 2003/10/02 06:34:03 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.114.2.1 2007/08/25 19:08:44 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -112,8 +112,6 @@ DefineIndex(RangeVar *heapRelation,
relationId = RelationGetRelid(rel);
namespaceId = RelationGetNamespace(rel);
- heap_close(rel, NoLock);
-
/*
* Verify we (still) have CREATE rights in the rel's namespace.
* (Presumably we did when the rel was created, but maybe not
@@ -251,6 +249,8 @@ DefineIndex(RangeVar *heapRelation,
ComputeIndexAttrs(indexInfo, classObjectId, attributeList,
relationId, accessMethodName, accessMethodId);
+ heap_close(rel, NoLock);
+
index_create(relationId, indexRelationName,
indexInfo, accessMethodId, classObjectId,
primary, isconstraint, allowSystemTableMods);