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 1nRwkk-0000UD-Qt for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Mar 2022 13:53:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nRwkj-0007BU-Az for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Mar 2022 13:53:21 +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 1nRwki-00077r-IS for pgsql-hackers@lists.postgresql.org; Wed, 09 Mar 2022 13:53:21 +0000 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nRwkf-00039U-A7 for pgsql-hackers@postgresql.org; Wed, 09 Mar 2022 13:53:19 +0000 Received: by mail-ej1-x62f.google.com with SMTP id yy13so5216273ejb.2 for ; Wed, 09 Mar 2022 05:53:17 -0800 (PST) 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=EsjPbjrfnXffAeDAFbZhnoN239ar0HoQu7BqDr696S8=; b=TZgccylJugiTMH0UGFdSMRytxKQ2mGLed78/ZpRIR1MbfW18uO63sb8qfaM4liHLA3 xRWOOMIPQKu9Wmu+VZ2cKqIrdLYqsJH+GzHYPJ0BjJp4EDetIRC0LsuzRPwqnfg8w/Xi MSF0vezKTKJ/DSeo8nKTxGqER8lUJEk6h3hpz0YqAQRJB9+Nm1zi3lsqtHKfyb+A/7JK ClZcqF7Xp48cRlR66nYk281SiEUekkMN9gsUv1Flf0OKDnpC+SoJAKpP+lvDeAsFIhU9 6iJArcftNNQwdqSfsCkm5HgFh4PChTzW3b3TLpQevLixBpOQcUXYv8MyBO1Ir3c7+qUS /PKg== 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=EsjPbjrfnXffAeDAFbZhnoN239ar0HoQu7BqDr696S8=; b=Clh1dOcXDzhrE9DILszcppSY9/weuuM96OWBtys1/NSkz/Qndm8s9yhm3nIsdYq3Jm X4OpKACPFU+eTD75xFcUUr30u9WehFjBhFUSiok4QDWfCffQhfUdisNfxfTfV/KG+pfJ ODYHk+pwGXDGX/IVkLu9XlghXriMWgF12fCPmOI45C+yDp+jNdDkqINAWufuQNwSvwl3 YA/fAZVUCD64bA5JjT0EsQCtXulhf7mLyzsvwi3v4hAAWKHIRFc/ZM/q5bdU7f58Y8Dh z9MDxZX4YELsCSMWthZZ0kbhnbe3X5y9blskqMlS1EETS72HynDunjvsymlFJg2ojbCv 1r1Q== X-Gm-Message-State: AOAM5305ZiezUcblfr9nJII769ClQOzBeDWnjWCa+5wQvhkeOK3f6i6Q trqa/OkumexBQSzTCLoxmZ1XNSQ1HSG8/hGWOkmDmp9piOj1u9FzSTxmw8JPIISf5YhQ8Yj0mpp +RjFsCI64/9Pt46g1g99BVmye4mDmB7IYGR2iB1Krwi74mAbmnZDH9OhhcEOA7dpJIYvuKFBVAy J4WU+sdRlbFBzLHz9vN+Ro0LlroW5p3/YPegC6 X-Google-Smtp-Source: ABdhPJyl4MENOZWLPqdso+ZLyAi/+D2f6KxRJ9s3EZth0hIGBLweZWwORMxh20yOGngedr83nrl3dQ== X-Received: by 2002:a17:906:b157:b0:6d0:9f3b:a6aa with SMTP id bt23-20020a170906b15700b006d09f3ba6aamr17631255ejb.365.1646833995657; Wed, 09 Mar 2022 05:53:15 -0800 (PST) Received: from [10.137.0.19] (ip-86-49-251-241.net.upcbroadband.cz. [86.49.251.241]) by smtp.gmail.com with ESMTPSA id hg11-20020a1709072ccb00b006cee4fb36c7sm785685ejc.64.2022.03.09.05.53.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 09 Mar 2022 05:53:14 -0800 (PST) Message-ID: <7ce6a43a-830a-931f-d311-a5bfd444b3ae@enterprisedb.com> Date: Wed, 9 Mar 2022 14:53:12 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: Column Filtering in Logical Replication Content-Language: en-US To: Amit Kapila Cc: Peter Eisentraut , Alvaro Herrera , Justin Pryzby , "houzj.fnst@fujitsu.com" , Rahila Syed , Peter Smith , pgsql-hackers , shiy.fnst@fujitsu.com References: <202201120041.p24wvsfcsope@alvherre.pgsql> 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 3/9/22 11:03, Amit Kapila wrote: > ... >> Hmm, yeah. That seems like a genuine problem - it should not depend on >> the order of publications in the subscription, I guess. >> >> But is it an issue in the patch? Isn't that a pre-existing issue? AFAICS >> the problem is that we initialize publish_as_relid=relid before the loop >> over publications, and then just update it. So the first iteration >> starts with relid, but the second iteration ends with whatever value is >> set by the first iteration (e.g. the root). >> >> So with the example you posted, we start with >> >> publish_as_relid = relid = test_part1 >> >> but then if the first publication is pubviaroot=true, we update it to >> parent. And in the second iteration, we fail to find the column filter, >> because "parent" (publish_as_relid) is not part of the pub2. >> >> If we do it in the other order, we leave the publish_as_relid value as >> is (and find the filter), and then update it in the second iteration >> (and find the column filter too). >> >> Now, this can be resolved by re-calculating the publish_as_relid from >> scratch in each iteration (start with relid, then maybe update it). But >> that's just half the story - the issue is there even without column >> filters. Consider this example: >> >> create table t (a int, b int, c int) partition by range (a); >> >> create table t_1 partition of t for values from (1) to (10) >> partition by range (a); >> >> create table t_2 partition of t_1 for values from (1) to (10); >> >> create publication pub1 for table t(a) >> with (PUBLISH_VIA_PARTITION_ROOT); >> >> create publication pub2 for table t_1(a) >> with (PUBLISH_VIA_PARTITION_ROOT); >> >> >> Now, is you change subscribe to "pub1, pub2" and "pub2, pub1", we'll end >> up with different publish_as_relid values (t or t_1). Which seems like >> the same ambiguity issue. >> > > I think we should fix this existing problem by always using the > top-most table as publish_as_relid. Basically, we can check, if the > existing publish_as_relid is an ancestor of a new rel that is going to > replace it then we shouldn't replace it. Right, using the topmost relid from all publications seems like the correct solution. > However, I think even if we > fix the existing problem, we will still have the order problem for the > column filter patch, and to avoid that instead of fetching column > filters in the publication loop, we should use the final > publish_as_relid. I think it will have another problem as well if we > don't use final publish_as_relid which is that sometimes when we > should not use any filter (say when pubviaroot is true and that > publication has root partitioned table which has no filter) as per our > rule of filters for a partitioned table, it can still use some filter > from the non-root table. > Yeah, the current behavior is just a consequence of how we determine publish_as_relid now. If we rework that, we should first determine the relid and then fetch the filter only for that single rel. >> >>> * >>> Fetching column filter info in tablesync.c is quite expensive. It >>> seems to be using four round-trips to get the complete info whereas >>> for row-filter we use just one round trip. I think we should try to >>> get both row filter and column filter info in just one round trip. >>> >> >> Maybe, but I really don't think this is an issue. >> > > I am not sure but it might matter for small tables. Leaving aside the > performance issue, I think the current way will get the wrong column > list in many cases: (a) The ALL TABLES IN SCHEMA case handling won't > work for partitioned tables when the partitioned table is part of one > schema and partition table is part of another schema. (b) The handling > of partition tables in other cases will fetch incorrect lists as it > tries to fetch the column list of all the partitions in the hierarchy. > > One of my colleagues has even tested these cases both for column > filters and row filters and we find the behavior of row filter is okay > whereas for column filter it uses the wrong column list. We will share > the tests and results with you in a later email. We are trying to > unify the column filter queries with row filter to make their behavior > the same and will share the findings once it is done. I hope if we are > able to achieve this that we will reduce the chances of bugs in this > area. > OK, I'll take a look at that email. > Note: I think the first two patches for tests are not required after > commit ceb57afd3c. > Right. Will remove. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company