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 1uWR5H-00Domc-Op for pgsql-hackers@arkaria.postgresql.org; Tue, 01 Jul 2025 02:50:59 +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 1uWR5F-0039mp-Py for pgsql-hackers@arkaria.postgresql.org; Tue, 01 Jul 2025 02:50:58 +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 1uWR5F-0039mX-9G for pgsql-hackers@lists.postgresql.org; Tue, 01 Jul 2025 02:50:58 +0000 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uWR5D-00512W-2U for pgsql-hackers@lists.postgresql.org; Tue, 01 Jul 2025 02:50:57 +0000 Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-54b10594812so3272081e87.1 for ; Mon, 30 Jun 2025 19:50:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751338254; x=1751943054; darn=lists.postgresql.org; 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=oG24LkO9f7QmNtkg94Q732FUuOPpJYN55uvbnLzYdRQ=; b=HL3juvFtSmysnMVCz7Hsz8eMMsZj+/8Onht+JpLOE3r9+hwbo1fVAweFkRrd1vt9xn lmYqB0Shhr5ke7Ou4t8DsH1WOxDO0EivTI81+2qP185m4B6tNVr9PvRQSfa5oZfP23Pp bS/3Ci67Z+JRZqGWadqXJz853zLacJ+KOx4KznQILs4PEeZo4N0tvf2id9gPiOOws8wu v415UhGhmk01zXtcR6vqDRbR2ua4OiR0FZMJKoTt27lryweIrrfzCc5mT2owwF2Y5or7 pgFuUyibX9EnGT2yv9sH4jQzkjZFwJeyk8BeB+qAGOC2QImw/Hg4t9nA3I/8655ErYNq 3EbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751338254; x=1751943054; 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=oG24LkO9f7QmNtkg94Q732FUuOPpJYN55uvbnLzYdRQ=; b=LULIBqDSS4+aaAoVovvWUryqLQZZvTW61xb+XpNuqZlIh1p4wuRkJU64/PDnf+bwrz vj/Zzm0i0inrQ3jTZWzahEWjG+ouseszJvJPRWoBA6P3HIkT28pFWMjuFEl0vVclwtSM pBPtZ5zEi4MufwD2L8fs3Sjv1uFX4m1Sp0stSDBZSm3fLMinJb5BoyfreFQ8B1eG5ezh F5aWolKKxtRDHAojVPeBpypRdp2glCUQF2rOJ1TfB0wkrRPJCx1rTv5tBBeLOq01xALN 08jyaxvSSzXHDL/+Um4I0BUw0t4PrI9Sn7gX9btY5GcN8YaIhms1miN5vuhRnNEOyZac XgoQ== X-Forwarded-Encrypted: i=1; AJvYcCWYeVOgB1t1B/5pUpmKnOuC7aA0/Pkacyw1oy68cW5R+KE2quef+oNbPIwubmsR6zPdmSbXHe4pvPEOBz1S@lists.postgresql.org X-Gm-Message-State: AOJu0YxZZZBJnwgPFCYzQML74Q7G37U3Qco0XgqIg9g5K9Jlk7QiFgN/ 9KNBF+NIvG2+zuTBOgxWoF2nStanM9+fO2NY15W6W37B+6cLqY238FPTCacVndmsExoHmcb8QxL 0HQ1TkgAw7Svvb5KMT3A+kZUDDhowK+8= X-Gm-Gg: ASbGncsqMwHqgScfysjEA4GBXWw1jExKMD+HlwNRo3AANldsJ4h4PeAbrBtn20bISD2 Cfpr7ZhOIlV6ysgodTSi9vxsSn8wVzZzqWtbLzFIJy+p7EfTF4M9bMUI0YfBStaJQ2FQ2Qry/SP dpOFI2kqr15zNBFymYck/2kOhd2MAVrkZbwWTAbDDxR4rD X-Google-Smtp-Source: AGHT+IHYYt7WV+NXjrT6siRW1thQiSTlkGNM5zHaVDRqoXt5MbkkRI12vUDFwC4c8HXErv9c2lG9C4yVJnNC2MyaoAQ= X-Received: by 2002:ac2:4f14:0:b0:553:2ff8:5e0b with SMTP id 2adb3069b0e04-5550ba0c994mr5626141e87.42.1751338253747; Mon, 30 Jun 2025 19:50:53 -0700 (PDT) MIME-Version: 1.0 References: <202505101759.6qlloepaeddl@alvherre.pgsql> In-Reply-To: From: Ajin Cherian Date: Tue, 1 Jul 2025 12:50:41 +1000 X-Gm-Features: Ac12FXx0YqrYRw7N945ZNhE_xjviZ6SFxFCcoctOMLX9kBlpm0YAlZlAKEQn2PA Message-ID: Subject: Re: Restrict publishing of partitioned table with a foreign table as partition To: Shlok Kyal Cc: Amit Kapila , =?UTF-8?Q?=C3=81lvaro_Herrera?= , vignesh C , Sergey Tatarintsev , pgsql-hackers@lists.postgresql.org 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 Mon, Jun 9, 2025 at 3:58=E2=80=AFPM Shlok Kyal wrote: > > On Wed, 4 Jun 2025 at 16:12, Ajin Cherian wrote: > > > > On Tue, May 20, 2025 at 2:33=E2=80=AFAM Shlok Kyal wrote: > > > > > > This approach seems better to me. I have created a patch with the > > > above approach. > > > > > > Thanks and Regards, > > > Shlok Kyal > > > > Some quick comments on the patch: > > 1. In doc/src/sgml/ref/create_subscription.sgml: > > + has partitioned table with foreign table as partition. If this sce= nario is > > + detected we ERROR is logged to the user. > > + > > + > > > > Should be: "If this scenario is detected an ERROR is logged to the > > user." (remove "we"). > > > > In src/backend/commands/subscriptioncmds.c: > > 2. The comment header: > > + * This function is in charge of detecting if publisher with > > + * publish_via_partition_root=3Dtrue publishes a partitioned table tha= t has a > > + * foreign table as a partition. > > > > Add "and throw an error if found" at the end of that sentence to > > correctly describe what the function does. > > > > 3. > > + appendStringInfoString(&cmd, > > + "SELECT DISTINCT P.pubname AS pubname " > > + "from pg_catalog.pg_publication p, LATERAL = " > > + "pg_get_publication_tables(p.pubname) gpt, = LATERAL " > > + "pg_partition_tree(gpt.relid) gt JOIN > > pg_catalog.pg_foreign_table ft ON " > > + "ft.ftrelid =3D gt.relid WHERE p.pubviaroot > > =3D true AND p.pubname IN ("); > > > > use FROM rather than from to maintain SQL style consistency. > > > > 4. > > + errdetail_plural("The subscription being created on a > > publication (%s) with publish_via_root_partition =3D true and contains > > partitioned tables with foreign table as partition ", > > + "The subscription being created on > > publications (%s) with publish_via_root_partition =3D true and contains > > partitioned tables with foreign table as partition ", > > + list_length(publist), pubnames->data)= , > > > > I think you meant "publish_via_partition_root" here and not > > "publish_via_root_partition ". > > > > I have addressed all the comments and attached the updated patch. Hi Shlok, Some more comments: 1. + Replication is not supported for foreign tables. When used as partit= ions + of partitioned tables, publishing of the partitioned table is only al= lowed + if the publish_via_partition_root is set to + false. In patch: "When used as partitions of partitioned tables, publishing of the partitioned table is only allowed if the publish_via_partition_root is set to false. Change to: When foreign tables are used as partitions of partitioned tables, publishing of the partitioned table is only allowed if the publish_via_partition_root is set to false. 2. + + When using a subscription parameter copy_data =3D true, corresponding + publications are checked if it has publish_via_partition_root =3D true= and + has partitioned table with foreign table as partition. If this scenari= o is + detected an ERROR is logged to the user. + In patch: "When using a subscription parameter copy_data =3D true, ..." Change to: "When using the subscription parameter copy_data =3D true, ..." In patch: "and has partitioned table with foreign table as partition." Change to: "and has a partitioned table with a foreign table as its partiti= on" 3. + * check_publications_foreign_parts + * Check if the publications, on which subscriber is subscribing, publishe= s any + * partitioned table that has an foreign table as its partition and has + * publish_via_partition_root set as true. The check is performed only if + * copy_data is set as true for the subscription. In patch: "publishes any partitioned table that has an foreign table as its partition" Change to: "publishes any partitioned table that has a foreign table as its partition" 4. + * DML data changes are not published for data in foreign tables, + * and yet the tablesync worker is not smart enough to omit data from + * foreign tables when they are partitions of partitioned tables. change to:"Although DML changes to foreign tables are excluded from publication, the tablesync worker will still attempt to copy data from foreign table partitions during initial table synchronization." 5. + * When publish_via_partition_root is false, each partition published for + * replication is listed individually in pg_subscription_rel, and we + * don't add partitions that are foreign tables, so this check is not + * needed. In patch: "so this check is not needed" Change to: "so this function is not called for such tables" 6. + errdetail_plural("The subscription being created on a publication (%s) with publish_via_partition_root =3D true and contains partitioned tables with foreign table as partition ", + "The subscription being created on publications (%s) with publish_via_partition_root =3D true and contains partitioned tables with foreign table as partition ", + list_length(publist), pubnames->data), Change to: "The subscription is for a publication (%s) with publish_via_partition_root =3D true but one of the partitioned tables has a foreign table as a partition" "The subscription is for publications (%s) with publish_via_partition_root =3D true but one of the partitioned tables has a foreign table as a partition" 7. + /* capture all publications that include this relation directly */ + puboids =3D list_concat(puboids, GetRelationPublications(rel->rd_i= d)); + schemaid =3D RelationGetNamespace(rel); + puboids =3D list_concat(puboids, GetSchemaPublications(schemaid)); + + /* and do the same for its ancestors, if any */ + ancestors =3D get_partition_ancestors(rel->rd_id); + foreach_oid(ancestor, ancestors) + { + puboids =3D list_concat(puboids, GetRelationPublications(ances= tor)); + schemaid =3D get_rel_namespace(ancestor); + puboids =3D list_concat(puboids, GetSchemaPublications(schemai= d)); + } + + /* Now check the publish_via_partition_root bit for each of those = */ + list_sort(puboids, list_oid_cmp); + list_deduplicate_oid(puboids); + foreach_oid(puboid, puboids) Why do we need to do all this logic for non partition foreign tables? Just directly throw an error for those tables and do this extra logic only for partitioned tables. 8. + pg_fatal("Your installation contains publications, which has foreign table which are partitions of published table.\n" + "A list of potentially-affected publications is in the file:\n" Change to: "Your installation contains publications, where one of the partitioned tables has a foreign table as a partition.\n" regards, Ajin Cherian Fujitsu Australia