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 1uoeib-007cmw-Th for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Aug 2025 09:02:55 +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 1uoeib-006bxn-8v for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Aug 2025 09:02:53 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uoeia-006bxf-S7 for pgsql-hackers@lists.postgresql.org; Wed, 20 Aug 2025 09:02:53 +0000 Received: from mail-oi1-x229.google.com ([2607:f8b0:4864:20::229]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uoeiY-000okA-2o for pgsql-hackers@lists.postgresql.org; Wed, 20 Aug 2025 09:02:52 +0000 Received: by mail-oi1-x229.google.com with SMTP id 5614622812f47-435de838484so4079755b6e.3 for ; Wed, 20 Aug 2025 02:02:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755680570; x=1756285370; 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=veoN4yxUpF1mkkxbsK05nuT4prBHAbbheP2xE+YkKVo=; b=VzyBW+SF7soZiep2KuK/BLktJwgLUTxP5CP54lQaUvniWhnSWSYSeGH/4CcjIbKMOi 6qEwEJU7PBvbGGSSo/9L09lxuUAbzTbvGQNnYBMCHPflWcMNjlLc/EyIvdLx0+x5WY8v Ff5waqbRObLp7rnVNptr1Kh6i6Bl3wIcjV6uQPQRd9Q+JfEobfVyCz0rm8kyNzo0I4e5 69mwthL+M5sSWIB0vsSl1GxziZnfnoud3+xu7+KWvpG7rmJHEXez3HVw435V/XAMuGmU 25XWESAMwwLfHXlfTEVITAaVmh+xut8ERsZUfRjfia+XBQOChVKZFxgWwbuxH4Psofr+ kgCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755680570; x=1756285370; 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=veoN4yxUpF1mkkxbsK05nuT4prBHAbbheP2xE+YkKVo=; b=gQY4oRFcBZ1IrckQ3DpCyxK3k+CE+n2fi6dnm4EDq0nvTeioCGisnrdrnlyroHVZI9 5zPB7WHR1DQ3vwdRB7BDe8nQPLMfPubUmZcjlO5sUM3OKZOdR9MFpX9Iwt+puxOJCIvc Wj0+T41PCfRcIgLfvxUG7p8Mc7yXIYvGqHsWtQ48+8kPqgEUJf/Q2VqFuy1eQiQVVXYl iJOjfoxm5SNzBA+Jfm6MSjngC+FMyhzDVds78zP5jO2wKfsdwOzeVZDdyU7wYt+Cqe/w lAf1bcrFgH4P+KbmQOOuat2yc6/ZahQXDIArpCNMEtkRpUJq/HIfSxIhFoSWPBcRIDSz hIbw== X-Forwarded-Encrypted: i=1; AJvYcCWW+1Vq9up3l/ANZiDuqzC7i28AbBszGOCRX5+UMLF9TRPlTvb7GRBeG5K+isvw9jHvVS+dPtuVk3SRqAJQ@lists.postgresql.org X-Gm-Message-State: AOJu0YzWMzRSO0RU65MfupwE8H/545DXILaHp0dt3JB5f/Z9sTxJz24H 3Op3Y5TnMQYm2/sp5pYxkWQ0QrtzABBrswh5Kd0MITXM9mOfYiiQ1UzqQ39QYTu7V8R4TLD6Qf1 5EdvHkUrRgypyv0PQCa2vW9jFRB1DWio= X-Gm-Gg: ASbGncvK3ECpLnyBWYcWlWiShcoTWV9PUuikFobfeJQFH/5EcI7k8QZS4B8JPDio8/L vS4/ucn8IZskB1eCUG+k/h4qLOMEsvOodoVpYSlUJHoBTohFA25+b1IZ+ZLgae7yTdNTqSNc2zx wzczVdaUTDPwrW6rMav/M3r+I5p9orHv34qWxmSJXOCG8LPOrN9Wcvx+leFfOuTM+acB3OhlALO yCO6QM4EA== X-Google-Smtp-Source: AGHT+IF0/oLwHhXMQG6vJv2PMksY46uVJIYihInNwISlUxphW9T6xPRZy02xxdbgRN6rKlKnqB2U09MrZmDvfmcA3zE= X-Received: by 2002:a05:6808:11c5:b0:406:6a21:524f with SMTP id 5614622812f47-4377208ccd3mr1264493b6e.19.1755680570100; Wed, 20 Aug 2025 02:02:50 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Shlok Kyal Date: Wed, 20 Aug 2025 14:32:38 +0530 X-Gm-Features: Ac12FXySP1n0ZjXRD_m_51qKfHVr2RkRnw-IdRmhgPO__AhLfOJvzt9vMDjL2ig Message-ID: Subject: Re: Skipping schema changes in publication To: Kirill Reshke Cc: Peter Smith , 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 Kirill, Thanks for reviewing the patch. On Fri, 15 Aug 2025 at 11:46, Kirill Reshke wrote: > > 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. > I also feel that we should create a new thread for the same. I have created a new thread. See [1]. > > > ~~~ > > > > 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 > Included these changes in the latest patch [2]. > > > > 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 > For now I have used the version shared by Peter. I felt it was more descriptive. [1] : https://www.postgresql.org/message-id/CANhcyEXHiCbk2q8%3Dbq3boQDyc8ac9fjgK-kkp5PdTYLcAOq80Q%40mail.gmail.com [2] : https://www.postgresql.org/message-id/CANhcyEUEMWSkTfGc7Q3B%2BUiOzSiOmOGLgK-%2BC5DXwtCGOnDBhg%40mail.gmail.com Thanks, Shlok Kyal