Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 75d091a

Browse files
committed
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.
1 parent 2116826 commit 75d091a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/backend/commands/indexcmds.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.161 2007/07/17 05:02:00 neilc Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.162 2007/08/25 19:08:19 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -428,8 +428,6 @@ DefineIndex(RangeVar *heapRelation,
428428
relationId, accessMethodName, accessMethodId,
429429
amcanorder, isconstraint);
430430

431-
heap_close(rel, NoLock);
432-
433431
/*
434432
* Report index creation if appropriate (delay this till after most of the
435433
* error checks)
@@ -441,6 +439,10 @@ DefineIndex(RangeVar *heapRelation,
441439
primary ? "PRIMARY KEY" : "UNIQUE",
442440
indexRelationName, RelationGetRelationName(rel))));
443441

442+
/* save lockrelid for below, then close rel */
443+
heaprelid = rel->rd_lockInfo.lockRelId;
444+
heap_close(rel, NoLock);
445+
444446
indexRelationId =
445447
index_create(relationId, indexRelationName, indexRelationId,
446448
indexInfo, accessMethodId, tablespaceId, classObjectId,
@@ -468,7 +470,6 @@ DefineIndex(RangeVar *heapRelation,
468470
* because there are no operations that could change its state while we
469471
* hold lock on the parent table. This might need to change later.
470472
*/
471-
heaprelid = rel->rd_lockInfo.lockRelId;
472473
LockRelationIdForSession(&heaprelid, ShareUpdateExclusiveLock);
473474

474475
CommitTransactionCommand();

0 commit comments

Comments
 (0)