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 1m3Nl0-0002k4-BL for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Jul 2021 19:07:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m3Nkz-0001ex-1f for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Jul 2021 19:07:49 +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 1m3Nky-0001ep-Jm for pgsql-hackers@lists.postgresql.org; Tue, 13 Jul 2021 19:07:48 +0000 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1m3Nkv-0005AB-Ln for pgsql-hackers@lists.postgresql.org; Tue, 13 Jul 2021 19:07:47 +0000 Received: by mail-ed1-x535.google.com with SMTP id ee25so16417796edb.5 for ; Tue, 13 Jul 2021 12:07:45 -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=afNhouYxziCtNBfcz+0qPual25FwzrmZ8QRGG1wEqe0=; b=sZkeCms7z9L339nnmYk2teGk6AEi8/aN6ALwin/ulQjHsbOuvDQETn6xekjSNWSIMf tvnG4HqDGEOMxl5w5jAWsp/QcuPGfU6FsnOJHE7XIgxCJW7sJ/8hACQ1j4Ddj9uH0t/v paFLhjS/6LQWbj5GwHLdTltIPeVLPPA1OmHMRIoQlJAjffNiBs779hzmErBfJg2B3Pzk dx09i32p2bdezZ3RKdTi3yo4OzH0oM8A83fkjMWyKkv1lXk2wGcGyW2pE6e3ThH3zkqA Go2ZPc7IAXN0ZRWf8178NxRxfYpXkolzO5za8xrQovf/Jc8f8OXxoI3eR/uu/nPVV96w eZsA== 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=afNhouYxziCtNBfcz+0qPual25FwzrmZ8QRGG1wEqe0=; b=bkDIk7nWb2AqRH4O87+x4PyIcn7BckpjeyZBpPGJLwhV+QYAzPAMidFF8TSUGOHlcl 0QEvd610ILJwb/RjH+ItLVjJrXqP5SKuWqvYWcg5SoPOxnx8Qqx+wDBKwfMiboh2RZQj ssuMZKsKKeoXRz8m439kye8oL+fqtnAxTbzJwd8GXoPArtD0mbaG7fTEi0jZfMMHh3WA rLI2A0ylCpUpVSGHC7qFgJPnaVvvPhaFoe+NIVkA/LuildVmi8m8Ez4LDZppT7MKuLV0 t+575F8Qdau+VWTV4IyTh8KagsAbOxBUho4B+JjNezdzU7cJ36K0guQ6k6mEGrHHF81n cspg== X-Gm-Message-State: AOAM533ziKQscV/tjUhoU+nOftAd9BXe+j2Kt3lLWK3uxCNvW7Etw5ox uzcYrBwGGexepaVX1GCHeNDzK9NiB8gbSSBVpUFSFa7+Fl6Pwwvfr8/t8BHnnNF2FvH185cnOE5 QzBNjj4+IGBkAYngzhnt4hmlJ+WWHC4aLG6gE96NX54M/Fm7KLfSNifRSYKzyvJludSHQ/ZjpH7 V0gbhPuGqM1vCXNaywCzlzdPsPrEC1aMb5WbtbNsXfGe61HP9t8mWeepoXJzJpLQzJW5/XuSjkw Qqhg3c/xYiUtvspu8WObqR9ollbOr6/R/v5GWpO2ud8IIPuP9q+Ow== X-Google-Smtp-Source: ABdhPJykDnlZgdVeyXu9tDOOdPo1T2FfsNLBIl0TmUynhxUCvfpd3Ffp/kBT496UBFfnQEnlvaxehQ== X-Received: by 2002:a05:6402:10c7:: with SMTP id p7mr7854308edu.159.1626203263072; Tue, 13 Jul 2021 12:07:43 -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 i11sm10088233edu.97.2021.07.13.12.07.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 13 Jul 2021 12:07:42 -0700 (PDT) Subject: Re: row filtering for logical replication To: Jeff Davis , Amit Kapila 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> <15cdb1b63669b6e6d7a3dcd9a21f156aa1bea8fd.camel@j-davis.com> From: Tomas Vondra Message-ID: <86dcff6e-9b5f-0f9a-8602-69a5602a30c9@enterprisedb.com> Date: Tue, 13 Jul 2021 21:07:38 +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: <15cdb1b63669b6e6d7a3dcd9a21f156aa1bea8fd.camel@j-davis.com> 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 5:44 PM, Jeff Davis wrote: > On Tue, 2021-07-13 at 10:24 +0530, Amit Kapila wrote: >> 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, > > Right, because the walsender is using a historical snapshot. > >> (b) it doesn't use UDFs in any way (in expressions, in >> user-defined operators, user-defined types, etc.), > > Is this a reasonable requirement? Postgres has a long history of > allowing UDFs nearly everywhere that a built-in is allowed. It feels > wrong to make built-ins special for this feature. > Well, we can either prohibit UDF or introduce a massive foot-gun. The problem with functions in general (let's ignore SQL functions) is that they're black boxes, so we don't know what's inside. And if the function gets broken after an object gets dropped, the replication is broken and the only way to fix it is to recover the subscription. And this is not hypothetical issue, we've seen this repeatedly :-( So as much as I'd like to see support for UDFs here, I think it's better to disallow them - at least for now. And maybe relax that restriction later, if possible. >> (c) the columns >> referred to in the filter should be part of PK or Replica Identity. > > Why? > I'm not sure either. > > Also: > > * Andres also mentioned that the function should not leak memory. > * One use case for this feature is when sharding a table, so the > expression should allow things like "hashint8(x) between ...". I'd > really like to see this problem solved, as well. > I think built-in functions should be fine, because generally don't get dropped etc. (And if you drop built-in function, well - sorry.) Not sure about the memory leaks - I suppose we'd free memory for each row, so this shouldn't be an issue I guess ... >> 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. > > This sounds like a better direction. We probably need some kind of > catalog information here to say what functions/operators are "safe" for > this kind of purpose. There are a couple questions: > Not sure. It's true it's a bit like volatile/stable/immutable categories where we can't guarantee those labels are correct, and it's up to the user to keep the pieces if they pick the wrong category. But we can achieve the same goal by introducing a simple GUC called dangerous_allow_udf_in_decoding, I think. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company