RE: Support logical replication of DDLs

From: "Zhijie Hou (Fujitsu)" <houzj(dot)fnst(at)fujitsu(dot)com>
To: shveta malik <shveta(dot)malik(at)gmail(dot)com>
Cc: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, vignesh C <vignesh21(at)gmail(dot)com>, Ajin Cherian <itsajin(at)gmail(dot)com>, "Wei Wang (Fujitsu)" <wangw(dot)fnst(at)fujitsu(dot)com>, Runqi Tian <runqidev(at)gmail(dot)com>, Peter Smith <smithpb2250(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, li jie <ggysxcq(at)gmail(dot)com>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, Japin Li <japinli(at)hotmail(dot)com>, rajesh singarapu <rajesh(dot)rs0541(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Zheng Li <zhengli10(at)gmail(dot)com>
Subject: RE: Support logical replication of DDLs
Date: 2023-04-25 03:57:59
Message-ID: OS0PR01MB57167AB450D6B3C5FF2C90EF94649@OS0PR01MB5716.jpnprd01.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On Thursday, April 20, 2023 8:39 PM shveta malik <shveta(dot)malik(at)gmail(dot)com> wrote:
> On Thu, Apr 20, 2023 at 2:28 PM shveta malik <shveta(dot)malik(at)gmail(dot)com>
> wrote:
> >
> > On Thu, Apr 20, 2023 at 9:11 AM shveta malik <shveta(dot)malik(at)gmail(dot)com>
> wrote:
> >>
> >> On Mon, Apr 17, 2023 at 5:32 PM Zhijie Hou (Fujitsu)
> >> <houzj(dot)fnst(at)fujitsu(dot)com> wrote:
> >> >
> >> > Attach the new version patch set which include the following changes:
> >> Few comments for ddl_deparse.c in patch dated April17:
> >>
> > Few comments for ddl_json.c in the patch dated April17:
> >

Comments from [1]

> 1) append_format_string()
> I think we need to have 'Assert(sub_fmt)' here like we have it in all
> other similar functions (append_bool_object, append_object_object,
> ...)

Added.

>
> 2) append_object_to_format_string()
> here we have code piece :
> if (sub_fmt == NULL || tree->fmtinfo == NULL)
> return sub_fmt;
> but sub_fmt will never be null when we reach this function as all its
> callers assert for null sub_fmt. So that means when tree->fmtinfo is
> null, we end up returning sub_fmt as it is, instead of extracting
> object name from that. Is this intended?

No, removed this check and added an Assert for tree->fmtinfo as the caller
should not pass a NULL fmtinfo when using this function.

