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 1u1drC-005eZa-GJ for pgsql-hackers@arkaria.postgresql.org; Mon, 07 Apr 2025 04:13:11 +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 1u1drA-009N24-Vg for pgsql-hackers@arkaria.postgresql.org; Mon, 07 Apr 2025 04:13:09 +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 1u1drA-009N1w-GO for pgsql-hackers@lists.postgresql.org; Mon, 07 Apr 2025 04:13:09 +0000 Received: from mail.postgrespro.ru ([93.174.132.70]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u1dr8-003pnM-1x for pgsql-hackers@lists.postgresql.org; Mon, 07 Apr 2025 04:13:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1743999185; bh=P1P8GVf2kguhmssfzHW5prKLKPP99VWWWY9FlF4zH3I=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=CW84upuQaEzamqUJZsq+R3T9BVDBACWLzQD7n8HFd+ecOPVMYgCdBGEeza5fZXmhb FFQNs3LD3naDaidL2RTbqUTiUMci035QUgrbCgk3+UsRhZpuV1MpXXiuZpPtjz/Amh UCyCZdse39F928D+LuwfNzKdoRYQ3MS+6/p3hj9S+zdASPRg8ASYX9nwGdElBQuxcB +YqqYbBzYVgJViQicIkedL/1UT/Uig7cZ0qvJZZdSeTqaraElBHp72CrTMfrVAxdZl oTUYK21nf1t5n/xI1FJKF6fElwEzT0sZVpQXinM9ApIoeQgSGnbbPK1rwMvimxHYyc JaYj1Ex9uJ8CQ== Received: from [172.30.48.58] (unknown [93.174.131.138]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: s.tatarintsev@postgrespro.ru) by mail.postgrespro.ru (Postfix/465) with ESMTPSA id 3938C602AA; Mon, 7 Apr 2025 07:13:05 +0300 (MSK) Content-Type: multipart/alternative; boundary="------------DT9MqFBxCqAXH4YOSF3tp5Qb" Message-ID: Date: Mon, 7 Apr 2025 11:13:04 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Restrict publishing of partitioned table with a foreign table as partition To: =?UTF-8?Q?=C3=81lvaro_Herrera?= , Shlok Kyal Cc: vignesh C , pgsql-hackers@lists.postgresql.org References: <202504062027.tqmabk2h353o@alvherre.pgsql> Content-Language: en-US From: Sergey Tatarintsev In-Reply-To: <202504062027.tqmabk2h353o@alvherre.pgsql> X-KSMG-AntiPhishing: NotDetected X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.1.0.7854, bases: 2025/04/07 03:33:00 #27860952 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------DT9MqFBxCqAXH4YOSF3tp5Qb Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 07.04.2025 03:27, Álvaro Herrera пишет: > On 2025-Apr-01, Shlok Kyal wrote: > >> I have modified the comment in create_publication.sgml and also added >> comment in the restrictions section of logical-replication.sgml. >> I have also added a more detailed explanation in comment of >> 'check_foreign_tables' >> >> I have attached the updated v11 patch. > Sadly I don't have time to describe the changes proposed here right now, > but I'll do that early tomorrow. (Some minor changes are still needed, > particularly the comments to publication_check_foreign_parts which are > mostly unchanged from what your patch has. I'll do another review round > tomorrow.) > Hello! I looked at the latest patch again and found one more place for list_free(). Also look at additional test case: diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index 51e463c112b..7fcc191feb9 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -442,6 +442,7 @@ GetPubPartitionOptionRelations(List *result, PublicationPartOpt pub_partopt,                         result = lappend_oid(result, partOid);                 } +               list_free(all_parts);         }         else                 result = lappend_oid(result, relid); diff --git a/src/test/regress/sql/publication.sql b/src/test/regress/sql/publication.sql index 49c9d98b668..e56aebc397a 100644 --- a/src/test/regress/sql/publication.sql +++ b/src/test/regress/sql/publication.sql @@ -1296,6 +1296,14 @@ SELECT pubname, tablename FROM pg_publication_tables WHERE schemaname in ('sch3'  -- foreign partition  ALTER PUBLICATION pub1 SET (publish_via_partition_root); +CREATE SCHEMA sch5; +CREATE SCHEMA sch6; +CREATE TABLE sch6.tmain(id int) PARTITION BY RANGE(id); +CREATE TABLE sch5.part1 PARTITION OF sch6.tmain FOR VALUES FROM (0) TO (10) PARTITION BY RANGE(id); +CREATE FOREIGN TABLE sch6.part2 PARTITION OF sch5.part1 FOR VALUES FROM (0) TO (5) SERVER fdw_server; +CREATE PUBLICATION pub4 FOR TABLES IN SCHEMA sch5 WITH (publish_via_partition_root); +SELECT pubname, tablename FROM pg_publication_tables WHERE pubname = 'pub4' ORDER BY pubname, tablename; +  DROP PUBLICATION pub1;  DROP PUBLICATION pub2;  DROP PUBLICATION pub3; I think this is a wrong assumption: ScanKeyInit(&key[keycount++], Anum_pg_class_relispartition, BTEqualStrategyNumber, F_BOOLEQ, BoolGetDatum(false)); In this case sch5.part1 is partitioned table, but it also partition of table in different schema -- With best regards, Sergey Tatarintsev, PostgresPro --------------DT9MqFBxCqAXH4YOSF3tp5Qb Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
07.04.2025 03:27, Álvaro Herrera пишет:
On 2025-Apr-01, Shlok Kyal wrote:

I have modified the comment in create_publication.sgml and also added
comment in the restrictions section of logical-replication.sgml.
I have also added a more detailed explanation in comment of
'check_foreign_tables'

I have attached the updated v11 patch.
Sadly I don't have time to describe the changes proposed here right now,
but I'll do that early tomorrow.  (Some minor changes are still needed,
particularly the comments to publication_check_foreign_parts which are
mostly unchanged from what your patch has.  I'll do another review round
tomorrow.)

