Re: Heap lock levels for REINDEX INDEX CONCURRENTLY not quite right?

From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>, pgsql-hackers(at)postgresql(dot)org, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Subject: Re: Heap lock levels for REINDEX INDEX CONCURRENTLY not quite right?
Date: 2019-05-02 08:44:44
Message-ID: b434ada7-e121-cd30-3885-da88f7d072a2@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2019-04-30 17:17, Andres Freund wrote:
> indOid = RangeVarGetRelidExtended(indexRelation,
> concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock,
> 0,
> RangeVarCallbackForReindexIndex,
> (void *) &heapOid);
>
> doesn't pass concurrent-ness to RangeVarCallbackForReindexIndex(). Which
> then goes on to lock the table
>
> static void
> RangeVarCallbackForReindexIndex(const RangeVar *relation,
> Oid relId, Oid oldRelId, void *arg)
>
> if (OidIsValid(*heapOid))
> LockRelationOid(*heapOid, ShareLock);
>
> without knowing that it should use ShareUpdateExclusive. Which
> e.g. ReindexTable knows:
>
> /* The lock level used here should match reindex_relation(). */
> heapOid = RangeVarGetRelidExtended(relation,
> concurrent ? ShareUpdateExclusiveLock : ShareLock,
> 0,
> RangeVarCallbackOwnsTable, NULL);
>
> so there's a lock upgrade hazard.

Confirmed.

What seems weird to me is that the existing callback argument heapOid
isn't used at all. It seems to have been like that since the original
commit of the callback infrastructure. Therefore also, this code

if (relId != oldRelId && OidIsValid(oldRelId))
{
/* lock level here should match reindex_index() heap lock */
UnlockRelationOid(*heapOid, ShareLock);

in RangeVarCallbackForReindexIndex() can't ever do anything useful.

Patch to remove the unused code attached; but needs some checking for
this dubious conditional block.

Thoughts?

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachment Content-Type Size
0001-Remove-unused-argument-of-RangeVarCallbackForReindex.patch text/plain 2.1 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2019-05-02 08:56:52 Re: Unhappy about API changes in the no-fsm-for-small-rels patch
Previous Message Thomas Munro 2019-05-02 08:06:19 Re: How to estimate the shared memory size required for parallel scan?