Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1umnkA-003s5c-1I for pgsql-hackers@arkaria.postgresql.org; Fri, 15 Aug 2025 06:16:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1umnk8-00D6SQ-FM for pgsql-hackers@arkaria.postgresql.org; Fri, 15 Aug 2025 06:16:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1umnk8-00D6SI-5L for pgsql-hackers@lists.postgresql.org; Fri, 15 Aug 2025 06:16:48 +0000 Received: from mail-lj1-x22d.google.com ([2a00:1450:4864:20::22d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1umnk5-000s0h-2q for pgsql-hackers@lists.postgresql.org; Fri, 15 Aug 2025 06:16:48 +0000 Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-333f8f02afaso14398481fa.1 for ; Thu, 14 Aug 2025 23:16:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755238604; x=1755843404; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=/kXzHNOo5jAX/gxoodTlHpCBuuF9NESD7j9UvS3aY20=; b=Wd7dy2Pimd9XC3/hPl1UqEC8IRIOPun6huohtXmEkbLZwuUVUgJJ/g4kZ0TyIjwP5a Nc12l1jyXHPmnWW++A5y7gqVRQlUuWTDFdqPiNnWlSPrEuqGDCtS6r6lILqjl3odx6Tu Mqu9ltLIUh24T8jiDA0orLesl/wNMgZ9cerAOi6Dee9W49mN1HYHEEMyWbnSpicuxcmC o/neik46xCBo5yQfZFlde4h8LuVwwPtKJtneqnPiSPi58PiCpEYVO6F4t7faiOO46aui 04zeoDKvakxuq66BN5sbJ0nBtEeY/RGy7hy/wx2uj789HtA+8hB9+CQ8zo3AKAFArUO/ sEBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755238604; x=1755843404; h=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=/kXzHNOo5jAX/gxoodTlHpCBuuF9NESD7j9UvS3aY20=; b=iyA69j7iD1vYiVJckf0FkTkgdpVAplYSPjjDGXNHA2SbMjTyscBsafqVBXeDj2aUn9 v6OEBGPSFOy5I9F15aRHolsTK6wIZLaydvNWtKPBbLJUst8azjSXlskF7521OK9bxPpe QRlTOKfv1eu5KgDN1DLVpwlQ6De0xc1neOU1uZqLizZ6Dj8eo6rfLyuu4XDprfcoT5su XB8kqOZMASdvmNA0kyo8ZaBZZ/Q5M/MQ1MCviJBUGxE3olw2CoKIPnjOuQnxejgsauWc r6EomLJF6EQB6XpPc3yo+IfBiskMaRMrhmLWHru1ze8t2SwDWLd7A1mueaQ6gwW7+0uC cBFQ== X-Forwarded-Encrypted: i=1; AJvYcCUrWrfTnEvVz3fQzPM/RzcMfkwudrNj01pbr9S0eVw/W2un2T4WwLnsiAXGc0HoZLJDAcWHZOmvnsGbysys@lists.postgresql.org X-Gm-Message-State: AOJu0Yz+zsRT+3zHOnp/t/b2p9KEDpb66RcwrQ2vhTL9Xib8jN1EhUe9 KBv5aQ8CjGu9XSbaROkZn4IZZ8MlEpbrmYIgYZjQQZp/vWqjRxufVVz5TxaogCX6d51K8Wm7oih rblfKKPkPj1g4KrzxT+qE7XM0CTztGOI= X-Gm-Gg: ASbGnctJ9I04pyW83238vptIEmGPnZ+B0hax56uHhmhTVSwNalOahS+BInBet/PIUR6 edogYL6nOJusvpLOMqDJIJ7u4E11yLChdANhfRo0BpgVJBd6tabvqp/rEJRBeCEdJIyuiJiEiCz d+bMmZ7yd6vIZDrRqi0VabhQ4igRYJS5MWtsq5mDTpYSdLlYZZGe9141R7+pOJBiOCGCTiD7QPE ikqrOL8DO8DmQfMBhSnSOTv75orEktiLuJXMGI= X-Google-Smtp-Source: AGHT+IHLnvAiSxQnxn4o85PGBv9aYF5Ws7Mh2VU+/h5dJpUJAIJ6oRKZUsUC6EiIRtcftZnsSrkyEUO9nxhgssBQn7M= X-Received: by 2002:a05:651c:1108:20b0:332:57b8:92e1 with SMTP id 38308e7fff4ca-3340982b104mr1758151fa.11.1755238604026; Thu, 14 Aug 2025 23:16:44 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Kirill Reshke Date: Fri, 15 Aug 2025 11:16:32 +0500 X-Gm-Features: Ac12FXxsESqhAtuDz9junIxalMKK8KqEYEPtQgoTtWl-0Wajdx0kLPDhXxbnlBk Message-ID: Subject: Re: Skipping schema changes in publication To: Peter Smith Cc: Shlok Kyal , Amit Kapila , "Zhijie Hou (Fujitsu)" , vignesh C , YeXiu <1518981153@qq.com>, Ian Lawrence Barwick , Bharath Rupireddy , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi On Fri, 15 Aug 2025 at 05:53, Peter Smith wrote: > 1. > bool isnull = true; > - Datum whereClauseDatum; > - Datum columnListDatum; > + Datum datum; > > I know you did not write the code, but that "isnull = true" is > redundant, and seems kind of misleading because it will always be > re-assigned before it is used. People are not generally excited about refactoring code they did not change. This makes patch to have more review cycles, and less probable to actually being committed. If we are really wedded with this change, this could be a separate thread. > ~~~ > > 2. > /* Load the WHERE clause for this table. */ > - whereClauseDatum = SysCacheGetAttr(PUBLICATIONRELMAP, rftuple, > - Anum_pg_publication_rel_prqual, > - &isnull); > + datum = SysCacheGetAttr(PUBLICATIONRELMAP, rftuple, > + Anum_pg_publication_rel_prqual, > + &isnull); > if (!isnull) > - oldrelwhereclause = stringToNode(TextDatumGetCString(whereClauseDatum)); > + oldrelwhereclause = stringToNode(TextDatumGetCString(datum)); > > /* Transform the int2vector column list to a bitmap. */ > - columnListDatum = SysCacheGetAttr(PUBLICATIONRELMAP, rftuple, > - Anum_pg_publication_rel_prattrs, > - &isnull); > + datum = SysCacheGetAttr(PUBLICATIONRELMAP, rftuple, > + Anum_pg_publication_rel_prattrs, > + &isnull); > + > + if (!isnull) > + oldcolumns = pub_collist_to_bitmapset(NULL, datum, NULL); > + > + /* Load the prexcept flag for this table. */ > + datum = SysCacheGetAttr(PUBLICATIONRELMAP, rftuple, > + Anum_pg_publication_rel_prexcept, > + &isnull); > > if (!isnull) > - oldcolumns = pub_collist_to_bitmapset(NULL, columnListDatum, NULL); > + oldexcept = DatumGetBool(datum); > > Use consistent spacing. Either do or don't (I prefer don't) put a > blank line between the pairs of "datum =" and "if (!isnull)". Avoid > having a mixture. > > ====== > src/bin/psql/describe.c > > addFooterToPublicationOrTableDesc: > > 3. > +/* > + * If is_tbl_desc is true add footer to table description else add footer to > + * publication description. > + */ > +static bool > +addFooterToPublicationOrTableDesc(PQExpBuffer buf, const char *footermsg, > + bool as_schema, printTableContent *const cont, > + bool is_tbl_desc) > > 3a. > Since you are changing this anyway, I think it would be better to keep > those boolean params together (at the end). > > ~ > > 3b. > It seems a bit mixed up calling this addFooterToPublicationOrTableDesc > but having the variable 'is_tbl_desc', because it seems more natural > to me to read left to right, so the logical order of everything here > should be pub desc then table desc. In other words, use boolean > 'is_pub_desc' instead of 'is_tbl_desc'. Also, I think that 'as_schema' > thing is kind of a *subset* of the publication description, so it > makes more sense for that to come last too. > > e.g. > CURRENT > addFooterToPublicationOrTableDesc(buf, footermsg, as_schema, cont, is_tbl_desc) > SUGGESTION > addFooterToPublicationOrTableDesc(buf, cont, footermsg, is_pub_desc, as_schema) > > ~ > > 3c > While you are changing things, maybe also consider changing that > 'as_schema' name because I did not understand what "as" means. Perhaps > rename like 'pub_schemas', or 'only_show_schemas' or something better > (???). > > ~~~ > > 4. > + PGresult *res; > + int count = 0; > + int i = 0; > + int col = is_tbl_desc ? 0 : 1; > + > + res = PSQLexec(buf->data); > + if (!res) > + return false; > + else > + count = PQntuples(res); > + > > 4a. > Assignment count = 0 is redundant. > > ~ > > 4b. > Remove the 'i' declaration here. Declare it in the "for" loop later. > > ~ > > 4c. > The "else" is not required. If 'res' was not good, you already returned. > > ~~~ > > 5. > + if (as_schema) > + printfPQExpBuffer(buf, " \"%s\"", PQgetvalue(res, i, 0)); > + else > + { > + if (is_tbl_desc) > + printfPQExpBuffer(buf, " \"%s\"", PQgetvalue(res, i, col)); > + else > + printfPQExpBuffer(buf, " \"%s.%s\"", PQgetvalue(res, i, 0), > + PQgetvalue(res, i, col)); > > This function is basically either (a) a footer for a table description > or (b) a footer for a publication description. And that all hinges on > the boolean 'is_tbl_desc'. Therefore, it seems more natural for the > main condition to be "if (is_tbl_desc)" here. > > This turned everything inside out. PSA: a top-up patch to show a way > to do this. Perhaps my implementation is a bit verbose, but OTOH it > seems easier to understand. Anyway, see what you think... > + 1 > > 6. > + /*--------------------------------------------------- > + * Publication/ table description columns: > + * [0]: schema name (nspname) > + * [col]: table name (relname) / publication name (pubname) > + * [col + 1]: row filter expression (prqual), may be NULL > + * [col + 2]: column list (comma-separated), may be NULL > + * [col + 3]: except flag ("t" if EXCEPT, else "f") > + *--------------------------------------------------- > > I've modified this comment slightly so I could understand it better. > See if you agree. For me that's equal. lets see what other people think -- Best regards, Kirill Reshke