Re: relhassubclass and partitioned indexes - Mailing list pgsql-hackers

From Amit Langote
Subject Re: relhassubclass and partitioned indexes
Date
Msg-id 223ce956-01e1-7685-0fdc-82cce6b84a00@lab.ntt.co.jp
Whole thread Raw
In response to Re: relhassubclass and partitioned indexes  (Michael Paquier <michael@paquier.xyz>)
Responses Re: relhassubclass and partitioned indexes  (Alvaro Herrera <alvherre@2ndquadrant.com>)
List pgsql-hackers
Hi,

On 2018/10/22 11:09, Michael Paquier wrote:
> On Fri, Oct 19, 2018 at 06:46:15PM +0900, Amit Langote wrote:
>> Thanks.  Attached a patch to set relhassubclass when an index partition is
>> added to a partitioned index.
> 
> Thanks, committed after adding a test with ALTER TABLE ONLY, and
> checking upgrades as well as ATTACH partition for ALTER INDEX and ALTER
> TABLE.  In all cases the same code paths are taken.

Thank you for committing with those changes.  I didn't know about create
index on "only".

>>      /* update pg_inherits, if needed */
>>      if (OidIsValid(parentIndexRelid))
>> +    {
>>          StoreSingleInheritance(indexRelationId, parentIndexRelid, 1);
>>  
>> +        /* Also, set the parent's relhassubclass. */
>> +        SetRelationHasSubclass(parentIndexRelid, true);
>> +    }
> 
> Calling SetRelationHasSubclass() updates pg_class for this parent
> relation.  We would need CommandCounterIncrement() if the tuple gets
> updated, but that's not the case as far as I checked for all code paths
> where this gets called.  This would be seen immediately by the way..

I assume you're talking about avoiding getting into a situation that
results in "ERROR: tuple concurrently updated".

Afaics, acquire_inherited_sample_rows() "does" perform CCI, because as the
comment says the parent's pg_class row may already have been updated in
that case:

     /* CCI because we already updated the pg_class row in this command */
     CommandCounterIncrement();
     SetRelationHasSubclass(RelationGetRelid(onerel), false);

In all the other case, SetRelationHasSubclass() seems to be the first time
that the parent's pg_class row is updated.

Thanks,
Amit



pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: relhassubclass and partitioned indexes
Next
From: Michael Paquier
Date:
Subject: Re: pgsql: Avoid duplicate XIDs at recovery when building initialsnapshot