Hello!

I looked at the latest patch again and found one more place for list_free(). Also look at additional test case:

diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index 51e463c112b..7fcc191feb9 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -442,6 +442,7 @@ GetPubPartitionOptionRelations(List *result, PublicationPartOpt pub_partopt,                           result = lappend_oid(result, partOid);                 } +               list_free(all_parts);         }         else                 result = lappend_oid(result, relid); diff --git a/src/test/regress/sql/publication.sql b/src/test/regress/sql/publication.sql index 49c9d98b668..e56aebc397a 100644 --- a/src/test/regress/sql/publication.sql +++ b/src/test/regress/sql/publication.sql @@ -1296,6 +1296,14 @@ SELECT pubname, tablename FROM pg_publication_tables WHERE schemaname in ('sch3'  -- foreign partition  ALTER PUBLICATION pub1 SET (publish_via_partition_root);   +CREATE SCHEMA sch5; +CREATE SCHEMA sch6; +CREATE TABLE sch6.tmain(id int) PARTITION BY RANGE(id); +CREATE TABLE sch5.part1 PARTITION OF sch6.tmain FOR VALUES FROM (0) TO (10) PARTITION BY RANGE(id); +CREATE FOREIGN TABLE sch6.part2 PARTITION OF sch5.part1 FOR VALUES FROM (0) TO (5) SERVER fdw_server; +CREATE PUBLICATION pub4 FOR TABLES IN SCHEMA sch5 WITH (publish_via_partition_root); +SELECT pubname, tablename FROM pg_publication_tables WHERE pubname = 'pub4' ORDER BY pubname, tablename; +  DROP PUBLICATION pub1;  DROP PUBLICATION pub2;  DROP PUBLICATION pub3;

I think this is a wrong assumption:

ScanKeyInit(&key[keycount++], Anum_pg_class_relispartition, BTEqualStrategyNumber, F_BOOLEQ, BoolGetDatum(false));

In this case sch5.part1 is partitioned table, but it also partition of table in different schema

-- 
With best regards,
Sergey Tatarintsev, 
PostgresPro
--------------DT9MqFBxCqAXH4YOSF3tp5Qb--