Kevin Grittner wrote:
> Simon Riggs wrote:
>> On 6 October 2012 00:56, Tom Lane <t...@sss.pgh.pa.us> wrote:
>  
>>> 2. DROP INDEX CONCURRENTLY doesn't bother to do
>>> TransferPredicateLocksToHeapRelation until long after it's
>>> invalidated the index. Surely that's no good? Is it even possible
>>> to do that correctly, when we don't have a lock that will prevent
>>> new predicate locks from being taken out meanwhile?
>> 
>> No idea there. Input appreciated.
 
> If the creation of a new tuple by insert or update would not
> perform the related index tuple insertion, and the lock has not yet
> been transfered to the heap relation, yes we have a problem.  Will
> take a look at the code.
> 
> Creation of new predicate locks while in this state has no bearing
> on the issue as long as locks are transferred to the heap relation
> after the last scan using the index has completed.
 
To put that another way, it should be done at a time when it is sure
that no query sees indisvalid = true and no query has yet seen
indisready = false.  Patch attached.  Will apply if nobody sees a
problem with it.

-Kevin
*** a/src/backend/catalog/index.c
--- b/src/backend/catalog/index.c
***************
*** 1316,1321 **** index_drop(Oid indexId, bool concurrent)
--- 1316,1326 ----
  	 * 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.
+ 	 *
+ 	 * All predicate locks on the index are about to be made invalid. Promote
+ 	 * them to relation locks on the heap. For correctness this must be done
+ 	 * after the index was last seen with indisready = true and before it is
+ 	 * seen with indisvalid = false.
  	 */
  	heapId = IndexGetRelation(indexId, false);
  	if (concurrent)
***************
*** 1349,1354 **** index_drop(Oid indexId, bool concurrent)
--- 1354,1361 ----
  		 */
  		indexRelation = heap_open(IndexRelationId, RowExclusiveLock);
  
+ 		TransferPredicateLocksToHeapRelation(userIndexRelation);
+ 
  		tuple = SearchSysCacheCopy1(INDEXRELID,
  									ObjectIdGetDatum(indexId));
  		if (!HeapTupleIsValid(tuple))
***************
*** 1438,1449 **** index_drop(Oid indexId, bool concurrent)
  		userHeapRelation = heap_open(heapId, ShareUpdateExclusiveLock);
  		userIndexRelation = index_open(indexId, AccessExclusiveLock);
  	}
! 
! 	/*
! 	 * All predicate locks on the index are about to be made invalid. Promote
! 	 * them to relation locks on the heap.
! 	 */
! 	TransferPredicateLocksToHeapRelation(userIndexRelation);
  
  	/*
  	 * Schedule physical removal of the files
--- 1445,1452 ----
  		userHeapRelation = heap_open(heapId, ShareUpdateExclusiveLock);
  		userIndexRelation = index_open(indexId, AccessExclusiveLock);
  	}
! 	else
! 		TransferPredicateLocksToHeapRelation(userIndexRelation);
  
  	/*
  	 * Schedule physical removal of the files
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to