aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-08-25 19:08:25 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-08-25 19:08:25 +0000
commit10f436225528ab795526f477bd963edfaf3ebaa6 (patch)
tree62f442f07fd4a3bbb3453f647a947f31d37e96c0 /src/backend
parentf94c9dbf22119e19af05c09e184fecee2d6adb41 (diff)
downloadpostgresql-10f436225528ab795526f477bd963edfaf3ebaa6.tar.gz
postgresql-10f436225528ab795526f477bd963edfaf3ebaa6.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.
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/commands/indexcmds.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index 5f54f66f591..87dec1909d8 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.149 2006/10/04 00:29:51 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.149.2.1 2007/08/25 19:08:25 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -423,8 +423,6 @@ DefineIndex(RangeVar *heapRelation,
relationId, accessMethodName, accessMethodId,
isconstraint);
- heap_close(rel, NoLock);
-
/*
* Report index creation if appropriate (delay this till after most of the
* error checks)
@@ -436,6 +434,10 @@ DefineIndex(RangeVar *heapRelation,
primary ? "PRIMARY KEY" : "UNIQUE",
indexRelationName, RelationGetRelationName(rel))));
+ /* save lockrelid for below, then close rel */
+ heaprelid = rel->rd_lockInfo.lockRelId;
+ heap_close(rel, NoLock);
+
indexRelationId =
index_create(relationId, indexRelationName, indexRelationId,
indexInfo, accessMethodId, tablespaceId, classObjectId,
@@ -463,7 +465,6 @@ DefineIndex(RangeVar *heapRelation,
* because there are no operations that could change its state while we
* hold lock on the parent table. This might need to change later.
*/
- heaprelid = rel->rd_lockInfo.lockRelId;
LockRelationIdForSession(&heaprelid, ShareUpdateExclusiveLock);
CommitTransactionCommand();