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 1q7dOI-00083o-Ab for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Jun 2023 14:47:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q7dOG-0003F5-LS for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Jun 2023 14:47:00 +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 1q7dOG-0003Ew-AX for pgsql-hackers@lists.postgresql.org; Fri, 09 Jun 2023 14:47:00 +0000 Received: from mail.thelabyrinth.net ([45.56.70.56]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1q7dO9-0015yl-D3 for pgsql-hackers@postgresql.org; Fri, 09 Jun 2023 14:46:58 +0000 Received: from [10.5.0.2] (unknown [185.199.103.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: dsteele) by mail.thelabyrinth.net (Postfix) with ESMTPSA id 0D66854669; Fri, 9 Jun 2023 14:46:51 +0000 (UTC) Message-ID: <462cd5de-3ade-989b-0798-7e1cab562991@pgmasters.net> Date: Fri, 9 Jun 2023 17:46:48 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.11.1 Subject: Re: Views no longer in rangeTabls? Content-Language: en-US To: Amit Langote Cc: Pg Hackers References: <3953179e-9540-e5d1-a743-4bef368785b0@pgmasters.net> From: David Steele In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Amit, On 6/9/23 14:25, Amit Langote wrote: > On Fri, Jun 9, 2023 at 17:28 David Steele > wrote: > > In prior versions of Postgres, views were listed in rangeTabls when > ExecutorCheckPerms_hook() was called but in PG16 the views are no > longer > in this list. > > I’m not exactly sure how pgAudit’s code is searching for view relations > in the range table, but if the code involves filtering on rtekind == > RTE_RELATION, then yes, such code won’t find views anymore. That’s > because the rewriter no longer adds extraneous RTE_RELATION RTEs for > views into the range table. Views are still there, it’s just that their > RTEs are of kind RTE_SUBQUERY, but they do contain some RELATION fields > like relid, rellockmode, etc.  So an extension hook’s relation RTE > filtering code should also consider relid, not just rtekind. Thank you, this was very helpful. I am able to get the expected result now with: /* We only care about tables/views and can ignore subqueries, etc. */ if (!(rte->rtekind == RTE_RELATION || (rte->rtekind == RTE_SUBQUERY && OidIsValid(rte->relid)))) continue; One thing, though, rte->relkind is not set for views, so I still need to call get_rel_relkind(rte->relid). Not a big deal, but do you think it would make sense to set rte->relkind for views? > Perhaps, we are missing a comment near the hook definition mentioning > this detail about views. I don't see any meaningful comments near the hook definition. That would certainly be helpful. Thanks! -David