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 1m5TNQ-0004Es-EY for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Jul 2021 13:32:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m5TNP-0004pi-9d for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Jul 2021 13:32:07 +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 1m5TNO-0004pa-LK for pgsql-hackers@lists.postgresql.org; Mon, 19 Jul 2021 13:32:07 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1m5TNL-00022h-OQ for pgsql-hackers@lists.postgresql.org; Mon, 19 Jul 2021 13:32:05 +0000 Received: by mail-wm1-x331.google.com with SMTP id b14-20020a1c1b0e0000b02901fc3a62af78so12853596wmb.3 for ; Mon, 19 Jul 2021 06:32:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=ZPNGM3vhG3PXtb1azpdw2tap3KTBRWcheVPuWoVCipM=; b=dnI/NDbkH13+TVDXgYeSuVOhm3yxdBnl9WPRNfBpAnEusMj+MAP5qPhQgWH7nkO59e CK5THfBUq2nPusxDSuNTI0foZrp5/zYGUcmNdI+H8K12qiLUm0WmOJmHwoj4m2yGO79x 0needo7s5aNVfD8EZIQSp7aDQL5RbhpKX5VYVtNVGHENnpTob1JyCoQ719y9Aib8kPUP NeLLLi6xF+NHepvjBj23hhh8wit+WockMuYGvq+l4/SODf6Xn/Tk//Cowo8VhAW4zcPJ uuw4bcH6ayXVG3ZcRWsZWj+4PC5dXHeVsz7EAszzUqMYcyPtQWBy32IIL0D5+m2F8bbP M07g== 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=ZPNGM3vhG3PXtb1azpdw2tap3KTBRWcheVPuWoVCipM=; b=U9Xdn4FucWozpToiO1G3Jqy2no8IHjo00gyUzGt4pqO3Ghz7oWKXI9NKw1ywpW8lLu 1506f2d1lMztvxgT1hJpC96wFLeEWXpaLz72yA2CAWiS6/IZnJZydnYTYpSMIvV3wKn5 RosSqpbiN4EzAVQ5+3VWWyI74DGOkTVgITqiRR/O9AA47TnTZFNbgLMnQri8sl14ulQw PzAuxC4qlZjrrIExnv/bV+s9ETNuIElRi6Gjitmo5n95bn6YjnyrXR9+rT+WTTWEvH7H fLQhWF00EhUDZwOnyAKQsZyogwAOl7S0ZW2h9ZhNXbE+PPrVFWW1x2ztGr/Y6JPyxX3u Ir5A== X-Gm-Message-State: AOAM530rUwLofS7JWT3cTDCKBgoWovV8sdT3zBgp7qnbb1RdjC9+VLbG fOZLbRynk/kVK206bpQ05UQdbnrNIUCd3CozO5fOetPM+M5miRCroHhqflWl98VqbHeIVBWeio6 zO8kJ/gaWjRpbHwnYYo5AxiC7M2tNgsdM2rvfb8cbP77j9bEMvIooMeq3TrJU/6CqSTEztre6Ij iXmVIWXhbHyfEKP90N3dZ/QcBPpVS7PUce0ysoYh/B6p13GWk5iRqEBvqEHi/6BzE1C2haQkLTI GNrUAMPMxFRxOwCebRkwfeOXJ2aAqWj6q2r7IULlxm3UzdyV5H79g== X-Google-Smtp-Source: ABdhPJxLUtSrrB4mFOLfTcvrYNl6ZATCG0RdGqFHB54xoOUy6PQ0AgmLSyentGYu/AS2UK67YZQo5Q== X-Received: by 2002:a7b:ce82:: with SMTP id q2mr31686801wmj.60.1626701521666; Mon, 19 Jul 2021 06:32:01 -0700 (PDT) Received: from [10.137.0.19] (ip-86-49-254-183.net.upcbroadband.cz. [86.49.254.183]) by smtp.gmail.com with ESMTPSA id m4sm20539245wrs.14.2021.07.19.06.32.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Jul 2021 06:32:00 -0700 (PDT) Subject: Re: row filtering for logical replication To: Dilip Kumar , Amit Kapila Cc: Alvaro Herrera , Greg Nancarrow , Euler Taveira , Peter Smith , Rahila Syed , Peter Eisentraut , =?UTF-8?B?w5ZuZGVyIEthbGFjxLE=?= , japin , Michael Paquier , David Steele , Craig Ringer , Tomas Vondra , Amit Langote , PostgreSQL Hackers References: <202107162135.m5ehijgcasjk@alvherre.pgsql> From: Tomas Vondra Message-ID: Date: Mon, 19 Jul 2021 15:31:56 +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 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/19/21 1:00 PM, Dilip Kumar wrote: > On Mon, Jul 19, 2021 at 3:12 PM Amit Kapila wrote: >> a. Just log it and move to the next row >> b. send to stats collector some info about this which can be displayed >> in a view and then move ahead >> c. just skip it like any other row that doesn't match the filter clause. >> >> I am not sure if there is any use of sending a row if one of the >> old/new rows doesn't match the filter. Because if the old row doesn't >> match but the new one matches the criteria, we will anyway just throw >> such a row on the subscriber instead of applying it. > > But at some time that will be true even if we skip the row based on > (a) or (c) right. Suppose the OLD row was not satisfying the > condition but the NEW row is satisfying the condition, now even if we > skip this operation then in the next operation on the same row even if > both OLD and NEW rows are satisfying the filter the operation will > just be dropped by the subscriber right? because we did not send the > previous row when it first updated to value which were satisfying the > condition. So basically, any row is inserted which did not satisfy > the condition first then post that no matter how many updates we do to > that row either it will be skipped by the publisher because the OLD > row was not satisfying the condition or it will be skipped by the > subscriber as there was no matching row. > I have a feeling it's getting overly complicated, to the extent that it'll be hard to explain to users and reason about. I don't think there's a "perfect" solution for cases when the filter expression gives different answers for old/new row - it'll always be surprising for some users :-( So maybe the best thing is to stick to the simple approach already used e.g. by pglogical, which simply user the new row when available (insert, update) and old one for deletes. I think that behaves more or less sensibly and it's easy to explain. All the other things (e.g. turning UPDATE to INSERT, advanced conflict resolution etc.) will require a lot of other stuff, and I see them as improvements of this simple approach. >>> Maybe a second option is to have replication change any UPDATE into >>> either an INSERT or a DELETE, if the old or the new row do not pass the >>> filter, respectively. That way, the databases would remain consistent. > > Yeah, I think this is the best way to keep the data consistent. > It'd also require REPLICA IDENTITY FULL, which seems like it'd add a rather significant overhead. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company