From 5377ccbe2495b81c3b9fbd170841492098875998 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 31 May 2009 20:55:37 +0000 Subject: [PATCH] Update obsolete comment in index_drop(). When the comment was written, queries frequently took no lock at all on individual indexes. That's not true any more, but we still need lock on the parent table to make it safe to use cached lists of index OIDs. --- src/backend/catalog/index.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index a14c588cc6..c1001c0fac 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.315 2009/03/31 22:12:46 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.316 2009/05/31 20:55:37 tgl Exp $ * * * INTERFACE ROUTINES @@ -901,14 +901,13 @@ index_drop(Oid indexId) /* * To drop an index safely, we must grab exclusive lock on its parent - * table; otherwise there could be other backends using the index! - * Exclusive lock on the index alone is insufficient because another - * backend might be in the midst of devising a query plan that will use - * the index. The parser and planner take care to hold an appropriate - * lock on the parent table while working, but having them hold locks on - * all the indexes too seems overly expensive. We do grab exclusive lock - * on the index too, just to be safe. Both locks must be held till end of - * transaction, else other backends will still see this index in pg_index. + * table. Exclusive lock on the index alone is insufficient because + * another backend might be about to execute a query on the parent table. + * If it relies on a previously cached list of index OIDs, then it could + * attempt to access the just-dropped index. We must therefore take a + * table lock strong enough to prevent all queries on the table from + * proceeding until we commit and send out a shared-cache-inval notice + * that will make them update their index lists. */ heapId = IndexGetRelation(indexId); userHeapRelation = heap_open(heapId, AccessExclusiveLock);