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 1mAZNM-0005FU-WC for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Aug 2021 14:57:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mAZNL-0003jf-N9 for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Aug 2021 14:57:07 +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 1mAZNL-0003jX-Ey for pgsql-hackers@lists.postgresql.org; Mon, 02 Aug 2021 14:57:07 +0000 Received: from smtp-fw-2101.amazon.com ([72.21.196.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mAZNJ-0000FW-8X for pgsql-hackers@postgresql.org; Mon, 02 Aug 2021 14:57:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1627916226; x=1659452226; h=to:cc:references:from:message-id:date:mime-version: in-reply-to:content-transfer-encoding:subject; bh=Gom+TwzBPDOdZQf8hZth72SahPNc9O8/j5ZoElnSaLw=; b=pJGdNzF+q1ZI8SE3uJ68d8LjPWFWJej/XXOm3kwf2mwDT4quWMw5T4Hd lJWD6A2fmKGhuFcvnf7lwQ8lJsaWu4W50HxoD/fIKt+gJ8p1CjjmbWlXD kGdKIT3lMoH5NDL1wVo7Jj4FSyaHW6zIzXLNx4HXuq+9hqE9PWfwu79ft Q=; X-IronPort-AV: E=Sophos;i="5.84,289,1620691200"; d="scan'208";a="126557267" Subject: Re: Minimal logical decoding on standbys Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-2c-456ef9c9.us-west-2.amazon.com) ([10.43.8.2]) by smtp-border-fw-2101.iad2.amazon.com with ESMTP; 02 Aug 2021 14:56:55 +0000 Received: from EX13D03EUC003.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-2c-456ef9c9.us-west-2.amazon.com (Postfix) with ESMTPS id CEC4AC25B3; Mon, 2 Aug 2021 14:56:53 +0000 (UTC) Received: from 38f9d36c4abb.ant.amazon.com (10.43.162.36) by EX13D03EUC003.ant.amazon.com (10.43.164.192) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Mon, 2 Aug 2021 14:56:48 +0000 To: Alvaro Herrera CC: Ibrar Ahmed , Amit Khandekar , Andres Freund , , tushar , "[pgdg] Robert Haas" , Rahila Syed , pgsql-hackers References: <202107281526.o74ieuj6sj7z@alvherre.pgsql> From: "Drouvot, Bertrand" Message-ID: Date: Mon, 2 Aug 2021 16:56:44 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <202107281526.o74ieuj6sj7z@alvherre.pgsql> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [10.43.162.36] X-ClientProxiedBy: EX13D35UWB001.ant.amazon.com (10.43.161.47) 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 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. > 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 instead of opening and closing it time and again. That does make sense, I'll look at it. Bertrand