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 1mOEJp-0007Ui-51 for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Sep 2021 07:17:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mOEJm-0003m8-HV for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Sep 2021 07:17:54 +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 1mOEJl-0003m0-MJ for pgsql-hackers@lists.postgresql.org; Thu, 09 Sep 2021 07:17:53 +0000 Received: from smtp-fw-9103.amazon.com ([207.171.188.200]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mOEJj-0007fD-1b for pgsql-hackers@postgresql.org; Thu, 09 Sep 2021 07:17:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1631171871; x=1662707871; h=from:subject:to:cc:references:message-id:date: mime-version:in-reply-to; bh=eI7m0YkI+rhbCbYl5DYJHq9jC7ATtNIXiF6276/7bjA=; b=uSVgRtRuZlnWmSba09WrzGSk73iFkKzVNlbj9sT5P/qyQehZE/QWT0fS /naH3zfYW5V621xyz3V9B1THL/1wtlQ8VBfRxfZTefSy4Rz+u/xhuYjAn xEOLImL/o0vkI5L1SHMoGQ3FTBUUIBCOpxropDwm9nS1iO4Civ6rA1Grm U=; X-IronPort-AV: E=Sophos;i="5.85,279,1624320000"; d="scan'208,217";a="956524652" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-1a-7d76a15f.us-east-1.amazon.com) ([10.25.36.210]) by smtp-border-fw-9103.sea19.amazon.com with ESMTP; 09 Sep 2021 07:17:39 +0000 Received: from EX13D03EUC003.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-1a-7d76a15f.us-east-1.amazon.com (Postfix) with ESMTPS id 90404A1ADD; Thu, 9 Sep 2021 07:17:36 +0000 (UTC) Received: from 38f9d36c4abb.ant.amazon.com (10.43.161.82) by EX13D03EUC003.ant.amazon.com (10.43.164.192) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Thu, 9 Sep 2021 07:17:32 +0000 From: "Drouvot, Bertrand" Subject: Re: Minimal logical decoding on standbys To: Alvaro Herrera CC: Ibrar Ahmed , Amit Khandekar , Andres Freund , , tushar , "[pgdg] Robert Haas" , Rahila Syed , pgsql-hackers References: <202107281526.o74ieuj6sj7z@alvherre.pgsql> Message-ID: Date: Thu, 9 Sep 2021 09:17:27 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------26F3DC7BFE89E934791EB596" Content-Language: en-US X-Originating-IP: [10.43.161.82] X-ClientProxiedBy: EX13D20UWC003.ant.amazon.com (10.43.162.18) To EX13D03EUC003.ant.amazon.com (10.43.164.192) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --------------26F3DC7BFE89E934791EB596 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit Hi Alvaro, On 8/2/21 4:56 PM, Drouvot, Bertrand wrote: > Hi Alvaro, > > On 7/28/21 5:26 PM, Alvaro Herrera wrote: >> On 2021-Jul-27, Drouvot, Bertrand wrote: >> >>> diff --git a/src/backend/utils/cache/lsyscache.c >>> b/src/backend/utils/cache/lsyscache.c >>> +bool >>> +get_rel_logical_catalog(Oid relid) >>> +{ >>> +     bool    res; >>> +     Relation rel; >>> + >>> +     /* assume previously locked */ >>> +     rel = table_open(relid, NoLock); >>> +     res = RelationIsAccessibleInLogicalDecoding(rel); >>> +     table_close(rel, NoLock); >>> + >>> +     return res; >>> +} >> So RelationIsAccessibleInLogicalDecoding() does a cheap check for >> wal_level which can be done without opening the table; I think this >> function should be rearranged to avoid doing that when not needed. > > Thanks for looking at it. > > >> Also, putting this function in lsyscache.c seems somewhat wrong since >> it's not merely accessing the system caches ... >> >> I think it would be better to move this elsewhere (relcache.c, proto in >> relcache.h, perhaps call it RelationIdIsAccessibleInLogicalDecoding) and >> short-circuit for the check that can be done before opening the table. So you have in mind to check for XLogLogicalInfoActive() first, and if true, then open the relation and call RelationIsAccessibleInLogicalDecoding()? If so, then what about also creating a new RelationIsAccessibleWhileLogicalWalLevel() or something like this doing the same as RelationIsAccessibleInLogicalDecoding() but without the XLogLogicalInfoActive() check? >> At least the GiST code appears to be able to call this several times per >> vacuum run, so it makes sense to short-circuit it for the fast case. >> >> ... though looking at the GiST code again I wonder if it would be more >> sensible to just stash the table's Relation pointer somewhere in the >> context structs Do you have a "good place" in mind? Thanks Bertrand --------------26F3DC7BFE89E934791EB596 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: 8bit

Hi Alvaro,

On 8/2/21 4:56 PM, Drouvot, Bertrand wrote:
Hi Alvaro,

On 7/28/21 5:26 PM, Alvaro Herrera wrote:
On 2021-Jul-27, Drouvot, Bertrand wrote:

diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c
+bool
+get_rel_logical_catalog(Oid relid)
+{
+     bool    res;
+     Relation rel;
+
+     /* assume previously locked */
+     rel = table_open(relid, NoLock);
+     res = RelationIsAccessibleInLogicalDecoding(rel);
+     table_close(rel, NoLock);
+
+     return res;
+}
So RelationIsAccessibleInLogicalDecoding() does a cheap check for
wal_level which can be done without opening the table; I think this
function should be rearranged to avoid doing that when not needed.

Thanks for looking at it.


Also, putting this function in lsyscache.c seems somewhat wrong since
it's not merely accessing the system caches ...

I think it would be better to move this elsewhere (relcache.c, proto in
relcache.h, perhaps call it RelationIdIsAccessibleInLogicalDecoding) and
short-circuit for the check that can be done before opening the table.

So you have in mind to check for XLogLogicalInfoActive() first, and if true, then open the relation and call
RelationIsAccessibleInLogicalDecoding()?

If so, then what about also creating a new RelationIsAccessibleWhileLogicalWalLevel() or something like this doing the same as RelationIsAccessibleInLogicalDecoding() but without the XLogLogicalInfoActive() check?

At least the GiST code appears to be able to call this several times per
vacuum run, so it makes sense to short-circuit it for the fast case.

... though looking at the GiST code again I wonder if it would be more
sensible to just stash the table's Relation pointer somewhere in the
context structs

Do you have a "good place" in mind?

Thanks

Bertrand

--------------26F3DC7BFE89E934791EB596--