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 1m3Pc7-0006fH-HV for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Jul 2021 21:06:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m3Pc5-00060F-GY for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Jul 2021 21:06:45 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m3Pc5-000607-8n for pgsql-hackers@lists.postgresql.org; Tue, 13 Jul 2021 21:06:45 +0000 Received: from new3-smtp.messagingengine.com ([66.111.4.229]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m3Pc3-000661-1K for pgsql-hackers@lists.postgresql.org; Tue, 13 Jul 2021 21:06:44 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailnew.nyi.internal (Postfix) with ESMTP id 57166580508; Tue, 13 Jul 2021 17:06:42 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Tue, 13 Jul 2021 17:06:42 -0400 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= fm3; bh=blMVM5TjSd7C06TAIUo/tOP09shbJiTTht2ID243FZE=; b=XB444hm6 Bu9WClu2IMJOWWtsQVt97Zdz83tM6Dy0x/mPQK+3kjbt8SeLttdNQ96N6bYWrz+g H272uYD7vmIf4zk0Y5myWEQ6VWDRkwvBWy36s8/eHpjiKpB22PANj/iH5uKH65Xw uWuwHPWi86St15oLUsL5a8DqTA7CIakx+S9pfJwFJn86dQjFUrrCmPiTMTmi3E0D RftILPH7J8JCahAggqejYUpLBFaEhUlyUmL0Q8bdRWeUbwvuEBdY5U8RUtO5eoPZ Vy5S53uysNhK27XeXyKI117mzWtsgnyD7Sob5Amvfd9SSVpj5px1H1duGsdM4d4q VQTVTtsi1seYDg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudeigddufecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkgggtugfgjgesthekredttddtjeenucfhrhhomheptehlvhgrrhho ucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgheqne cuggftrfgrthhtvghrnhepveffuddvgfehheehveduveffhefgkeeutdegheffleetieev jeeutdekfeekgeejnecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomhdprg gtthhsohhfghhorhgurdgtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghm pehmrghilhhfrhhomheprghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Jul 2021 17:06:41 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 6D7432A0A4F; Tue, 13 Jul 2021 17:06:36 -0400 (-04) Date: Tue, 13 Jul 2021 17:06:36 -0400 From: Alvaro Herrera To: Euler Taveira Cc: Peter Smith , Amit Kapila , Rahila Syed , Peter Eisentraut , =?utf-8?B?w5ZuZGVyIEthbGFjxLE=?= , japin , Michael Paquier , David Steele , Craig Ringer , Tomas Vondra , Amit Langote , PostgreSQL Hackers Subject: Re: row filtering for logical replication Message-ID: <202107132106.wvjgvjgcyezo@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2021-Jul-13, Euler Taveira wrote: > + > + The WHERE clause should contain only columns that are > + part of the primary key or be covered by REPLICA > + IDENTITY otherwise, DELETE operations will not > + be replicated. That's because old row is used and it only contains primary > + key or columns that are part of the REPLICA IDENTITY; the > + remaining columns are NULL. For INSERT > + and UPDATE operations, any column might be used in the > + WHERE clause. New row is used and it contains all > + columns. A NULL value causes the expression to evaluate > + to false; avoid using columns without not-null constraints in the > + WHERE clause. The WHERE clause does > + not allow functions and user-defined operators. > + There's a couple of points in this paragraph .. 1. if you use REPLICA IDENTITY FULL, then the expressions would work even if they use any other column with DELETE. Maybe it would be reasonable to test for this in the code and raise an error if the expression requires a column that's not part of the replica identity. (But that could be relaxed if the publication does not publish updates/deletes.) 2. For UPDATE, does the expression apply to the old tuple or to the new tuple? You say it's the new tuple, but from the user point of view I think it would make more sense that it would apply to the old tuple. (Of course, if you're thinking that the R.I. is the PK and the PK is never changed, then you don't really care which one it is, but I bet that some people would not like that assumption.) I think it is sensible that it's the old tuple that is matched, not the new; consider what happens if you change the PK in the update and the replica already has that tuple. If you match on the new tuple and it doesn't match the expression (so you filter out the update), but the old tuple does match the expression, then the replica will retain the mismatching tuple forever. 3. You say that a NULL value in any of those columns causes the expression to become false and thus the tuple is not published. This seems pretty unfriendly, but maybe it would be useful to have examples of the behavior. Does ExecInitCheck() handle things in the other way, and if so does using a similar trick give more useful behavior? The WHERE clause may only contain references to columns that are part of the table's replica identity. If <>DELETE or <>UPDATE operations are published, this restriction can be bypassed by making the replica identity be the whole row with ALTER TABLE .. SET REPLICA IDENTITY FULL. The WHERE clause does not allow functions or user-defined operators. -- Álvaro Herrera Valdivia, Chile — https://www.EnterpriseDB.com/ "The Gord often wonders why people threaten never to come back after they've been told never to return" (www.actsofgord.com)