RE: Selectively invalidate caches in pgoutput module - Mailing list pgsql-hackers

From Hayato Kuroda (Fujitsu)
Subject RE: Selectively invalidate caches in pgoutput module
Date
Msg-id OSCPR01MB14966206D8490B0EC5E7B6AAEF5C82@OSCPR01MB14966.jpnprd01.prod.outlook.com
Whole thread Raw
In response to Re: Selectively invalidate caches in pgoutput module  (Amit Kapila <amit.kapila16@gmail.com>)
List pgsql-hackers
Dear Amit,

> > When the ALTER PUBLICATION command is executed, all entries in
> RelationSyncCache
> > will be discarded anyway. This mechanism works well but is sometimes not
> efficient.
> > For example, when the ALTER PUBLICATION DROP TABLE is executed,
> > 1) the specific entry in RelationSyncCache will be removed, and then
> > 2) all entries will be discarded twice.
> >
> 
> In (2) Why twice? Is it because we call
> rel_sync_cache_publication_cb() first for PUBLICATIONRELMAP and then
> for PUBLICATIONOID via publication_invalidation_cb()?

This part was not correct. I considered that ALTER PUBLICATION DROP TABLE also
invalidated the pg_publication syscache, but it would not do. So...the command
firstly invalidate a specific entry, and then invalidate all entries once.

> > This happens because the pgoutput plugin registers both RelcacheCallback
> > (rel_sync_cache_relation_cb) and SyscacheCallback
> (publication_invalidation_cb,
> > rel_sync_cache_publication_cb). Then, when ALTER PUBLICATION
> ADD/SET/DROP is executed,
> > both the relation cache of added tables and the syscache of pg_publication_rel
> and
> > pg_publication are invalidated.
> > The callback for the relation cache will remove an entry from the hash table, and
> > syscache callbacks will look up all entries and invalidate them. However,
> AFAICS
> > does not need to invalidate all of them.
> >
> 
> IIUC, you want to say in the above case only (1) would be sufficient, right?

Right, this is a main aim of this proposal.

> Is it possible to see the impact? I guess if there are a large number
> of relations (or partitions), then all will get invalidated even if
> one relation is added/dropped from the publication; if so, this should
> impact the performance.

Agreed. I'm planning to do and share results. Please wait...

> For Rename/Owner, can we use a new invalidation instead of using
> relcache invalidation, as that can impact other sessions for no
> benefit? IIUC, changing the other properties of publication like
> dropping the table requires us to invalidate even the corresponding
> relcache entry because it contains the publication descriptor
> (rd_pubdesc). See RelationBuildPublicationDesc().

Attached patchset implemented with the approach.
0001 contains only part to avoid whole cache invalidation, for ADD/SET/DROP command.
0002 introduces new type of invalidation message which only invalidates caches on
the decoding plugin. Better name is very welcome.
0003 uses the mechanism to avoid discarding relcache for RENAME/OWNER case.

Best regards,
Hayato Kuroda
FUJITSU LIMITED


Attachment

pgsql-hackers by date:

Previous
From: Evgeny
Date:
Subject: Re: Elimination of the repetitive code at the SLRU bootstrap functions.
Next
From: Jakub Wartak
Date:
Subject: Re: FileFallocate misbehaving on XFS