IMO, the nested checking of opts.twophase in the ternary makes the
patch code unnecessarily hard to follow across combinations.

My suggestion is to implement it using more verbose, but easier-to-read code:

     /* Change system catalog accordingly */
if (sub->twophasestate == LOGICALREP_TWOPHASE_STATE_DISABLED)
{
    if (opts.twophase)
    {
        /* enable two_phase */
        values[Anum_pg_subscription_subtwophasestate - 1] =
            CharGetDatum(LOGICALREP_TWOPHASE_STATE_PENDING);
        replaces[Anum_pg_subscription_subtwophasestate - 1] = true;
    }
}
else if (!opts.twophase)
{
    /* disable two_phase */
    values[Anum_pg_subscription_subtwophasestate - 1] =
        CharGetDatum(LOGICALREP_TWOPHASE_STATE_DISABLED);
    replaces[Anum_pg_subscription_subtwophasestate - 1] = true;
}

~

This way also avoids redundant replacements like 'd' to 'd', 'p' to 'p', etc.

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


Reply via email to