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 1nj7Dz-0005Ot-QB for pgsql-hackers@arkaria.postgresql.org; Mon, 25 Apr 2022 22:30: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 1nj7Dy-00059h-2l for pgsql-hackers@arkaria.postgresql.org; Mon, 25 Apr 2022 22:30:30 +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 1nj7Dx-00059X-Av for pgsql-hackers@lists.postgresql.org; Mon, 25 Apr 2022 22:30:29 +0000 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nj7Dt-0000QP-VO for pgsql-hackers@lists.postgresql.org; Mon, 25 Apr 2022 22:30:28 +0000 Received: by mail-ej1-x62a.google.com with SMTP id g6so9579467ejw.1 for ; Mon, 25 Apr 2022 15:30:25 -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 :references:from:cc:in-reply-to:content-transfer-encoding; bh=FGeWtDBSG/EcUBwVj0pUvBMGgG1RiiiQRPuRpZboWls=; b=kWZdCDAcbP0F7NzjLZnicuU2pNtKcDdhzHiAkywkqoCLItG5iF0t3liziJ/5aYLHcy PWBWIJWCB2UNlKH9GHet5uJe5Y0gT1Us54KGixU+p7D0BDs7SWuq99P/R+dMCwjJYNZt vsrtO02kXJI6swQk28/peFSIJC2McvRFVaYYtGcs0nh0aRsG4Zr1lmvMl+UnnoWKKjO7 VC0axuhVHMFyiiGKX4XAukqx6+rYy1Wddlt6cHKHkoB4RU3miJpYQQYsmA+KuwhD5j+m R2d0Ehzq6+MGbzsHWuTi1kh6or+ltzveGIcqJ6hS0Ikb9ih7FH2o0blFntmaXPuabeQi OgYg== 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:references:from:cc:in-reply-to :content-transfer-encoding; bh=FGeWtDBSG/EcUBwVj0pUvBMGgG1RiiiQRPuRpZboWls=; b=CkhiOo1kXF0kgwhFoMglAA3UNc0+8Ego2PSxHcHLz4ZHQpjZPBt51EnXbyARwwIplg 6LVx2Aj1k5K7Bu/DbTv9noWPDIgcRWtn7v6SawE4HK4S6Rq+vsEaBmbna3Wy+t1Ei7ee gKIo2ZH9nB+QY+fmZddKtjq0rSx9vPS20SphCPj4d9v12H1bD2AhimjPJ47Sk7AbRXWg rQWQYapsDEuwflO3x/A/M7yhIU7863kEJzT16yTU3EMnS+9f26dBVwM8lfp9TxqAan0X yAmh0pkQIswqPagacufizkCAyCHotoOB18rU6ZhEF3BOLOl0KnGPVx39P0xBY3g/37U1 bRXA== X-Gm-Message-State: AOAM530TOROpI6/A92ncKt2KVKqejDynJgJWziBA1YhldmZxSajfSxKw Ns/kgyIKC529NniFtNhjGKAVrJLs/bd/Kqv62Zfk0H/cTk5QG17q0ccL0rkahb7PDFt8+jCKm2R MtgMI4aKk+qqPzeID3UNsyIpQ82lFPu7mwlpDdjjKNIjLrhyNaMI4Y7itFhpFVsgQ2v/fwiOJJO xldilXN4g2OBUGiJ0BaKFcIbGrAsVBDCOfis9h8y1feEE07w9hhb+3rT8RU8UA X-Google-Smtp-Source: ABdhPJzS0LbCHEIf8Ta/eJMmWOFBUQT7Dru5/6RKsj//gK+9vuoYn5Ik2OisVBs0lQkD70ZG7GpWLw== X-Received: by 2002:a17:906:7946:b0:6f0:12ee:4418 with SMTP id l6-20020a170906794600b006f012ee4418mr18646747ejo.156.1650925824432; Mon, 25 Apr 2022 15:30:24 -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 aj18-20020a1709069a5200b006f3a2a53c1csm870200ejc.54.2022.04.25.15.30.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 Apr 2022 15:30:22 -0700 (PDT) Message-ID: <006d5ffc-1e7a-5cf2-c507-88eee6e0c14d@enterprisedb.com> Date: Tue, 26 Apr 2022 00:30:21 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: bogus: logical replication rows/cols combinations Content-Language: en-US To: Alvaro Herrera , Pg Hackers References: <202204251548.mudq7jbqnh7r@alvherre.pgsql> From: Tomas Vondra Cc: Amit Kapila In-Reply-To: <202204251548.mudq7jbqnh7r@alvherre.pgsql> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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/25/22 17:48, Alvaro Herrera wrote: > I just noticed that publishing tables on multiple publications with > different row filters and column lists has somewhat surprising behavior. > To wit: if a column is published in any row-filtered publication, then > the values for that column are sent to the subscriber even for rows that > don't match the row filter, as long as the row matches the row filter > for any other publication, even if that other publication doesn't > include the column. > > Here's an example. > > Publisher: > > create table uno (a int primary key, b int, c int); > create publication uno for table uno (a, b) where (a > 0); > create publication dos for table uno (a, c) where (a < 0); > > Here, we specify: publish columns a,b for rows with positive a, and > publish columns a,c for rows with negative a. > > What happened next will surprise you! Well, maybe not. On subscriber: > > create table uno (a int primary key, b int, c int); > create subscription sub_uno connection 'port=55432 dbname=alvherre' publication uno,dos; > > Publisher: > insert into uno values (1, 2, 3), (-1, 3, 4); > > Publication 'uno' only has columns a and b, so row with a=1 should not > have value c=3. And publication 'dos' only has columns a and c, so row > with a=-1 should not have value b=3. But, on subscriber: > > table uno; > a │ b │ c > ────┼───┼─── > 1 │ 2 │ 3 > -1 │ 3 │ 4 > > q.e.d. > > I think results from a too simplistic view on how to mix multiple > publications with row filters and column lists. IIRC we are saying "if > column X appears in *any* publication, then the value is published", > period, and don't stop to evaluate the row filter corresponding to each > of those publications. > Right. > The desired result on subscriber is: > > table uno; > a │ b │ c > ────┼───┼─── > 1 │ 2 │ > -1 │ │ 4 > > > Thoughts? > I'm not quite sure which of the two behaviors is more "desirable". In a way, it's somewhat similar to publish_as_relid, which is also calculated not considering which of the row filters match? But maybe you're right and it should behave the way you propose ... the example I have in mind is a use case replicating table with two types of rows - sensitive and non-sensitive. For sensitive, we replicate only some of the columns, for non-sensitive we replicate everything. Which could be implemented as two publications create publication sensitive_rows for table t (a, b) where (is_sensitive); create publication non_sensitive_rows for table t where (not is_sensitive); But the way it's implemented now, we'll always replicate all columns, because the second publication has no column list. Changing this to behave the way you expect would be quite difficult, because at the moment we build a single OR expression from all the row filters. We'd have to keep the individual expressions, so that we can build a column list for each of them (in order to ignore those that don't match). We'd have to remove various other optimizations - for example we can't just discard row filters if we found "no_filter" publication. Or more precisely, we'd have to consider column lists too. In other words, we'd have to merge pgoutput_column_list_init into pgoutput_row_filter_init, and then modify pgoutput_row_filter to evaluate the row filters one by one, and build the column list. I can take a stab at it, but it seems strange to not apply the same logic to evaluation of publish_as_relid. I wonder what Amit thinks about this, as he wrote the row filter stuff. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company