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 1m4JU4-0000wc-0N for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Jul 2021 08:46:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m4JU1-0000Qy-Mx for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Jul 2021 08:46:09 +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 1m4JU1-0000Qq-En for pgsql-hackers@lists.postgresql.org; Fri, 16 Jul 2021 08:46:09 +0000 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1m4JTv-0006YZ-T2 for pgsql-hackers@lists.postgresql.org; Fri, 16 Jul 2021 08:46:09 +0000 Received: by mail-ed1-x52d.google.com with SMTP id w14so11920168edc.8 for ; Fri, 16 Jul 2021 01:46:03 -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=wB5wKW7F6f1fzDb9MV35i/FNheJGD4C9bDjZxyJcflE=; b=2HR4EhfHXUkGIQq0Cxyp9KEzbcS+iTXjDX2FRJk+y1KGYWeKhuu8LESCwZgL6RhLa2 iaWldOjOmR20J1M0NB21xbLZzFZr0sPRTbJdgasZPl9oApROCYbF1lNGPQmoy67BbgFt 2HeGxUs7XDSKXRxDZlyo5Bi0lAlcqL8jiyYhmtHDQ8qi7DtrkntMMVpLFe9r5/MlcSm7 zb41NvzwyxttIk+1EXAmH9Svm0Tzf7AS/cOBIkUYsx7idALfrBXxmo1QAbpzuH8RFoVt z+XVwNPaD8vjWVOke4dnt1lMYeX16yG9sTnXYJwyMsCc8J+tVjqh+oFLGEYSCvWabWBD a8yQ== 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=wB5wKW7F6f1fzDb9MV35i/FNheJGD4C9bDjZxyJcflE=; b=EIL3sWYmQiASZ4KODxTKFq0Llfk3yBOrlM1B05oT2FCrU/t5YaeUI9nPizopDTTTay fuY48ld/kGPMpzST79Ex/hKJLF1lyC5A7vWVW3FEwQZkMkGI93myxUPmsYy9hNhNa1pv ViOSm2A/2X2R8GHI8UfBS6YNdyQQ9ADUfym/a8eByRh3SqJ9HrCFhe/2/WJLRCRgsTI+ SXwubFX5czEOOMXc9ZxBztuRhb3nuFoexfujB7USCI1z2Jrsf6I1QNzNvWIYrdxIfwZk 7gBZSDb1dmSZYMa2WbAjG7tsSjznBuJR4RvC/TupORWGf8t99r1pasX5QG45y43Rm8/X kJwg== X-Gm-Message-State: AOAM530TJYSUUGihg8JF+xtGv1sV2OKeaunCJOB1GePe6YBnK97PBcKL 3BOaJQTvHgWralCFcEsRwJFQFarKr+AaBLezmN/aGpLQzWoz7OWaurQrIfWW9p0N0ccCSSCaSwP qHb1237E4AJalaO/yg8tX9WBAp/w6GOKMOboze117faWYad3wMyObbEaadks+ThgZEa0xZnCt7n xeoxr/BwEtsuDwuNTqtGXe6NE9KIiX5b4T/DdBIZDnPoIdtiDgs5aQ+Io1jfgI4m2g25pG1fRsy bzUflGVkBFhkxxiJ4eRsv3dUVzeYsWIOnyz/xB6ls/JpP+VwQB1/Q== X-Google-Smtp-Source: ABdhPJymHbKopA60s+32AT3L6cXu5DNojlDwBKL/gyXSfArqB63ijHRLHOM9VsJ5hWR5z2tuZtBchg== X-Received: by 2002:aa7:c857:: with SMTP id g23mr13035758edt.100.1626425162071; Fri, 16 Jul 2021 01:46:02 -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 g8sm3531553eds.25.2021.07.16.01.46.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Jul 2021 01:46:01 -0700 (PDT) Subject: Re: row filtering for logical replication To: Amit Kapila , Dilip Kumar 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: Fri, 16 Jul 2021 10:45:59 +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/16/21 5:26 AM, Amit Kapila wrote: > On Wed, Jul 14, 2021 at 4:30 PM Dilip Kumar wrote: >> >> On Wed, Jul 14, 2021 at 3:58 PM Tomas Vondra >> wrote: >>> >>> 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 for insert we are only allowing those rows to replicate which >> are matching filter conditions, so if we updating any row then also we >> should maintain that sanity right? That means at least on the NEW rows >> we should apply the filter, IMHO. Said that, now if there is any row >> inserted which were satisfying the filter and replicated, if we update >> it with the new value which is not satisfying the filter then it will >> not be replicated, I think that makes sense because if an insert is >> not sending any row to a replica which is not satisfying the filter >> then why update has to do that, right? >> > > There is another theory in this regard which is what if the old row > (created by the previous insert) is not sent to the subscriber as that > didn't match the filter but after the update, we decide to send it > because the updated row (new row) matches the filter condition. In > this case, I think it will generate an update conflict on the > subscriber as the old row won't be present. As of now, we just skip > the update but in the future, we might have some conflict handling > there. Right. > If this is true then even if the new row matches the filter, > there is no guarantee that it will be applied on the subscriber-side > unless the old row also matches the filter. Sure, there could be a > case where the user might have changed the filter between insert and > update but maybe we can have a separate way to deal with such cases if > required like providing some provision where the user can specify > whether it would like to match old/new row in updates? > I think the best we can do for now is to document this. AFAICS it can't be solved without a conflict resolution that would turn the UPDATE to INSERT. And that would require REPLICA IDENTITY FULL, otherwise the UPDATE would not have data for all the columns. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company