RE: [BUG]Invalidate relcache when setting REPLICA IDENTITY

From: "houzj(dot)fnst(at)fujitsu(dot)com" <houzj(dot)fnst(at)fujitsu(dot)com>
To: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, "tanghy(dot)fnst(at)fujitsu(dot)com" <tanghy(dot)fnst(at)fujitsu(dot)com>
Subject: RE: [BUG]Invalidate relcache when setting REPLICA IDENTITY
Date: 2021-11-11 12:01:33
Message-ID: OS0PR01MB5716714BC4EA96EB207C768B94949@OS0PR01MB5716.jpnprd01.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thursday, November 11, 2021 5:36 PM houzj(dot)fnst(at)fujitsu(dot)com wrote:
> On Thur, Nov 11, 2021 12:08 PM Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> wrote:
> > On Thu, Nov 11, 2021 at 7:07 AM houzj(dot)fnst(at)fujitsu(dot)com
> <houzj(dot)fnst(at)fujitsu(dot)com> wrote:
> > >
> > > On Wed, Nov 10, 2021 7:29 PM Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
> wrote:
> > > >
> > > > I don't understand the purpose of idx_b in the above test case,
> > > > why is it required to reproduce the problem?
> > > > @@ -15488,6 +15488,7 @@ relation_mark_replica_identity(Relation
> > > > rel,
> > char
> > > > ri_type, Oid indexOid,
> > > > CatalogTupleUpdate(pg_index, &pg_index_tuple->t_self,
> > pg_index_tuple);
> > > > InvokeObjectPostAlterHookArg(IndexRelationId, thisIndexOid, 0,
> > > > InvalidOid, is_internal);
> > > > + CacheInvalidateRelcache(rel);
> > > >
> > > > CatalogTupleUpdate internally calls heap_update which calls
> > > > CacheInvalidateHeapTuple(), why is that not sufficient for invalidation?
> > >
> > > I think it's because the bug happens only when changing REPLICA
> > > IDENTITY
> > index
> > > from one(idx_a) to another one(idx_b).
> > >
> >
> > Okay, but do we need to invalidate the rel cache each time the dirty
> > flag is set? Can't we do it once outside the foreach index loop? I
> > think we can record whether to do relcache invalidation in a new
> > boolean variable need_rel_inval or something like that. Also, it is
> > better if you can add a comment on the lines of: "Invalidate the
> > relcache for the table so that after we commit all sessions will
> > refresh the table's replica identity index before attempting any
> > update on the table.".
>
> I agree.
>
> Attach the new version fix patch which move the invalidation out of the loop and
> addressed the comments[1] for the testcases.

Also attach the patches for back branch and remove some unnecessary
changes from pgindent.

Best regards,
Hou zj

Attachment Content-Type Size
PG12-0001-Invalidate-relcache-when-setting-REPLICA-IDENTITY.patch application/octet-stream 5.0 KB
PG11-0001-Invalidate-relcache-when-setting-REPLICA-IDENTITY.patch application/octet-stream 5.1 KB
PG10-0001-Invalidate-relcache-when-setting-REPLICA-IDENTITY.patch application/octet-stream 5.1 KB
PG14-0001-Invalidate-relcache-when-setting-REPLICA-IDENTITY.patch application/octet-stream 5.1 KB
PG13-0001-Invalidate-relcache-when-setting-REPLICA-IDENTITY.patch application/octet-stream 5.2 KB
v2-HEAD-0001-Invalidate-relcache-when-setting-REPLICA-IDENTITY.patch application/octet-stream 5.2 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrey Borodin 2021-11-11 12:17:23 Re: 2021-11-11 release announcement draft
Previous Message Shay Rojansky 2021-11-11 11:05:22 Re: Should AT TIME ZONE be volatile?