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 1nlHL6-0007qp-Hi for pgsql-hackers@arkaria.postgresql.org; Sun, 01 May 2022 21:42:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nlHL4-00023U-5K for pgsql-hackers@arkaria.postgresql.org; Sun, 01 May 2022 21:42:46 +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 1nlHL3-00023L-S3 for pgsql-hackers@lists.postgresql.org; Sun, 01 May 2022 21:42:45 +0000 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nlHKu-0008UM-Qo for pgsql-hackers@lists.postgresql.org; Sun, 01 May 2022 21:42:44 +0000 Received: by mail-ed1-x530.google.com with SMTP id p18so14750319edr.7 for ; Sun, 01 May 2022 14:42:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=FN888Gog/q2C5iXAmrsrymrqLG2gTUokJtjfanLaEWI=; b=f2RuM3Rv+YMWTSV/ow2hMLqjJKOgbU61Vfy1GVAr4fYzRNKUVIyMeGY8k+yCgnioXm pr8TDXSK1lObUXBp8QR2nK6npDWGOWQuqB0SqoXRoS+oWS0+ceQqertIL5JtP9wL4Nq+ 6gehN426sUK7Dpjl5BDClQmDe7zRYc4DeMzurmbb/s5Tbduo4t38Myp42QvJ0ynxS3p/ l4lSzTSxVIiU9NE5ZCWD3DgYggqcCAbnCFfz0pdu24GzATJC1U6W8ZaJzK9O86NnqtPn 8YxmAMAH5UC3MKVRz1HhYb7U4tdtxB72+vwE8CEV8WAFKSYNL60lC7u+A5Tgh+Ovw1p1 KYtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=FN888Gog/q2C5iXAmrsrymrqLG2gTUokJtjfanLaEWI=; b=HGGKyXv2xf1PjAyGtUXW6ckrxZuE7u8LtbEscs3l+bnxPTK6qJ9AVCcKelCzNGYtVD M33ag70/JA5Q3zBDFlQJdVfC7xTiZiQYP3sWUi4CufWLcqr+e8MiNNN4yyXH+j+S2RKh o7O9el9+bu0gSuwvz2MdZq9qguRGyOxfkFEXTnv60eBc5lKtWqPS9g+GoGqLXuvhY5gj g3+6NLqPigQxINS88g8Xf0psjKttwa0J9bfGQ8MED45L/po5lwUp5uvz8Lf7qUAA7gPA H19xvvSIlyELkwaUh5ZSxTbZ0pSeGopyg9MQEtPdazijc4GrasPGdrsV6Vlto3NSYBq+ sLmw== X-Gm-Message-State: AOAM533tZ5Hf/kbnyFEyB92q16gV7m8FnOrNQSywx3tTEcQbnAfC3b6p SDKytwr0ZSgbO+YaLxCQB2NYbkSvFUGJxTnBo6Ybgvmj3oFaHuonTnaE+tKxFXvVH2ZYunXibhm 1C+1tFMT4X4PousYwYph8NbPnLrTLUO8z1T+yZgQl/wOUjoF3n9hfOiJVVkR0yIJwI0YSLa02yh Oi5cV4+e1SJcUjPIy2MSdLJbuWHu2HnPfHDuluDtzWO0FzzT+DZTsp X-Google-Smtp-Source: ABdhPJwWKOjwyNzI9HpqFTHrCBzj2PttZB2IWZkj2C47gEVFqRVMKmM7C6dv016q4VqxKHtuSS4llw== X-Received: by 2002:aa7:df15:0:b0:41d:675f:ea9a with SMTP id c21-20020aa7df15000000b0041d675fea9amr10747623edy.148.1651441355518; Sun, 01 May 2022 14:42:35 -0700 (PDT) Received: from [10.137.0.17] (ip-86-49-250-165.net.upcbroadband.cz. [86.49.250.165]) by smtp.gmail.com with ESMTPSA id gz19-20020a170907a05300b006f3ef214ddasm2900866ejc.64.2022.05.01.14.42.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 01 May 2022 14:42:35 -0700 (PDT) Message-ID: <338e719c-4bc8-f40a-f701-e29543a264e4@enterprisedb.com> Date: Sun, 1 May 2022 23:42:34 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: bogus: logical replication rows/cols combinations Content-Language: en-US To: Amit Kapila , Peter Eisentraut Cc: Alvaro Herrera , Pg Hackers References: <006d5ffc-1e7a-5cf2-c507-88eee6e0c14d@enterprisedb.com> <202204270943.4ol7indtwv3i@alvherre.pgsql> <39077967-c327-eddb-ac4b-7d64117944fb@enterprisedb.com> From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 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 4/29/22 07:05, Amit Kapila wrote: > On Thu, Apr 28, 2022 at 5:56 PM Peter Eisentraut > wrote: >> >> On 27.04.22 12:33, Amit Kapila wrote: >>> Currently, when the subscription has multiple publications, we combine >>> the objects, and actions of those publications. It happens for >>> 'publish_via_partition_root', publication actions, tables, column >>> lists, or row filters. I think the whole design works on this idea >>> even the initial table sync. I think it might need a major change >>> (which I am not sure about at this stage) if we want to make the >>> initial sync also behave similar to what you are proposing. >> >> If one publication says "publish if insert" and another publication says >> "publish if update", then the combination of that is clearly "publish if >> insert or update". Similarly, if one publication says "WHERE (foo)" and >> one says "WHERE (bar)", then the combination is "WHERE (foo OR bar)". >> >> But if one publication says "publish columns a and b if condition-X" and >> another publication says "publish columns a and c if not-condition-X", >> then the combination is clearly *not* "publish columns a, b, c if true". >> That is not logical, in the literal sense of that word. >> > > So, what should be the behavior in the below cases: > > Case-1: > pub1: "publish columns a and b if condition-X" > pub2: "publish column c if condition-X" > > Isn't it okay to combine these? > Yes, I think it's reasonable to combine those. So the whole publication will have WHERE (condition-X) and the column list will be (a,b,c). > Case-2: > pub1: "publish columns a and b if condition-X" > pub2: "publish columns c if condition-Y" > In this case the publication will have WHERE (condition-X or condition-Y) and there will be different column filters for different row sets: if (condition-X and condition-Y) => (a,b,c) else if (condition-X and NOT condition-Y) => (a,b) else if (condition-Y and NOT condition-X) => (c) I think this behavior is reasonable, and it's what the patch does. > Here Y is subset of condition X (say something like condition-X: > "col > 5" and condition-Y: "col1 > 10").> > What should we do in such a case? > > I think if there are some cases where combining them is okay but in > other cases, it is not okay then it is better to prohibit 'not-okay' > cases if that is feasible. > Not sure I understand what's the (supposed) issue with this example. We'll simply do this: if (col1 > 5 and col1 > 10) => (a,b,c) else if (col1 > 5 and col1 <= 10) => (a,b) else if (col1 > 10 and col1 <= 5) => (c) Obviously, the third branch is unreachable, because the if condition can never be satisfied, so we can never see only column list (c). But that's fine IMO. When phrased using the CASE expressions (as in tablesync) it's probably somewhat less cumbersome. I think it's easier to think about this using "data redaction" example where you specify which columns can be replicated under what condition. Obviously, that's "orthogonal" in the sense that we specify column list for a row filer condition, not row filter for a column. But in principle it's the same thing, just different grammar. And in that case it makes perfect sense that you don't blindly combine the column lists from all publications, because that'd defeat the whole point of filtering columns based on row filters. Imagine have a table with customers from different regions, and you want to replicate the data somewhere else, but for some reason you can only replicate details for one particular region, and subset of columns for everyone else. So you'd do something like this: CREATE PUBLICATION p1 FOR TABLE customers (... all columns ...) WHERE region = 'USA'; CREATE PUBLICATION p1 FOR TABLE customers (... subset of columns ...) WHERE region != 'USA'; I think ignoring the row filters and just merging the column lists makes no sense for this use case. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company