Re: Views no longer in rangeTabls?

From: David Steele <david(at)pgmasters(dot)net>
To: Amit Langote <amitlangote09(at)gmail(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Views no longer in rangeTabls?
Date: 2023-06-09 14:46:48
Message-ID: 462cd5de-3ade-989b-0798-7e1cab562991@pgmasters.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Amit,

On 6/9/23 14:25, Amit Langote wrote:
> On Fri, Jun 9, 2023 at 17:28 David Steele <david(at)pgmasters(dot)net
> <mailto:david(at)pgmasters(dot)net>> 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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tristan Partin 2023-06-09 14:55:25 Re: Use COPY for populating all pgbench tables
Previous Message Tristan Partin 2023-06-09 14:28:51 Re: Meson build updates