>
> 3) We can remove extra spaces after full-stop in the comment below
> /*
> * Deparse a ColumnDef node within a typed table creation. This is simpler
> * than the regular case, because we don't have to emit the type declaration,
> * collation, or default. Here we only return something if the column is being
> * declared NOT NULL.
> ...
> deparse_ColumnDef_typed()

Removed.

>
> 5) deparse_AlterRelation()
> We have below variable initialized to false in the beginning
> 'bool istype = false;'
> And then we have many conditional codes using the above, eg: istype ?
> "ATTRIBUTE" : "COLUMN". We are not changing 'istype' anywhere and it
> is hard-coded in the beginning. It means there are parts of code in
> this function which will never be htt (written for 'istype=true' case)
> , so why do we need this variable and conditional code around it?

Removed.

>
> 6) There are plenty of places where we use 'append_not_present'
> without using 'append_null_object'.
> Do we need to have 'append_null_object' along with
> 'append_not_present' at these places?

I think we can remove append_null_object and replace it with a
append_format_string as the null object is unnecessary. And I moved these logic
to a separate patch and extended the append_not_present to automatically add a
format string.

>
>
> 7) deparse_utility_command():
> Rather than inject --> Rather than injecting

Fixed

~~~~
Comments from [2]

> 1) expand_jsonval_string()
> I think we need to assert if jsonval is neither jbvString nor jbvBinary.

Added.

> 2) expand_jsonval_strlit()
> same here, assert if not jbvString (like we do in expand_jsonval_number and expand_jsonval_identifier > etc)
>

Added.

> 6)expand_fmt_recursive():
> value = findJsonbValueFromContainer(container, JB_FOBJECT, &key);
> Should this 'value' be freed at the end like we do at all other places in this file?

Added.

~~~~
Comments from [3]

>
> Few more comments, mainly for event_trigger.c in the patch dated April17:
>
> 1)EventTriggerCommonSetup()
> + pub_funcoid = LookupFuncName(pubfuncname, 0, NULL, true);
>
> This is the code where we have special handling for ddl-triggers. Here we are
> passing 'missing_ok' as true, so shouldn't we check pub_funcoid against
> 'InvalidOid' ?
>
>
> 2) EventTriggerTableInitWriteEnd()
>
> + if (stmt->objtype == OBJECT_TABLE)
> + {
> + parent = currentEventTriggerState->currentCommand->parent;
> + pfree(currentEventTriggerState->currentCommand);
> + currentEventTriggerState->currentCommand = parent; } else {
> + MemoryContext oldcxt;
> + oldcxt = MemoryContextSwitchTo(currentEventTriggerState->cxt);
> + currentEventTriggerState->currentCommand->d.simple.address =
> address;
> + currentEventTriggerState->commandList =
> + lappend(currentEventTriggerState->commandList,
> + currentEventTriggerState->currentCommand);
> +
> + MemoryContextSwitchTo(oldcxt);
> + }
> +}
>
> It will be good to add some comments in the 'else' part. It is not very much
> clear what exactly we are doing here and for which scenario.

I moved these codes to different patches but haven’t addressed comments.
I will address this in next version.

>
>
> 3) EventTriggerTableInitWrite()
>
> + if (!currentEventTriggerState)
> + return;
> +
> + /* Do nothing if no command was collected. */ if
> + (!currentEventTriggerState->currentCommand)
> + return;
>
> Is it possible that when we reach here no command is collected yet? I think this
> can happen only for the case when commandCollectionInhibited is true. If so,
> above can be modified to:
>
> if (!currentEventTriggerState ||
> currentEventTriggerState->commandCollectionInhibited)
> return;
> Assert(currentEventTriggerState->currentCommand != NULL);
>
> This will make the behaviour and checks consistent across similar functions in
> this file.

I am not sure if we should check commandCollectionInhibited at this function,
because normally this was only checked at command collection
function(EventTriggerCollectSimpleCommand, EventTriggerAlterTableStart).

>
>
> 4) EventTriggerTableInitWriteEnd()
> Here as well, we can have the same assert as below:
> Assert(currentEventTriggerState->currentCommand != NULL);
> 'currentEventTriggerState' and 'commandCollectionInhibited' checks are
> already present.

Added.

>
> 5) logical_replication.sgml:
> + 'This is especially useful if you have lots schema changes over time that
> need replication.'
>
> lots schema --> lots of schema

Fixed.

Thanks Shveta for helping address comments.

Aport from above comments, I splitted the code related to verbose
mode to a separate patch. And here is the new version patch set.

[1] https://www.postgresql.org/message-id/CAJpy0uDb2mDJtLNFXzUY4911qRZOvj6Q8pu4xFh4BMYBeOSPow%40mail.gmail.com
[2] https://www.postgresql.org/message-id/CAJpy0uAA0SQ0kPA5bXmrW%3D32p0bwFCifoKb5OSgteTjGggEkLA%40mail.gmail.com
[3] https://www.postgresql.org/message-id/CAJpy0uB7f2GxPNor5iTT-30JuD-p-gvnsMZG9tiiHN%2BDHJj0RQ%40mail.gmail.com

Best Regards,
Hou zj

Attachment Content-Type Size
ddl-replication-2023_04_25.tar.gz application/x-gzip 145.2 KB

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jagmohan Kaintura 2023-04-25 10:44:27 Re: murmur3 hash binary data migration from Oracle to PostgreSQL
Previous Message Jeffrey Walton 2023-04-25 03:22:11 Re: murmur3 hash binary data migration from Oracle to PostgreSQL

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2023-04-25 04:23:25 Re: Add two missing tests in 035_standby_logical_decoding.pl
Previous Message Thomas Munro 2023-04-25 03:41:06 Re: seemingly useless #include recently added