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:
@@ -338,6 +338,22 @@ AlterObjectRename_internal(Relation rel, Oid objectId, const char *new_name)
|
||||
|
||||
InvokeObjectPostAlterHook(classId, objectId, 0);
|
||||
|
||||
/* Do post catalog-update tasks */
|
||||
if (classId == PublicationRelationId)
|
||||
{
|
||||
Form_pg_publication pub = (Form_pg_publication) GETSTRUCT(oldtup);
|
||||
|
||||
/*
|
||||
* Invalidate relsynccache entries.
|
||||
*
|
||||
* Unlike ALTER PUBLICATION ADD/SET/DROP commands, renaming a
|
||||
* publication does not impact the publication status of tables. So,
|
||||
* we don't need to invalidate relcache to rebuild the rd_pubdesc.
|
||||
* Instead, we invalidate only the relsyncache.
|
||||
*/
|
||||
InvalidatePubRelSyncCache(pub->oid, pub->puballtables);
|
||||
}
|
||||
|
||||
/* Release memory */
|
||||
pfree(values);
|
||||
pfree(nulls);
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user