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 1uibIG-00DZYi-4d for pgsql-hackers@arkaria.postgresql.org; Sun, 03 Aug 2025 16:10:40 +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 1uibIF-00E104-3G for pgsql-hackers@arkaria.postgresql.org; Sun, 03 Aug 2025 16:10:39 +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 1uibIE-00E0zw-Og for pgsql-hackers@lists.postgresql.org; Sun, 03 Aug 2025 16:10:38 +0000 Received: from mail-oi1-x22a.google.com ([2607:f8b0:4864:20::22a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uibIC-000YKq-0P for pgsql-hackers@lists.postgresql.org; Sun, 03 Aug 2025 16:10:38 +0000 Received: by mail-oi1-x22a.google.com with SMTP id 5614622812f47-433f984817dso751414b6e.0 for ; Sun, 03 Aug 2025 09:10:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1754237434; x=1754842234; 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=92PKujy+NuJJnfC9cpo5MSKzV28DsvV/cxGsutStYM8=; b=WIjyKWTy/hkHo4gOiNfJoOWlHlhvnixAQ7amBHPHbDH8FjsYecY4WJDeJy2l8zHYix +jpwDJrjh5AjSorJBh9NovYyO9wEShYDUOIPqrhmMzVfpU7XJB/ikd/ohK4zaejtzfjW dKodolVjFhAA9kwF5wCHJ8dtD2SS5cqB8XT/UXzOIPxiX7z2bFChBWC5FXaqXjQLQmpF pmCarijX1wVm/+l0sWKqdr+iNZ86p+T8pzuU6q5wY49446YaCeEhITqsjx26a/R7Epcj lAHp9tVYmsg+Vpl7pOfX79pfkns4lXZRbd5lwDzSWGPi4GljU0EWby5asEsJ3PsQHMds 5aPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754237434; x=1754842234; 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=92PKujy+NuJJnfC9cpo5MSKzV28DsvV/cxGsutStYM8=; b=Uf7kkeo8Y9JuC6n3H1eiBmR/ONiPFXmfJHiYsKeVH7AAD+zzfJzPJBEv/robJHe5TV KeKFDcxEk4QFPbC4w0lYYfDUaldW0DYrU7w6PdwJL/xBrYq+n3g2tNI8zHdT3qMyCVeu IhfsOwawhrcZ0fIntuQ5Zc1yNJ+ZOrPN1bML+bLTCF2tAcy+cxhXOIwBkfZrwJLa42G9 zY0wdRAzLXGwVfevBPFOvw/COfZvDlQJrH7k5S5LCoN2SQkd48cJg3p/M8fykIl/yvJK 36puGGA7OWQksGdjixbxU1A83K/UCw7hokKNGF5pT9TqWpnIGFpEEdisFGlEGxeJbGdE ZXWg== X-Forwarded-Encrypted: i=1; AJvYcCUqsvaLkAgiWdxo+bXlWCMEtXRivEQX/4oNKQ5XLPW6iUleGG+lmeOxSgsWuGqpg7RLdqtT0gAs4prK2RUC@lists.postgresql.org X-Gm-Message-State: AOJu0YwxbBDJWnss1o8zQIt38fd63hn09qjP7BvcYwF8EgX7iWB6tYUx yMLI6H6L3Ng0YIpbp9CF2+pYjmzY9LzcseWdsEWxeoCZ3AIpSePS+c/AZ1wxw8Ew5GRQ/YNPdic aCMYWFFWoCSehJPvq+Z91m+ZRdHtMjZgW6okw X-Gm-Gg: ASbGncuco4oUEbLEP3r0dmwsBWr1Alo9mL0/a7oRmJ7nB6Je69Ehf5ftGO13LOt9VMs OUXaQ8B4gseS0dw2pj9X9yleTHokZGMSTjBw+gFhOkOtntCAbqFNAaG26kd8F0/15HcAV2Q3/Xj eLfveuPM+b+8fJYxsJiWaL5IC9fwviRUMwp/vIIOQFqAVroRlXe6k+Msv64a0AOAB+9bY51REH6 jwihTFD9iqr65BmzvSf X-Google-Smtp-Source: AGHT+IEWTO3XV750ZIvqJ8gpawPMk3tZX7bMoIxUuyBVSAOwXhKrRQXDpslt2+xP+1byTXDQQ1Q6NEaP3M1U+nG6BlM= X-Received: by 2002:a05:6808:bc2:b0:433:8abc:e574 with SMTP id 5614622812f47-433f0127969mr3510316b6e.0.1754237434404; Sun, 03 Aug 2025 09:10:34 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Shlok Kyal Date: Sun, 3 Aug 2025 21:40:22 +0530 X-Gm-Features: Ac12FXwyip_kF7iIkkHfqHjF1Ke9Y4VVgQUQ7DyXibbL6TyhSsiAxJOLKnTXq6g Message-ID: Subject: Re: Skipping schema changes in publication To: shveta malik 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" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 22 Jul 2025 at 14:29, shveta malik wrote: > > On Sat, Jul 19, 2025 at 4:17=E2=80=AFPM Shlok Kyal wrote: > > > > On Mon, 30 Jun 2025 at 16:25, shveta malik wro= te: > > > > > > Few more comments on 002: > > > > > > 5) > > > +GetAllTablesPublicationRelations(Oid pubid, bool pubviaroot) > > > { > > > > > > + List *exceptlist; > > > + > > > + exceptlist =3D GetPublicationRelations(pubid, PUBLICATION_PART_ALL)= ; > > > > > > > > > a) Here, we are assuming that the list provided by > > > GetPublicationRelations() will be except-tables list only, but there > > > is no validation of that. > > > b) We are using GetPublicationRelations() to get the relations which > > > are excluded from the publication. The name of function and comments > > > atop function are not in alignment with this usage. > > > > > > Suggestion: > > > We can have a new GetPublicationExcludeRelations() function for the > > > concerned usage. The existing logic of GetPublicationRelations() can > > > be shifted to a new internal-logic function which will accept a > > > 'except-flag' as well. Both GetPublicationRelations() and > > > GetPublicationExcludeRelations() can call that new function by passin= g > > > 'except-flag' as false and true respectively. The new internal > > > function will validate 'prexcept' against that except-flag passed and > > > will return the results. > > > > > I have made the above change. > > Thank You for the changes. > > 1) > But on rethinking, shall we make GetPublicationRelations() similar to : > > /* Gets list of publication oids for a relation that matches the except_f= lag */ > GetRelationPublications(Oid relid, bool except_flag) > > i.e. we can have a single function GetPublicationRelations() taking > except_flag and comment can say: 'Gets list of relation oids for a > publication that matches the except_flag.' > > We can get rid of GetPubIncludedOrExcludedRels() and > GetPublicationExcludeRelations(). > > Thoughts? > This seems reasonable to me. I have made the changes for the same. > > 2) > we can rename except_table to except_flag to be consistent with > GetRelationPublications() > > 3) > + if ((except_table && pubrel->prexcept) || !except_table) > + result =3D GetPubPartitionOptionRelations(result, pub_partopt, > + pubrel->prrelid); > > 3a) > In the case of '!except_table', we are not matching it with > 'pubrel->prexcept', is that intentional? > > 3 b) > Shall we simplify this similar to the changes in GetRelationPublications(= ) i.e. > if (except_table/flag =3D=3D pubrel->prexcept) > result =3D GetPubPartitionOptionRelations(...) > > > > > > > 6) > > > Before your patch002, GetTopMostAncestorInPublication() was checking > > > pg_publication_rel and pg_publication_namespace to find out if the > > > table in the ancestor-list is part of a given particular. Both > > > pg_publication_rel and pg_publication_namespace did not have the entr= y > > > "for all tables" publications. That means > > > GetTopMostAncestorInPublication() was originally not checking whether > > > the given puboid is an "for all tables" publication to see if a rel > > > belongs to that particular pub or not. I > > > > > > But now with the current change, we do check if pub is all-tables pub= , > > > if so, return relid and mark ancestor_level (provided table is not > > > part of the except list). IIUC, the result in 2 cases may be > > > different. Is that the intention? Let me know if my understanding is > > > wrong. > > > > > This is intentional, in function get_rel_sync_entry, we are setting > > pub_relid to the topmost published ancestor. In HEAD we are directly > > setting using: > > /* > > * If this is a FOR ALL TABLES publication, pick the partit= ion > > * root and set the ancestor level accordingly. > > */ > > if (pub->alltables) > > { > > publish =3D true; > > if (pub->pubviaroot && am_partition) > > { > > List *ancestors =3D get_partition_ancestors(r= elid); > > > > pub_relid =3D llast_oid(ancestors); > > ancestor_level =3D list_length(ancestors); > > } > > } > > In HEAD, we can directly use 'llast_oid(ancestors)' to get the topmost > > ancestor for case of FOR ALL TABLES. > > But with this proposal. This change will no longer be valid as the > > 'llast_oid(ancestors)' may be excluded in the publication. So, to > > handle this change was made in GetTopMostAncestorInPublication. > > > > > > Also, during testing with the partitioned table and > > publish_via_partition_root the behaviour of the current patch is as > > below: > > For example we have a partitioned table t1. It has partitions part1 > > and part2. Now consider the following cases: > > 1. with publish_via_partition_root =3D true > > I. If we create publication on all tables with EXCEPT t1, no data > > for t1, part1 or part2 is replicated. > > Okay. Agreed. > > > II. If we create publication on all tables with EXCEPT part1, > > data for all tables t1, part1 and part2 is replicated. > > Okay. Is this because part1 changes are replicated through t1 and > since t1 changes are not restricted, part1 changes will also not be > restricted? In other words, part1 was never published directly in the > first place and thus 'EXCEPT part1' has no meaning when > 'publish_via_partition_root' =3D true? IMO, it is in alignment with the > 'publish_via_partition_root' definition but it might not be that > intuitive for users. So shall we emit a WARNING: > > WARNING: Partition "part1" is excluded, but publish_via_partition_root > =3D true, so this will have no effect. > Thoughts? Your understanding is correct. I have added a WARNING for this case > > > 2. with publish_via_partition_root =3D false > > I. If we create publication on all tables with EXCEPT t1, no data > > for t1, part1 or part2 is replicated. > > I think we shall still publish partitions here. Since > publish_via_partition_root is false, part1 and part2 are published > individually and thus shall we allow publishing of part1 and part 2 > here? Thoughts? I made a mistake in explaining this point. Yes your point is correct. Changes for partitions part1 and part2 will be replicated. I have documented the behaviour in the docs. > > > II. If we create publication on all tables with EXCEPT part1, > > data for part1 is not replicated > > > > Agreed. > I have addressed the comments and have attached the updated patch in [1]. [1]: https://www.postgresql.org/message-id/CANhcyEXkeg3sjkS3DS9yU1ckz4ozUBN= Z%2BRmrWaRNSSVCR8RquA%40mail.gmail.com Thanks, Shlok Kyal