Re: Support logical replication of DDLs

From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: Ajin Cherian <itsajin(at)gmail(dot)com>
Cc: Peter Smith <smithpb2250(at)gmail(dot)com>, vignesh C <vignesh21(at)gmail(dot)com>, Zheng Li <zhengli10(at)gmail(dot)com>, li jie <ggysxcq(at)gmail(dot)com>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, "houzj(dot)fnst(at)fujitsu(dot)com" <houzj(dot)fnst(at)fujitsu(dot)com>, 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>
Subject: Re: Support logical replication of DDLs
Date: 2023-02-10 11:06:52
Message-ID: CAA4eK1JGLCd+do-KurYrjnSxLwFNHf4bA7bL_r5Xc=ubVeVZpw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On Thu, Feb 9, 2023 at 3:25 PM Ajin Cherian <itsajin(at)gmail(dot)com> wrote:
>

Comments on 0001 and 0002
=======================
1.
* CREATE COLLATION
*/
ObjectAddress
-DefineCollation(ParseState *pstate, List *names, List *parameters,
bool if_not_exists)
+DefineCollation(ParseState *pstate, List *names, List *parameters,
+ bool if_not_exists, ObjectAddress *from_existing_collid)

I think it is better to expand function header comments to explain
return values especially from_existing_collid.

2.
+Form_pg_sequence_data
+get_sequence_values(Oid sequenceId)
+{
+ Buffer buf;
+ SeqTable elm;
+ Relation seqrel;
+ HeapTupleData seqtuple;
+ Form_pg_sequence_data seq;
+ Form_pg_sequence_data retSeq = palloc(sizeof(FormData_pg_sequence_data));
+
+ /* Open and AccessShareLock sequence */
+ init_sequence(sequenceId, &elm, &seqrel);

The comment above init_sequence() seems wrong to me. AFAICS, we
acquire RowExclusiveLock in init_sequence() via
lock_and_open_sequence(). Am, I missing anything?

3.
+get_sequence_values(Oid sequenceId)
...
...
+
+ if (pg_class_aclcheck(sequenceId, GetUserId(),
+ ACL_SELECT | ACL_UPDATE | ACL_USAGE) != ACLCHECK_OK)
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),

Why do we need to check UPDATE privilege just for reading the values?

4. I checked the callers of get_sequence_values and they just need
'last_val' but we still expose all values from Form_pg_sequence_data,
not sure if that is required. In deparse_CreateSeqStmt(), we use it to
append RESTART but the CREATE SEQUENCE syntax in docs doesn't have a
RESTART clause, so I am confused as to why the patch appends the same.
If it is really required then please add the comments for the same.

5. In deparse_CreateSeqStmt() and deparse_ColumnIdentity(), we open
SequenceRelationId, is that really required? Isn't locking the
sequence relation sufficient as is done by get_sequence_values()?
Also, I see that deparse_CreateSeqStmt() opens and locks the sequence
whereas deparse_ColumnIdentity() doesn't do the same. Then, we unlock
the relation in some cases but not in others (like get_sequence_values
uses NoLock whereas others release the lock while closing the rel).

6. In get_sequence_values(), we check the permissions whereas callers
just assume that it is done and don't check it while accessing the
sequence. This makes the code a bit unclear.

7. After seeing the above inconsistencies, I am thinking will it be
better to design get_sequence_values() such that it returns both
sequence parameters and last_val in a structure and the callers use
it. That would bit clean and avoid opening the relation multiple
times.

8.
+/*
+ * Return the given object type as a string.
+ * If isgrant is true, then this function is called
+ * while deparsing GRANT statement and some object
+ * names are replaced.
+ */
+const char *
+stringify_objtype(ObjectType objtype, bool isgrant)

Have an empty line after the Return line. The line length appears too short.

9. Similar to stringify_grant_objtype() and
stringify_adefprivs_objtype(), shall we keep the list of all
unsupported types in stringify_objtype()? That will help us to easily
identify which objects are yet not supported.

10. In pg_get_ruledef_detailed(), the code to form a string for qual
and action is mostly the same as what we have in make_ruledef(). I
think we can extract the common code into a separate function to avoid
missing the code updates at one of the places. I see that
'special_exprkind' is present in one place and not in other, it may be
that over time, we have added new things to deparse_context which
doesn't get updated in the patch. Also, I noticed that for
CMD_NOTHING, the patch just ignores the action whereas the core code
does append the definition. We should check whether such a difference
is required and if so, then add comments for the same.

--
With Regards,
Amit Kapila.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Masahiko Sawada 2023-02-10 14:52:41 Re: Support logical replication of DDLs
Previous Message GF 2023-02-10 10:20:51 Re: How to use the BRIN index properly?

Browse pgsql-hackers by date

  From Date Subject
Next Message Takamichi Osumi (Fujitsu) 2023-02-10 11:26:21 RE: Time delayed LR (WAS Re: logical replication restrictions)
Previous Message Jeroen Vermeulen 2023-02-10 10:32:00 Re: libpq: PQgetCopyData() and allocation overhead