pgsql: Add target_relid parameter to pg_get_publication_tables().

From: Masahiko Sawada <msawada(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Add target_relid parameter to pg_get_publication_tables().
Date: 2026-04-02 18:35:19
Message-ID: E1w8Msw-002e44-0m@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Add target_relid parameter to pg_get_publication_tables().

When a tablesync worker checks whether a specific table is published,
it previously issued a query to the publisher calling
pg_get_publication_tables() and filtering the result by relid via a
WHERE clause. Because the function itself was fully evaluated before
the filter was applied, this forced the publisher to enumerate all
tables in the publication. For publications covering a large number of
tables, this resulted in expensive catalog scans and unnecessary CPU
overhead on the publisher.

This commit adds a new overloaded form of pg_get_publication_tables()
that accepts an array of publication names and a target table
OID. Instead of enumerating all published tables, it evaluates
membership for the specified relation via syscache lookups, using the
new is_table_publishable_in_publication() helper. This helper
correctly accounts for publish_via_partition_root, ALL TABLES with
EXCEPT clauses, schema publications, and partition inheritance, while
avoiding the overhead of building the complete published table list.

The existing VARIADIC array form of pg_get_publication_tables() is
preserved for backward compatibility. Tablesync workers use the new
two-argument form when connected to a publisher running PostgreSQL 19
or later.

Bump catalog version.

Reported-by: Marcos Pegoraro <marcos(at)f10(dot)com(dot)br>
Reviewed-by: Zhijie Hou <houzj(dot)fnst(at)fujitsu(dot)com>
Reviewed-by: Matheus Alcantara <matheusssilv97(at)gmail(dot)com>
Reviewed-by: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Reviewed-by: Peter Smith <smithpb2250(at)gmail(dot)com>
Reviewed-by: Hayato Kuroda <kuroda(dot)hayato(at)fujitsu(dot)com>
Reviewed-by: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Reviewed-by: Haoyan Wang <wanghaoyan20(at)163(dot)com>
Discussion: https://postgr.es/m/CAB-JLwbBFNuASyEnZWP0Tck9uNkthBZqi6WoXNevUT6+mV8XmA@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/fd7a25af11e2cad4f48ffc4e50f18644e657ed53

Modified Files
--------------
src/backend/catalog/pg_publication.c | 241 ++++++++++++++++++++++++----
src/backend/replication/logical/tablesync.c | 70 +++++---
src/include/catalog/catversion.h | 2 +-
src/include/catalog/pg_proc.dat | 13 +-
src/test/regress/expected/publication.out | 225 ++++++++++++++++++++++++++
src/test/regress/sql/publication.sql | 107 ++++++++++++
6 files changed, 606 insertions(+), 52 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Andrew Dunstan 2026-04-02 19:20:03 pgsql: Rename jsonpath method arg tokens
Previous Message Tom Lane 2026-04-02 16:20:51 pgsql: Harden astreamer tar parsing logic against archives it can't han