Re: Logical Replication - revisit `is_table_publication` function implementation - Mailing list pgsql-hackers

From vignesh C
Subject Re: Logical Replication - revisit `is_table_publication` function implementation
Date
Msg-id CALDaNm0nLdBKJVHVvvOnY_5mkVg20=OL18fdjA5+KZ3GhPB=TQ@mail.gmail.com
Whole thread
In response to Logical Replication - revisit `is_table_publication` function implementation  (Peter Smith <smithpb2250@gmail.com>)
Responses Re: Logical Replication - revisit `is_table_publication` function implementation
List pgsql-hackers
On Tue, 7 Apr 2026 at 12:32, Peter Smith <smithpb2250@gmail.com> wrote:
>
> Hi, after confirming my understanding of pg_publication_rel [1], I
> revisited some logical replication internal functions.
>
> Specifically.
> * The `is_table_publication` function is for checking if the
> publication has a clause like "FOR TABLE t1".
> * The `is_schema_publication` function is for checking if the
> publication has a clause like "FOR TABLES IN SCHEMA s1".
>
> Notice that neither of these ("FOR TABLE", "FOR TABLES IN SCHEMA")
> clauses are possible simultaneously with "FOR ALL TABLES".
>
> And we can readily discover if "FOR ALL TABLES" (aka `puballtables`)
> is present from the pubform.
>
> We can use this to optimise and simplify the implementations of the
> `is_schema_publication` and `is_table_publication` functions.
>
> PSA patch v1.
>
> AFAICT, the result is:
> - less code + simpler logic. e.g. is_table_publication does not check
> 'prexcept' anymore
> - more efficient. e.g. skips unnecessary scanning when puballtables is true.
> - more consistent. e.g., both functions are now almost identical.
>
> Thoughts?

I'm not sure if this additional check is sufficient in case of
is_schema_publication. Checking only puballtables can exclude FOR ALL
TABLES, but it still cannot distinguish regular table publications,
empty publications, or sequence publications. In all of those cases,
we still need to check pg_publication_namespace. And also why just
check for puballtables why not to check for puballsequences
+is_schema_publication(Form_pg_publication pubform)
 {
  Relation pubschsrel;
  ScanKeyData scankey;
  SysScanDesc scan;
  HeapTuple tup;
- bool result = false;
+ bool result;
+
+ /* FOR TABLES IN SCHEMA cannot coexist with FOR ALL TABLES. */
+ if (pubform->puballtables)
+ return false;

Regards,
Vignesh



pgsql-hackers by date:

Previous
From: Fujii Masao
Date:
Subject: Re: Use SIGTERM instead of SIGUSR1 for slotsync worker to exit during promotion?
Next
From: Amit Kapila
Date:
Subject: Re: Adding REPACK [concurrently]