[PATCH] Refactor parse_publication_options

Started by Miłosz Bieniek3 months ago4 messageshackers
Jump to latest
#1Miłosz Bieniek
bieniek.milosz@proton.me

Hi,
While reading the code related to creating subscriptions and publications for logical replication I found a difference between passing options to parse_subscription_options and parse_publication_options.
To parse_publication_options function we pass all options separately, while in parse_subscription_options we use SubOpts.
IMO the usage of a struct instead of each option separately seems cleaner.
I attached a patch that creates a PubOpts struct and uses it in all parse_publication_options occurrences.

--
Miłosz Bieniek

Attachments:

t253528_1
0001-Refactor-parse_publication_options.patchapplication/octet-stream; name=0001-Refactor-parse_publication_options.patchDownload+70-83
#2Peter Smith
smithpb2250@gmail.com
In reply to: Miłosz Bieniek (#1)
Re: [PATCH] Refactor parse_publication_options

On Mon, Aug 24, 2026 at 10:16 PM Miłosz Bieniek <milosz@bieniek.cc> wrote:

Hi,
While reading the code related to creating subscriptions and publications for logical replication I found a difference between passing options to parse_subscription_options and parse_publication_options.
To parse_publication_options function we pass all options separately, while in parse_subscription_options we use SubOpts.
IMO the usage of a struct instead of each option separately seems cleaner.
I attached a patch that creates a PubOpts struct and uses it in all parse_publication_options occurrences.

IIRC the introduction of SubOpt had become a necessity because there
was an excessive number of parameters to parse_subscription_options.
OTOH, publications have a lot fewer options than subscriptions, so
this patch to introduce PubOpts seems more a matter of code
consistency than necessity.

Anyway, +1 from me for attempting this, but I expect it could receive
pushback from the "if-it-aint-broke-dont-fix-it" people.

~~~

Meanwhile, here are some other review comments for patch 0001.

======

1.
+typedef struct PubOpts
+{
+ bool publish_given;
+ PublicationActions pubactions;
+ bool publish_via_partition_root_given;
+ bool publish_via_partition_root;
+ bool publish_generated_columns_given;
+ char publish_generated_columns;
+} PubOpts;

To make this more similar to SubOpts, then you should also remove
those `xxx_given` members and instead use a `specified_opts` bitmap
member and PUBOPT_xxx macros, exactly the same as SubOpts does.

~~~

parse_publication_options:

2.
+ /* Start out with cleared opts. */
+ memset(opts, 0, sizeof(PubOpts));
+
+ /* Set default values */
+ opts->publish_given = false;
+ opts->publish_via_partition_root_given = false;
+ opts->publish_generated_columns_given = false;

IMO it's unnecessary to assign these `xxx_given` members to false,
since you've only just done the memset 0.

======
Kind Regards,
Peter Smith.
Fujitsu Australia

#3Miłosz Bieniek
bieniek.milosz@proton.me
In reply to: Peter Smith (#2)
Re: [PATCH] Refactor parse_publication_options

Hi Peter, thanks for your review.

IIRC the introduction of SubOpt had become a necessity because there
was an excessive number of parameters to parse_subscription_options.
OTOH, publications have a lot fewer options than subscriptions, so
this patch to introduce PubOpts seems more a matter of code
consistency than necessity.

Anyway, +1 from me for attempting this, but I expect it could receive
pushback from the "if-it-aint-broke-dont-fix-it" people.

I understand that some people might not want to change working
code, but IMO it's worth the change for the sake of consistency.

~~~

Meanwhile, here are some other review comments for patch 0001.

======

1.
+typedef struct PubOpts
+{
+ bool publish_given;
+ PublicationActions pubactions;
+ bool publish_via_partition_root_given;
+ bool publish_via_partition_root;
+ bool publish_generated_columns_given;
+ char publish_generated_columns;
+} PubOpts;

To make this more similar to SubOpts, then you should also remove
those `xxx_given` members and instead use a `specified_opts` bitmap
member and PUBOPT_xxx macros, exactly the same as SubOpts does.

~~~

parse_publication_options:

2.
+ /* Start out with cleared opts. */
+ memset(opts, 0, sizeof(PubOpts));
+
+ /* Set default values */
+ opts->publish_given = false;
+ opts->publish_via_partition_root_given = false;
+ opts->publish_generated_columns_given = false;

IMO it's unnecessary to assign these `xxx_given` members to false,
since you've only just done the memset 0.

You're right. I made the v2 version more similar to SubOpts.

One thing I'm not so sure about is `IsSet` macro. I copied it from the 'subscriptionscmds.c',
but maybe it should be extracted to a header file?

Kind regards,
Miłosz Bieniek

Attachments:

t253528_3
v2-0001-Refactor-parse_publication_options.patchapplication/octet-stream; name=v2-0001-Refactor-parse_publication_options.patchDownload+81-84
#4Peter Smith
smithpb2250@gmail.com
In reply to: Miłosz Bieniek (#3)
Re: [PATCH] Refactor parse_publication_options

Patch v2 review comments:

1.
  Oid puboid;
  bool nulls[Natts_pg_publication];
  Datum values[Natts_pg_publication];
+ PubOpts opts;
  HeapTuple tup;
- bool publish_given;
- PublicationActions pubactions;
- bool publish_via_partition_root_given;
- bool publish_via_partition_root;
- bool publish_generated_columns_given;
- char publish_generated_columns;

Nit. Perhaps the PubOpts should come *after* the HeapTuple, just so
the nulls/values/tup all stay together like they were before.

~

Otherwise, the patch v2 LGTM

On Tue, Aug 25, 2026 at 7:43 PM Miłosz Bieniek <milosz@bieniek.cc> wrote:

...

One thing I'm not so sure about is `IsSet` macro. I copied it from the 'subscriptionscmds.c',
but maybe it should be extracted to a header file?

I would not worry about that for now. Wait to see if this patch gets
any support first.

======
Kind Regards,
Peter Smith
Fujitsu Australia