1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-27 00:12:01 +03:00

Avoid invalidating all RelationSyncCache entries on publication rename.

On Publication rename, we need to only invalidate the RelationSyncCache
entries corresponding to relations that are part of the publication being
renamed.

As part of this patch, we introduce a new invalidation message to
invalidate the cache maintained by the logical decoding output plugin. We
can't use existing relcache invalidation for this purpose, as that would
unnecessarily cause relcache invalidations in other backends.

This will improve performance by building fewer relation cache entries
during logical replication.

Author: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Author: Shlok Kyal <shlok.kyal.oss@gmail.com>
Reviewed-by: Hou Zhijie <houzj.fnst@fujitsu.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Discussion: https://postgr.es/m/OSCPR01MB14966C09AA201EFFA706576A7F5C92@OSCPR01MB14966.jpnprd01.prod.outlook.com
This commit is contained in:
Amit Kapila
2025-03-13 09:03:45 +05:30
parent 75da2bece6
commit 3abe9dc188
10 changed files with 302 additions and 16 deletions

View File

@@ -491,6 +491,45 @@ pub_contains_invalid_column(Oid pubid, Relation relation, List *ancestors,
return *invalid_column_list || *invalid_gen_col;
}
/*
* Invalidate entries in the RelationSyncCache for relations included in the
* specified publication, either via FOR TABLE or FOR TABLES IN SCHEMA.
*
* If 'puballtables' is true, invalidate all cache entries.
*/
void
InvalidatePubRelSyncCache(Oid pubid, bool puballtables)
{
if (puballtables)
{
CacheInvalidateRelSyncAll();
}
else
{
List *relids = NIL;
List *schemarelids = NIL;
/*
* For partitioned tables, we must invalidate all partitions and
* itself. WAL records for INSERT/UPDATE/DELETE specify leaf tables as
* a target. However, WAL records for TRUNCATE specify both a root and
* its leaves.
*/
relids = GetPublicationRelations(pubid,
PUBLICATION_PART_ALL);
schemarelids = GetAllSchemaPublicationRelations(pubid,
PUBLICATION_PART_ALL);
relids = list_concat_unique_oid(relids, schemarelids);
/* Invalidate the relsyncache */
foreach_oid(relid, relids)
CacheInvalidateRelSync(relid);
}
return;
}
/* check_functions_in_node callback */
static bool
contain_mutable_or_user_functions_checker(Oid func_id, void *context)