Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n1umz-0007hL-U5 for pgsql-hackers@arkaria.postgresql.org; Mon, 27 Dec 2021 18:32:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1n1umy-0002sC-G3 for pgsql-hackers@arkaria.postgresql.org; Mon, 27 Dec 2021 18:32:04 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n1umx-0002s3-JD for pgsql-hackers@lists.postgresql.org; Mon, 27 Dec 2021 18:32:04 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n1umo-0002Xj-Uv for pgsql-hackers@postgresql.org; Mon, 27 Dec 2021 18:32:02 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 08C9732005BC; Mon, 27 Dec 2021 13:31:50 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Mon, 27 Dec 2021 13:31:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=k4Xh+B/e8ZyZ/EoYommUCwFNbeIjAvtvsiYZSAOqDNg=; b=Ylucj6YJ L1CobAn2FlR1Nz4y70vbWGR9jk2zgcsN2J4yRCdqU9lf9/zRkuWHfVTpA/+OIfc5 lTibhCiv+JGR1OE0Ejfqph/B0Cq2LDbby2mJaW5F4I7v+YnX6IhwgCDjqh5VeKZ8 0thCxCFOj6LfpnjY/ZLuocOoDAIb/Iw6DlEDJ4J1ausvuU3Uln/TXp1QooZ20pUX ZZ+/rb7XwUE/KVo92I2JdYmoK8fIPhzKVCQ2BRXaMS9esMbuAQR6VRrlOr0NAwJJ fiBsCPei4B29U3aQKZPedmLxMXmjnERjy20/8VRrejirYZS3iHfTy8rOapxip6tE QMbOftliCjTY8w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddruddujedguddtvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvuffkgggtugfgjgesthekredttddtjeenucfhrhhomheptehlvhgr rhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh eqnecuggftrfgrthhtvghrnhepudejveejffejveduudetvdekieeuiedtvdeileefkeev jedufeeguedvjefhueelnecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhv hhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 27 Dec 2021 13:31:49 -0500 (EST) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 69BC22A054C; Mon, 27 Dec 2021 15:31:46 -0300 (-03) Date: Mon, 27 Dec 2021 15:31:46 -0300 From: Alvaro Herrera To: Tom Lane Cc: Peter Eisentraut , Rahila Syed , PostgreSQL-development Subject: Re: Column Filtering in Logical Replication Message-ID: <202112271831.ckar2sy4s5kv@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1513654.1640626709@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2021-Dec-27, Tom Lane wrote: > Alvaro Herrera writes: > > Determining that an array has a NULL element seems convoluted. I ended > > up with this query, where comparing the result of array_positions() with > > an empty array does that. If anybody knows of a simpler way, or any > > situations in which this fails, I'm all ears. > > Maybe better to rethink why we allow elements of prattrs to be null? What I'm doing is an unnest of all arrays and then aggregating them back into a single array. If one array is null, the resulting aggregate contains a null element. Hmm, maybe I can in parallel do a bool_or() aggregate of "array is null" to avoid that. ... ah yes, that works: with published_cols as ( select pg_catalog.bool_or(pr.prattrs is null) as all_columns, pg_catalog.array_agg(distinct unnest order by unnest) AS attrs from pg_catalog.pg_publication p join pg_catalog.pg_publication_rel pr on (p.oid = pr.prpubid) left join unnest(prattrs) on (true) where prrelid = :table and p.pubname in ('pub1', 'pub2') ) SELECT a.attname, a.atttypid, a.attnum = ANY(i.indkey) FROM pg_catalog.pg_attribute a LEFT JOIN pg_catalog.pg_index i ON (i.indexrelid = pg_get_replica_identity_index(:table)), published_cols WHERE a.attnum > 0::pg_catalog.int2 AND NOT a.attisdropped and a.attgenerated = '' AND a.attrelid = :table AND (all_columns OR attnum = ANY(published_cols.attrs)) ORDER BY a.attnum ; -- Álvaro Herrera Valdivia, Chile — https://www.EnterpriseDB.com/