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 1m3fxW-0008Hn-NL for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Jul 2021 14:33:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m3fxV-0000rA-Kq for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Jul 2021 14:33:57 +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 1m3fxV-0000r2-D1 for pgsql-hackers@lists.postgresql.org; Wed, 14 Jul 2021 14:33:57 +0000 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1m3fxR-0002Y5-RQ for pgsql-hackers@lists.postgresql.org; Wed, 14 Jul 2021 14:33:56 +0000 Received: by mail-wr1-x436.google.com with SMTP id d2so3578233wrn.0 for ; Wed, 14 Jul 2021 07:33:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=7EuJ+iWQQnfBN+S1vp0ceFkAHewz0GsTkPEdCzHx+0E=; b=uLt/kwRCQsJBYJ3JEw5SKrvamWsanYe0VVGFj+UN3ZGzaP27IEMh/jVXnh2V/KihVe RlIsF6m1SIz5k6V810d+4QY6mHjN3NNaSYgEx5c46DvreTG03G743v/hXE4c0DC/rYFH 7vJJumqrRQhgfgeevAlfUv69ByGO6AUNR0BiIBqgIGdEF+KjTe6g+7XL7g9nzNGyfuq9 NreYZ70wF6Lqcgw3gRw44fZVPXxyeDSxpVWJiiL/7onKru0IOa7oR7MHEsRa49hSKyPs DAqiRavYggljMxQXppeNmxJK1AWK/dBaIDPckDg/pa7YCEVgqatD+4yuG5m0xXzpB5pU ZU7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=7EuJ+iWQQnfBN+S1vp0ceFkAHewz0GsTkPEdCzHx+0E=; b=jvMaf5UiUFBbBW+RMApR7APy6ngWRoHbrmj4CRtxEfSIxnmNXw3eTTOMdiMaX08X65 AdiELyhUcVQi338a8MWHl4GXo9NeTJbXlGNV/PDeVJPmZvPJIdgb4gnynr8z/t2KPXPp 1blrYWpZPe2iIZb4iJy2yc1IEecf8SB0b0m8TGa0jY7WJ4cGVXfItINzye/u2O74xgrr 47lNjieIuJuOqzvInjURpKbLLnUO+FOt+xyyN591DJthJuvfNwHtVL5sTGPXpfcHJ/Nq i77GZxBBI4oyJEi9gQON4JwKm5UAA2waOUKaIEzQRcx3gwpSMmCD0ZNDndUcYZ8WbAyB 7PzA== X-Gm-Message-State: AOAM533YzJCnqKd9fx0yywUQFhlh6m1dq/ctdpjxhYXcL4N4or2xIuO5 /fnTH/AL69x9cYDH0+LnWVbKO0Yw8mFoDoDh0nJN7WKhTW58ihaOJAWgPaVhdG4zDCN8f3SIJu4 7FHvZdY6z1KWL1x6+cQniMy4JS6FDT3GFY6JM+UTk1tvg/K+1ACqYEw4nwLEiW8XIB7WT+3EbAL L909aXu7hfHKacZ5DtkuJVJ4QP483NwK8TPCivoRpY6rV5cTxUBXKhg32cAV6UyTkmaD7Ahat1Y ZSz3agXdeOKeGUSdI7kUHFJBEQQw9ue3Ty+J68fzsvIAO+sLTpa8A== X-Google-Smtp-Source: ABdhPJwX3wCZi6delrgGHdjzjILISgiRJKWz7yR7NOal8bnTtL/A1/DxmK8ObvsETxVSAuRV8YgESg== X-Received: by 2002:adf:f892:: with SMTP id u18mr13325503wrp.64.1626273232454; Wed, 14 Jul 2021 07:33:52 -0700 (PDT) Received: from [10.137.0.18] (ip-86-49-254-183.net.upcbroadband.cz. [86.49.254.183]) by smtp.gmail.com with ESMTPSA id l16sm5920724wmj.47.2021.07.14.07.33.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 14 Jul 2021 07:33:52 -0700 (PDT) Subject: Re: row filtering for logical replication To: Amit Kapila Cc: Euler Taveira , Alvaro Herrera , Peter Smith , Rahila Syed , Peter Eisentraut , =?UTF-8?B?w5ZuZGVyIEthbGFjxLE=?= , japin , Michael Paquier , David Steele , Craig Ringer , Tomas Vondra , Amit Langote , PostgreSQL Hackers References: <202107132106.wvjgvjgcyezo@alvherre.pgsql> <48e13621-10f7-49ef-bcbe-ed530195efd2@www.fastmail.com> From: Tomas Vondra Message-ID: Date: Wed, 14 Jul 2021 16:33:49 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 7/14/21 2:50 PM, Amit Kapila wrote: > On Wed, Jul 14, 2021 at 3:58 PM Tomas Vondra > wrote: >> >> On 7/14/21 7:39 AM, Amit Kapila wrote: >>> On Wed, Jul 14, 2021 at 6:28 AM Euler Taveira wrote: >>>> >>>> On Tue, Jul 13, 2021, at 6:06 PM, Alvaro Herrera wrote: >>>> >>>> 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.) >>>> >>> >>> +1. >>> >>>> I thought about it but came to the conclusion that it doesn't worth it. Even >>>> with REPLICA IDENTITY FULL expression evaluates to false if the column allows >>>> NULL values. Besides that REPLICA IDENTITY is changed via another DDL (ALTER >>>> TABLE) and you have to make sure you don't allow changing REPLICA IDENTITY >>>> because some row filter uses the column you want to remove from it. >>>> >>> >>> Yeah, that is required but is it not feasible to do so? >>> >>>> 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.) >>>> >>>> New tuple. The main reason is that new tuple is always there for UPDATEs. >>>> >>> >>> I am not sure if that is a very good reason to use a new tuple. >>> >> >> True. Perhaps we should look at other places with similar concept of >> WHERE conditions and old/new rows, and try to be consistent with those? >> >> I can think of: >> >> 1) updatable views with CHECK option >> >> 2) row-level security >> >> 3) triggers >> >> Is there some reasonable rule which of the old/new tuples (or both) to >> use for the WHERE condition? Or maybe it'd be handy to allow referencing >> OLD/NEW as in triggers? >> > > I think apart from the above, it might be good if we can find what > some other databases does in this regard? > Yeah, that might tell us what the users would like to do with it. I did some quick search, but haven't found much :-( The one thing I found is that Debezium [1] allows accessing both the "old" and "new" rows through value.before and value.after, and use both for filtering. I haven't found much about how this works in other databases, sadly. Perhaps the best way forward is to stick to the approach that INSERT uses new, DELETE uses old and UPDATE works as DELETE+INSERT (probably), and leave anything fancier (like being able to reference both versions of the row) for a future patch. [1] https://wanna-joke.com/wp-content/uploads/2015/01/german-translation-comics-science.jpg regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company