]> granicus.if.org Git - postgresql/commitdiff
Fix brain fade in DefineIndex(): it was continuing to access the table's
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 25 Aug 2007 19:08:31 +0000 (19:08 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 25 Aug 2007 19:08:31 +0000 (19:08 +0000)
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.

src/backend/commands/indexcmds.c

index e0f094756c89f582333f6d98ca988428e8905f22..de9ddd258bd02b3704c4613ba330d8830c4ce8ec 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.134.2.2 2006/02/10 19:01:22 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.134.2.3 2007/08/25 19:08:31 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -365,8 +365,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)
@@ -378,6 +376,8 @@ DefineIndex(RangeVar *heapRelation,
                                  primary ? "PRIMARY KEY" : "UNIQUE",
                                  indexRelationName, RelationGetRelationName(rel))));
 
+       heap_close(rel, NoLock);
+
        index_create(relationId, indexRelationName, indexRelationId,
                                 indexInfo, accessMethodId, tablespaceId, classObjectId,
                                 primary, isconstraint,