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.96) (envelope-from ) id 1whkz2-000P25-0t for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Jul 2026 09:23:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1whkz0-00CC9p-1N for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Jul 2026 09:23:51 +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.96) (envelope-from ) id 1whkz0-00CC9h-05 for pgsql-hackers@lists.postgresql.org; Thu, 09 Jul 2026 09:23:50 +0000 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1whkyy-00000000ILE-2bQO for pgsql-hackers@lists.postgresql.org; Thu, 09 Jul 2026 09:23:49 +0000 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-c9c26a5fb98so456883a12.0 for ; Thu, 09 Jul 2026 02:23:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1783589028; cv=none; d=google.com; s=arc-20260327; b=a7Oh+0dyXnAu8UO1ME5pc9Y/V3Q/wytdO1Z400P4kiKnz08r79oEzWfOXw3MPKWMoQ K0t0iJWMm5mwAFLJgU0+L/GxDur6pbD6grzgHwYZS7cCSRipzxTkepcy0YH//0R0yZjy cd5930XzRtDiggyZpD9Qfk0U0NfzQKpLfTku5krRWnfXcOedMniFF5NZb8q37omBVmJo 6rTJZvjoSpksHWVdbygKNUDP+UdltKY1qeFU8OgyGvT6Q3Dz2Uq3C5R8ckpcqlBDOkY5 INKNDycD7GmqUr3m6HTCOJ1N1Vx5df7adkH71e4CqoOsgt8tKU8Isbtj2McQ7q+uy41x pb0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=QX9qBIzwjQy4KBCVwkJcuLVJHRYFKhUrsEbhLk86PuU=; fh=eOVNcjwxEOJ8n7jfX53TkA6b8jUe0zAdZ2+0ySxRJ5k=; b=BP4kpgwQR23Uosv5/Cpf6R9YEWtDVzpQ36cwt2IbdNPqAahR7B/cWhDmj2cIdIm5/5 nWoMdvfavxUPGZadRwhiaXZfh5ToHK5X7WTV5Q/VCGUJGlg04TzmFmxtoYtL4khyv/Bm Ouw0kxz7GksYkQ7fDrJrW+4WV8+Gqu8jIzjSB9IFJE4S1mkg6Sg9Gtzahi1BV1hiV3Kn fBx8wl9nNhxdmKbGJxWaCQjL+QSoeNGMiX3V7Y59tEkAfIccbqB9yD7e45Zx1ykIQFA5 9bTujheEyVYlrUq6jFoP/GMJwbDJ/ufwJeqQSDKD0NTjStBQc1i040BQT4ShrQ6JgReg Q83w==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783589028; x=1784193828; darn=lists.postgresql.org; h=content-transfer-encoding:content-type:cc:to:subject:message-id :date:from:in-reply-to:references:mime-version:from:to:cc:subject :date:message-id:reply-to:content-type; bh=QX9qBIzwjQy4KBCVwkJcuLVJHRYFKhUrsEbhLk86PuU=; b=JQ0xTD2HyE1Acg748Lid1uObeyh95wfEX/dqhmY3QkcP8qZl9vvh06/hyzLzuNeHCl ywI0eEtz6qoIM/eCs8JVNEm65bRC+bdJLc954NE/oc0y3Pj3ffaCndyn5G72/6PaCj08 cU3+NjQp19DNN4jil2LcMI9IOPhgBIGW6AZhxGBe0KJ8f3gUi0FQnIXNYrbGqaRqgKmf Jw4C5AvgmO17BId/pGm15T0bNN9gFEPrdtgYzVOWAofZi4K6yk1m67zP3HxT7g5waTV/ uKOyc1MYG0SsIg9fd+piXCns3E02gX5Ljks3FPa7n2/OurMLu7u/wvyvosp1ZJFqR6de 3Cqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783589028; x=1784193828; h=content-transfer-encoding:content-type:cc:to:subject:message-id :date:from:in-reply-to:references:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=QX9qBIzwjQy4KBCVwkJcuLVJHRYFKhUrsEbhLk86PuU=; b=P6bZh+yNybeaVW3KLK4HwP+N0mgx+4k50A2aLWG45TCRPyngt/wIGnEoHBiH3me4iy ox+Fk8r7BnoZI1+bxsMDRVahG5BqF00e7tjIMYkwJ6S5mHgsQf5JUVJOnFOkrANX3gnG 8hGlzYuJs2lzZkvgatO4A0cjIHGFVjhK/1fDBl5gLeHCykJjn4xmrXH2OfZPDU2Hdzyn LLVHYZhVZSsIN/rtpYgNk9zwacAq2OJKGzLoj8yUPjscr1faR2ln0Iuvpovh2aW7f2lP SkunjD99xwFRtLl7XnigIeTf56EODFhlPKdT1bZC/6AWNJBrl/lOAXUnASJq5+KBShrh NerQ== X-Forwarded-Encrypted: i=1; AHgh+Rr2Akf8A/NblXHBpqXmgJQC9lzKir4U4EnECl0NeGQBddv183g8e514NLBA9/O0qeS3B3MzCnO7ighYTuAb@lists.postgresql.org X-Gm-Message-State: AOJu0Yw1vJZWQq2kjhAXcXHz3VMxGgltAfVGGtKappI3ENNcbrbrVkqZ Wh6pCR5ICfvl/oCzEDd98DDY5SGbNdSkvS0VLhcTiyKo6Trxrzg4nJ717R8VpFPxVhvhw3F3n29 3RKf8eEO3pkaH1Wx4VbdmzLZfb3XwlXM= X-Gm-Gg: AfdE7cnSbjPXW6jilUbof17t+Lz7luukWe1x24bEmNCcg7xqDtDGxvWnUCM3XO3VIgd VloUHdtcis78ySLmFTv3WUgTJMez7SZnhZCKoeWMkKJiG7hU1s7nK3jtq8vPLdm60PcJ18GwL6e v6v6NIp36GDMXa/cw/Z7xEO2ZkXRtLcyrg5dD+lOpTw9WzAY5ckTtsDuLuGxH0+47HYUVJgmmE7 MlCfe5OwMhhCno0TyVuvG7K86dNO7gKSUrQajhnZnWxH5SuyXPxSP6QT7vPkXnrPUXh7hyz9OhU Dwc2pCODKp3D2tICdZnma8MRe9IE9AKvTm16PaWjFA== X-Received: by 2002:a05:6a21:3381:b0:3bf:651d:fee0 with SMTP id adf61e73a8af0-3c0d69d035fmr2623693637.19.1783589027818; Thu, 09 Jul 2026 02:23:47 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: shveta malik Date: Thu, 9 Jul 2026 14:53:34 +0530 X-Gm-Features: AVVi8CeudXYq3QaOlp0OL6GHtnhnrDJ43VU6epeVzP75MrGvdOlkCqgZ4nGUxzA Message-ID: Subject: Re: Support EXCEPT for TABLES IN SCHEMA publications To: Nisha Moond Cc: Peter Smith , Amit Kapila , Zsolt Parragi , pgsql-hackers@lists.postgresql.org, shveta malik 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 Wed, Jul 8, 2026 at 8:50=E2=80=AFPM Nisha Moond wrote: > > On Tue, Jul 7, 2026 at 8:40=E2=80=AFAM shveta malik wrote: > > > > On Tue, Jul 7, 2026 at 4:31=E2=80=AFAM Peter Smith wrote: > > > > > > Hi Nisha. > > > > > > Bug: The current patch is allowing conflicting exclusion lists... > > > > > > =3D=3D=3D=3D=3D=3D > > > > > > Background: > > > > > > It's always been possible for CREATE PUBLICATION to specify the same > > > schema or same table multiple times. > > > > > > test_pub=3D# CREATE SCHEMA MYSCHEMA; > > > CREATE SCHEMA > > > test_pub=3D# CREATE TABLE T1(A INT); > > > CREATE TABLE > > > test_pub=3D# CREATE TABLE MYSCHEMA.T2(A INT); > > > CREATE TABLE > > > test_pub=3D# CREATE TABLE MYSCHEMA.T3(A INT); > > > CREATE TABLE > > > > > > // same table multiple times is OK > > > test_pub=3D# CREATE PUBLICATION PUB3 FOR TABLE T1,T1,T1,T1; > > > CREATE PUBLICATION > > > > > > // same schema multiple times is OK > > > test_pub=3D# CREATE PUBLICATION PUB1 FOR TABLES IN SCHEMA MYSCHEMA, > > > MYSCHEMA, MYSCHEMA; > > > CREATE PUBLICATION > > > > > > ~~~ > > > > > > But, this behaviour is only allowed if there are no specification > > > conflicts. e.g. You can't have multiple tables with column lists: > > > > > > test_pub=3D# CREATE PUBLICATION PUB4 FOR TABLE T1,T1(A),T1,T1; > > > ERROR: conflicting or redundant column lists for table "t1" > > > > > > =3D=3D=3D=3D=3D=3D > > > > > > Bug: > > > > > > IMO similar restrictions and a similar error message needs to happen > > > for clashing schema exclusions. Specifying the same schema multiple > > > times is fine, but it must be disallowed if there are conflicting > > > exclusion lists. > > > > > > > +1. Good Catch. > > > > Thanks for the bug report. I've fixed it and attached the fix as a > separate top-up patch, v19-0002. > > Until v18, schema qualification checks for EXCEPT tables were split > between two places: > > 1) TABLES IN SCHEMA (EXCEPT TABLE ); > -- the schema qualification check was performed in gram.y, since all > required information was available during parsing. > > 2) TABLES IN SCHEMA CURRENT_SCHEMA (EXCEPT TABLE ); > -- CURRENT_SCHEMA is resolved only at execution time, so the schema > qualification and eligibility checks were performed there. > > The reported bug also affects cases such as: > CREATE PUBLICATION PUB2 FOR TABLES IN SCHEMA MYSCHEMA EXCEPT (TABLE > T2), CURRENT_SCHEMA EXCEPT (TABLE T3); > -- where CURRENT_SCHEMA =3D myschema. Correct handling of this case > requires the checks to be performed after schema resolution, i.e., at > execution time. To reduce duplicate code, I moved the schema > qualification and eligibility checks for both cases to execution time > and removed the corresponding processing from gram.y. > > Since this changes a fair amount of code, I've kept it as a separate > patch (v19-0002) to make review easier. Depending on the feedback, we > can optimize the implementation or move parts of it back into gram.y > before merging it into patch 0001. > ~~~ > Nisha, - * Also flattens except_tables from TABLES IN SCHEMA nodes into the list s= o - * that ObjectsInPublicationToOids() sees them as top-level EXCEPT_TABLE entries. + * The except_tables attached to TABLES IN SCHEMA nodes are left in place; + * ObjectsInPublicationToOids() qualifies names, validates schema membersh= ip, + * and flattens them once the schema OID is known. Can you please explain what does 'flatten' mean here. The flatten logic here is added by your patch001 only, it is not an existing logic. To me (in my initial round of review), it seems okay if we moved it to ObjectsInPublicationToOids(). The only thing is that the one error (table in EXCEPT clause does not belong to schema) which is possible to get at the parsing stage will now be emitted during pub-creation stage. But since it will keep the entire logic of except-list verification at one place and considering that creat/alter-pub is not so frequent operation, I am fine with it. But lets see if others have any comment here. ~~ I had a quick look at the changes: + * Include the ONLY-ness of this entry in its signature. EXCEPT + * (TABLE parent) excludes parent and its inheritance children, + * while EXCEPT (TABLE ONLY parent) excludes only parent itself. I think this will unconditionally apply to paritioned tables as well but for paritioned table, EXCEPT doc says that ONLY and * has no effect, but here it shows the effect: Thsi gives error: postgres=3D# CREATE PUBLICATION pub1 FOR TABLES IN SCHEMA public EXCEPT (TABLE ONLY tab_root), TABLES IN SCHEMA public EXCEPT (TABLE tab_root); ERROR: 42P17: schema "public" specified with conflicting EXCEPT lists LOCATION: ProcessSchemaExceptTables, publicationcmds.c:299 While this does not: postgres=3D# CREATE PUBLICATION pub1 FOR TABLES IN SCHEMA public EXCEPT (TABLE tab_root), TABLES IN SCHEMA public EXCEPT (TABLE tab_root); CREATE PUBLICATION But I also checked column-list errors and found that even if columns are exact sames, we get error: postgres=3D# CREATE PUBLICATION PUB4 FOR TABLE T1(i), T1(i); ERROR: 42710: conflicting or redundant column lists for table "t1" LOCATION: OpenTableList, publicationcmds.c:2312 While this works: postgres=3D# CREATE PUBLICATION PUB4 FOR TABLE T1, T1; CREATE PUBLICATION This makes me think that even introducing the smartness of identifying ONLY in case of inherited tables and distinguishing it from parititoned tables is not required. We can just change your error message to 'conflicting or redundant EXCEPT lists for schmea "s1"' and throw error in all cases where schmea with except list repeats without actually comparing them. Does this sound reasonable? thanks Shveta