Re: policies with security definer option for allowing inline optimization

From: Noah Misch <noah(at)leadboat(dot)com>
To: Dan Lynch <pyramation(at)gmail(dot)com>
Cc: Joe Conway <mail(at)joeconway(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>, Isaac Morland <isaac(dot)morland(at)gmail(dot)com>, PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: policies with security definer option for allowing inline optimization
Date: 2021-04-06 06:20:56
Message-ID: 20210406062056.GA801591@rfd.leadboat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Apr 05, 2021 at 07:51:46PM -0700, Dan Lynch wrote:
> > > I suppose if the
> > > get_group_ids_of_current_user() function is marked as STABLE, would the
> > > optimizer cache this value for every row in a SELECT that returned
> > > multiple rows?
> >
> > While there was a patch to implement caching, it never finished. The
> > optimizer is allowed to, and sometimes does, choose plan shapes that reduce
> > the number of function calls.
>
> So for multiple rows, it's possible that the same query could happen for
> each row? Even if it's clearly stable and only a read operation is
> happening?

Yes. The caching patch thread gives some example queries:
https://postgr.es/m/flat/CABRT9RA-RomVS-yzQ2wUtZ%3Dm-eV61LcbrL1P1J3jydPStTfc6Q%40mail.gmail.com

> I suppose if the possibility exists that this could happen, perhaps using
> RLS for selects is not quite "production ready"?

I would not draw that conclusion.

> Or perhaps if the RLS
> qual/check is written well-enough, then maybe the performance hit wouldn't
> be noticed?

Yes.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Kyotaro Horiguchi 2021-04-06 06:24:21 Re: Stronger safeguard for archive recovery not to miss data
Previous Message tanghy.fnst@fujitsu.com 2021-04-06 06:03:42 RE: Table refer leak in logical replication