Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qBBHF-0003qE-Rt for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Jun 2023 09:34:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qBBHD-00056s-Tg for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Jun 2023 09:34:23 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qBBHD-00056j-FM for pgsql-hackers@lists.postgresql.org; Mon, 19 Jun 2023 09:34:23 +0000 Received: from mail-oo1-xc2d.google.com ([2607:f8b0:4864:20::c2d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qBBHA-0031xx-Nn for pgsql-hackers@lists.postgresql.org; Mon, 19 Jun 2023 09:34:22 +0000 Received: by mail-oo1-xc2d.google.com with SMTP id 006d021491bc7-55e11f94817so1725357eaf.2 for ; Mon, 19 Jun 2023 02:34:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687167259; x=1689759259; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=wrBLxyYo75PJPCv4z5C/Yv1HWcURl5153CYT4xO31T4=; b=paV4X5l2SznzaNenjolWQsb5Go5V5OgWL1YKR0/UrwRD6xig+cfHXy/LhhhEs+O7Ol RxKC6gPxs7uEDSY2tsv0f+CKVF2dso9r+JrFsco6hHIKkA8hoP93PndZKsLkNPV/TN8/ kmOijyFcJNvQQXAu0f+V6qd0jg21KhqjCvArT4W1BJJfHbAsCnEK0UpvkZmuTVSZ1/f2 M40q6ocb9lrpTYFKVXBpi4/X34bVGW+n53jUpj3JeGYsFmcoBXILFt3jPNn0VFQ5sfpJ gvRMUrd5aMP6+5TfTG1DLIjuGR1RV9x8Oz4eNnu46EF66Dm+FNYAcPdZHUNX7TtsqqcP spaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687167259; x=1689759259; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wrBLxyYo75PJPCv4z5C/Yv1HWcURl5153CYT4xO31T4=; b=NPL1RDlEt3Fm5VT+jMG8c1dfVlwHGR/8Au7cNljhfEu/sntEMnyugRrx+SRVzZwCfk 0rpYJZplJaiQs1BjswCJGHzgZYIHQs0RxSgFT/ZczNzuKupp7QMopYcaZ7TQR2bNHNxV dnisPrySxK9rSxwbA1Jhs/TkUY6Jexd8TPvcakt7gHq99cz2sjzyDGrSLAkp7mtk6mle GT0MsUsb831g7/1mmXy9dDJyxU3zDq0jRjaVC7VNmJkgOg0q5Ph6JS1xQUtm2GfZCv7f 1aC4fK91LdPY+eD5/3+8Rn7Hcz5pvYbcVGIgXzFzkQW1NLXPHnf5p5wNVffxUFyBjlzg OppA== X-Gm-Message-State: AC+VfDzczwKeaPgMECzA6Y0lVi9L/xzivPHQIvbsxxXm37Mn33z2Ah98 si1nqR3N1FTWnnB4yOYzFjmssUS0U1jNjmx4CYA= X-Google-Smtp-Source: ACHHUZ7F0Y6DxxINXm5C2sQ+uh5DxF/3/L3yaC/2FXckCER+rjhBax7HrDIenqiJ8Yb0hHs/nTDkvQMtZWHRCmZX/wA= X-Received: by 2002:a4a:e64f:0:b0:55e:3fe1:9e72 with SMTP id q15-20020a4ae64f000000b0055e3fe19e72mr1891551oot.9.1687167259302; Mon, 19 Jun 2023 02:34:19 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Amit Kapila Date: Mon, 19 Jun 2023 15:04:07 +0530 Message-ID: Subject: Re: Support logical replication of DDLs To: shveta malik Cc: Michael Paquier , "Wei Wang (Fujitsu)" , "Yu Shi (Fujitsu)" , vignesh C , "Zhijie Hou (Fujitsu)" , Ajin Cherian , Runqi Tian , Peter Smith , Tom Lane , li jie , Dilip Kumar , Alvaro Herrera , Masahiko Sawada , Japin Li , rajesh singarapu , PostgreSQL Hackers , Zheng Li Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Jun 16, 2023 at 4:01=E2=80=AFPM shveta malik wrote: > > With these changes, I hope the patch-set is somewhat easier to review. > Few comments: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 1. +static Jsonb * +deparse_CreateStmt(Oid objectId, Node *parsetree) { ... + /* PERSISTENCE */ + appendStringInfoString(&fmtStr, "CREATE %{persistence}s TABLE"); + new_jsonb_VA(state, NULL, NULL, false, 1, + "persistence", jbvString, + get_persistence_str(relation->rd_rel->relpersistence)); Do we need to add key/value pair if get_persistence_str() returns an empty string in the default deparsing mode? Won't it be somewhat inconsistent with other objects? 2. +static JsonbValue * +new_jsonb_VA(JsonbParseState *state, char *parentKey, char *fmt, + bool createChildObj, int numobjs,...) +{ + va_list args; + int i; + JsonbValue val; + JsonbValue *value =3D NULL; + + /* + * Insert parent key for which we are going to create value object here. + */ + if (parentKey) + insert_jsonb_key(state, parentKey); + + /* Set up the toplevel object if not instructed otherwise */ + if (createChildObj) + pushJsonbValue(&state, WJB_BEGIN_OBJECT, NULL); + + /* Set up the "fmt" */ + if (fmt) + fmt_to_jsonb_element(state, fmt); I think it would be better to handle parentKey, childObj, and fmt in the callers as this function doesn't seem to be the ideal place to deal with those. I see that in some cases we already handle those in the callers. It is bit confusing in which case callers need to deal vs. the cases where we need to deal here. 3. +static Jsonb * +deparse_AlterSeqStmt(Oid objectId, Node *parsetree) { ... + + new_jsonb_VA(state, NULL, "ALTER SEQUENCE %{identity}D %{definition: }s", + false, 0); Is there a need to call new_jsonb_VA() just to insert format? Won't it better to do this in the caller itself? 4. The handling for if_not_exists appears to be different in deparse_CreateSeqStmt() and deparse_CreateStmt(). I think the later one is correct and we should do that in both places. That means probably we can't have the entire format key in the beginning of deparse_CreateSeqStmt(). 5. + /* + * Check if table elements are present, if so, add them. This function + * call takes care of both the check and addition. + */ + telems =3D insert_table_elements(state, &fmtStr, relation, + node->tableElts, dpcontext, objectId, + false, /* not typed table */ + false); /* not composite */ Would it be better to name this function to something like add_table_elems_if_any()? If so, we can remove second part of the comment: "This function call takes care of both the check and addition." as that would be obvious from the function name. 6. + /* + * Check if table elements are present, if so, add them. This function + * call takes care of both the check and addition. + */ + telems =3D insert_table_elements(state, &fmtStr, relation, + node->tableElts, dpcontext, objectId, + false, /* not typed table */ + false); /* not composite */ + + /* + * If no table elements added, then add empty "()" needed for 'inherit' + * create table syntax. Example: CREATE TABLE t1 () INHERITS (t0); + */ + if (!telems) + appendStringInfoString(&fmtStr, " ()"); In insert_table_elements(), sometimes we access system twice for each of the columns and this is to identify the above case where no elements are present. Would it be better if simply for zero element object array in this case and detect the same on the receiving side? If this is feasible then we can simply name the function as add_table_elems/add_table_elements. Also, in this context, can we change the variable name telems to telems_present to make it bit easy to follow. 7. It would be better if we can further split the patch to move Alter case into a separate patch. That will help us to focus on reviewing Create/Drop in detail. --=20 With Regards, Amit Kapila.