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 1mTsst-0001q7-Q9 for pgsql-hackers@arkaria.postgresql.org; Fri, 24 Sep 2021 21:37:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mTssr-0001Yd-1R for pgsql-hackers@arkaria.postgresql.org; Fri, 24 Sep 2021 21:37:29 +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 1mTssq-0001YV-DK for pgsql-hackers@lists.postgresql.org; Fri, 24 Sep 2021 21:37:28 +0000 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mTssl-0005C6-KI for pgsql-hackers@lists.postgresql.org; Fri, 24 Sep 2021 21:37:26 +0000 Received: by mail-ed1-x52c.google.com with SMTP id dj4so41280723edb.5 for ; Fri, 24 Sep 2021 14:37:23 -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=qz4lJpIDGquqvYEQixqvniiukyzSECAGsAaEVflx+u4=; b=MtnpbhEZEdY2VRQ3k7vx97WTmpLfhohEVpf7qNyxzxH7B6jewlMCjc8SIYdyYK4yUT PfHC3xDHRxIIK05e/O8wO/DQZLatLooxCFYJeotxdvq/zrjHgzXMTZaU2M+6Jd2i4aCN vlWEPf4eLrTiutEQeihjuAD+TTO1tBIZAmse5WRFaPQKqzNEc8e5RyWGsU8rM2T0gO07 HUPcsk6fD6ZuOjw5cOouzlk0SUtjpUs/JP0F/Pw13cD6/AjN4F2h29gH/4LMnBU4D68e 2FmuafC8Wmhw6qOeOsOkqOR8VO8/sJYZQOR0SpmpHCh3NYzHlgtBhaNjKOOKy7hDkyMb uvuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=qz4lJpIDGquqvYEQixqvniiukyzSECAGsAaEVflx+u4=; b=yXOKMMDs5rcZvr6lMrYmLJZ7y/BohBjnmJ7rPX1aw9Cv7/WlOvvurjzXyMSg3sL4po /ZqRmzdBwOlWF4LLMeEdCppYUVPci3vH+ZBgU8lO6/PuSrekbKpauJOXKgrs0wUmyU3T R9xxe4AP2S0N7Pqd+Ogjc3YgOHzJ8hZB+J4L8SITlX/zrEk3p0OC+pOvzbXntmf+9aoW DgppdrzHIrFBvl3Q3//vOSlfmOxIW1rGBPQzxg/Ea2mc47W3I2YWNkefhduM/OdX44rO JNXoL6fUqhMdbTY7QGie0197cDwe0U37+KB0y0fVL3jTdrt1AAoDBomU2bTW3PSDLWtd x7vg== X-Gm-Message-State: AOAM533a2nWVC4YFpU2vcYRrtVpUBuATvGaaf2C16wppf9fR3dgQ37nU 13efTQHKtL4hTfj31i2cnv+pdy0wInhpEweVQle5W1V2UJlV9Bla9imEBKAZqkOO64fN9DO9DSo gsFY6OUkOEKREhWJNtHccizHM4pFxCRFD0WW8bi+08B5bKz7sf0/TheRfpXqyhMNuptMiJ/1QPG AInP3KQKK1CdnAAiQWB67Lj7nn4hyg8mjQLg8lh+ids0GGE0tjps9t7y6eJV3CdykThy8QYxkm5 NliGxbl53YsFD7ki8zfCGrfRvEobV2PV89unaTjQ/NfxskvftT4Dw== X-Google-Smtp-Source: ABdhPJzxaiq5y4LOM0XhX7xqaPudlffVCr7mwQw5T9v7th7jNsXzyBnk0lZZGzczCOUn84FSlFCrig== X-Received: by 2002:a50:e085:: with SMTP id f5mr7609075edl.9.1632519442100; Fri, 24 Sep 2021 14:37:22 -0700 (PDT) Received: from [10.137.0.18] (ip-86-49-251-104.net.upcbroadband.cz. [86.49.251.104]) by smtp.gmail.com with ESMTPSA id dk27sm6430010edb.19.2021.09.24.14.37.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Sep 2021 14:37:21 -0700 (PDT) Subject: Re: row filtering for logical replication To: Amit Kapila Cc: Ajin Cherian , 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: <0c2464d4-65f4-4d91-aeb2-c5584c1350f5@www.fastmail.com> <574b4e78-2f35-acf3-4bdc-4b872582e739@enterprisedb.com> From: Tomas Vondra Message-ID: <4b213b91-8428-85a7-7ed6-48ceefd7f7be@enterprisedb.com> Date: Fri, 24 Sep 2021 23:37:20 +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 9/24/21 8:09 AM, Amit Kapila wrote: > On Thu, Sep 23, 2021 at 6:03 PM Tomas Vondra > wrote: >> >> 13) turning update into insert >> >> I agree with Ajin Cherian [4] that looking at just old or new row for >> updates is not the right solution, because each option will "break" the >> replica in some case. So I think the goal "keeping the replica in sync" >> is the right perspective, and converting the update to insert/delete if >> needed seems appropriate. >> >> This seems a somewhat similar to what pglogical does, because that may >> also convert updates (although only to inserts, IIRC) when handling >> replication conflicts. The difference is pglogical does all this on the >> subscriber, while this makes the decision on the publisher. >> >> I wonder if this might have some negative consequences, or whether >> "moving" this to downstream would be useful for other purposes in the >> fuure (e.g. it might be reused for handling other conflicts). >> > > Apart from additional traffic, I am not sure how will we handle all > the conditions on subscribers, say if the new row doesn't match, how > will subscribers know about this unless we pass row_filter or some > additional information along with tuple. Previously, I have done some > research and shared in one of the emails above that IBM's InfoSphere > Data Replication [1] performs filtering in this way which also > suggests that we won't be off here. > I'm certainly not suggesting what we're doing is wrong. Given the design of built-in logical replication it makes sense doing it this way, I was just thinking aloud about what we might want to do in the future (e.g. pglogical uses this to deal with conflicts between multiple sources, and so on). >> >> >> 15) pgoutput_row_filter initializing filter >> >> I'm not sure I understand why the filter initialization gets moved from >> get_rel_sync_entry. Presumably, most of what the replication does is >> replicating rows, so I see little point in not initializing this along >> with the rest of the rel_sync_entry. >> > > Sorry, IIRC, this has been suggested by me and I thought it was best > to do any expensive computation the first time it is required. I have > shared few cases like in [2] where it would lead to additional cost > without any gain. Unless I am missing something, I don't see any > downside of doing it in a delayed fashion. > Not sure, but the arguments presented there seem a bit wonky ... Yes, the work would be wasted if we discard the cached data without using it (it might happen for truncate, I'm not sure). But how likely is it that such operations happen *in isolation*? I'd bet the workload is almost never just a stream of truncates - there are always some operations in between that would actually use this. Similarly for the errors - IIRC hitting an error means the replication restarts, which is orders of magnitude more expensive than anything we can save by this delayed evaluation. I'd keep it simple, for the sake of simplicity of the whole patch. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company