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 1m3Nsu-0002xi-1p for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Jul 2021 19:16:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m3Nss-0008Pd-PN for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Jul 2021 19:15:58 +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 1m3Nss-0008PU-HO for pgsql-hackers@lists.postgresql.org; Tue, 13 Jul 2021 19:15:58 +0000 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1m3Nso-0001TQ-86 for pgsql-hackers@lists.postgresql.org; Tue, 13 Jul 2021 19:15:57 +0000 Received: by mail-ej1-x62e.google.com with SMTP id go30so16385225ejc.8 for ; Tue, 13 Jul 2021 12:15: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=yCl5yfHMjrYpuNd1cyYmpOIom3Cq+/nieHxjng4c98k=; b=fD84lpXeBLuVrB3Q2wb7IjKSihFm9SRP7881iFdqybKaKhjtp2RHAbRIB1p0Dwys6o pHBEnzwMGYbevPQN383BDmgEAYn+/cYAauTwAh+raxRAa8JKkC3oWbtz6wqcS5cRjTDF M+2w93+vvA+Y/LxVaIGgKdJgJLVLqG0eG32tiqANLYVM6cczJ8EzYzIJ76hrinY5de3d ZAzxhdEYGPniGS+FuoMp2FYRugOgFIGmJLAe5kWw75l8x5Y9dVFO/S7VQUHZ0C0mgzpb PRvWQrXBJA94hhpnpPpb+x96eldEmvCKIy3GO65EL2OoZK8jZi7d2WWHyF+AZ+PASSoT jNKA== 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=yCl5yfHMjrYpuNd1cyYmpOIom3Cq+/nieHxjng4c98k=; b=bUMoXSzASNFxF9mlo7zD4gZgF7+ypkUXVJXl0+YCHK/CDHjGD2/hu7GA+39SErcqJK XmYyHKlAjq4bUK+G7A2D1iRqO8IYMAD2uv+msNjtNj7rCdZxm9R2OnaGON3lRPAlxeu9 r3UUBEZQu23GCZQ24RdWNZBovSr1FcdAXg4avsX5BJzsNYNCT3hsFx86izYqMh7kSqWS JTdeqWB+seTffkIgeRgeURwOxCJJyaAwsIpEwr5Wm1kXVVz/BED7nKTzWVkTksPODpUP QKXN/qr1zCfdcMZ4D3VTFOCgo9/5+QZfz/2JjyagXIrvm+lj/OYG1Kuvfbw4J3FqCufO 1DZA== X-Gm-Message-State: AOAM530m0psZlkdMoCg/XBFW2Zt8/GrobvmjngD091932gSqVRIlMvBe zEh0m5TYUB7c6FJepjhZfpZMRyG1Y5oBC1P/nyxGcDcjjoy1DLr41gVpeBiuPPFjAI13B74CCGi hhXRHagQEwIOqIDmgWwWs3vS3nwIFn+NQdLG0yOInpuRn+ILs+1HwHE71PydKuO9Hh81Fo17T+7 UfQEGNv5PW00NcVPreabg74BvqveTyvUvQahwp/PAu1ZKm0+svDyklcH+b31gof8VuIc5hASCfK pSo5YDaGk4qdzKxxuf/06FLIfDgjnQPS1ezggtug59pSFAwAZ6Hpw== X-Google-Smtp-Source: ABdhPJyE/iR/fdsvwcBg0xSTIYDPor777Y0W0Uep2MLmhuKtI2hc/rf5r9aRI4ElHZxx6L7tRjCPUg== X-Received: by 2002:a17:906:498b:: with SMTP id p11mr7557944eju.295.1626203752324; Tue, 13 Jul 2021 12:15: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 mm27sm8399059ejb.67.2021.07.13.12.15.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 13 Jul 2021 12:15:51 -0700 (PDT) Subject: Re: row filtering for logical replication To: Amit Kapila , Petr Jelinek Cc: Alvaro Herrera , Euler Taveira , Greg Nancarrow , Peter Smith , Rahila Syed , Peter Eisentraut , =?UTF-8?B?w5ZuZGVyIEthbGFjxLE=?= , japin , Michael Paquier , David Steele , Craig Ringer , Tomas Vondra , Amit Langote , PostgreSQL Hackers References: <849ee491-bba3-c0ae-cc25-4fce1c03f105@enterprisedb.com> <202107120148.l4nueeibgynb@alvherre.pgsql> <33c033f7-be44-e241-5fdf-da1b328c288d@enterprisedb.com> From: Tomas Vondra Message-ID: <4d9e0142-0e80-daee-5236-154cd785828c@enterprisedb.com> Date: Tue, 13 Jul 2021 21:15:48 +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/13/21 12:57 PM, Amit Kapila wrote: > On Tue, Jul 13, 2021 at 10:24 AM Amit Kapila wrote: >> >> On Mon, Jul 12, 2021 at 3:01 PM Tomas Vondra >> wrote: >> >>> In terms of implementation, I think there are two basic options - either >>> we can define a new "expression" type in gram.y, which would be a subset >>> of a_expr etc. Or we can do it as some sort of expression walker, kinda >>> like what the transform* functions do now. >>> >> >> I think it is better to use some form of walker here rather than >> extending the grammar for this. However, the question is do we need >> some special kind of expression walker here or can we handle all >> required cases via transformWhereClause() call as the patch is trying >> to do. AFAIU, the main things we want to prohibit in the filter are: >> (a) it doesn't refer to any relation other than catalog in where >> clause, (b) it doesn't use UDFs in any way (in expressions, in >> user-defined operators, user-defined types, etc.), (c) the columns >> referred to in the filter should be part of PK or Replica Identity. >> Now, if all such things can be detected by the approach patch has >> taken then why do we need a special kind of expression walker? OTOH, >> if we can't detect some of this then probably we can use a special >> walker. >> >> I think in the long run one idea to allow UDFs is probably by >> explicitly allowing users to specify whether the function is >> publication predicate safe and if so, then we can allow such functions >> in the filter clause. >> > > Another idea here could be to read the publication-related catalog > with the latest snapshot instead of a historic snapshot. If we do that > then if the user faces problems as described by Petr [1] due to > missing dependencies via UDFs then she can Alter the Publication to > remove/change the filter clause and after that, we would be able to > recognize the updated filter clause and the system will be able to > move forward. > > I might be missing something but reading publication catalogs with > non-historic snapshots shouldn't create problems as we use the > historic snapshots are required to decode WAL. > IMHO the best option for v1 is to just restrict the filters to known-safe expressions. That is, just built-in operators, no UDFs etc. Yes, it's not great, but both alternative proposals (allowing UDFs or using current snapshot) are problematic for various reasons. Even with those restrictions the row filtering seems quite useful, and we can relax those restrictions later if we find acceptable compromise and/or decide it's worth the risk. Seems better than having to introduce new restrictions later. > I think the problem described by Petr[1] is also possible today if the > user drops the publication and there is a corresponding subscription, > basically, the system will stuck with error: "ERROR: publication > "mypub" does not exist. I think allowing to use non-historic snapshots > just for publications will resolve that problem as well. > > [1] - https://www.postgresql.org/message-id/92e5587d-28b8-5849-2374-5ca3863256f1%402ndquadrant.com > That seems like a completely different problem, TBH. For example the slot is dropped too, which means the WAL is likely gone etc. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company