Re: Slow GRANT ROLE on PostgreSQL 16 with thousands of ROLEs

From: alex work <alexwork033(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Nathan Bossart <nathandbossart(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org, Robert Haas <robertmhaas(at)gmail(dot)com>
Subject: Re: Slow GRANT ROLE on PostgreSQL 16 with thousands of ROLEs
Date: 2024-03-22 02:02:57
Message-ID: CAGvXd3OKuu2Qad30PqJ6sQFFkLoV5Rvgkp7r5zu3JXUC+RVRVQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

First of all thank you for looking into this.

At the moment we workaround the problem by altering `acc` ROLE into a SUPERUSER
in PostgreSQL 16 instances. It sidestep the problem and having the lowest cost
to implement for us. While at first we think this feels like opening a security
hole, it does not introduce side effects for **our use case** by the way our
application make use of this `acc` ROLE.

Of course we cannot recommend the workaround we took to others having similar
situation.

On Fri, Mar 22, 2024 at 7:59 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> Nathan Bossart <nathandbossart(at)gmail(dot)com> writes:
> > On Thu, Mar 21, 2024 at 03:40:12PM -0500, Nathan Bossart wrote:
> >> On Thu, Mar 21, 2024 at 04:31:45PM -0400, Tom Lane wrote:
> >>> I don't think we have any really cheap way to de-duplicate the role
> >>> OIDs, especially seeing that it has to be done on-the-fly within the
> >>> collection loop, and the order of roles_list is at least potentially
> >>> interesting. Not sure how to make further progress without a lot of
> >>> work.
>
> >> Assuming these are larger lists, this might benefit from optimizations
> >> involving SIMD intrinsics.
>
> > Never mind. With the reproduction script, I'm only seeing a ~2%
> > improvement with my patches.
>
> Yeah, you cannot beat an O(N^2) problem by throwing SIMD at it.
>
> However ... I just remembered that we have a Bloom filter implementation
> in core now (src/backend/lib/bloomfilter.c). How about using that
> to quickly reject (hopefully) most role OIDs, and only do the
> list_member_oid check if the filter passes?
>
> regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2024-03-22 02:07:19 Re: Slow GRANT ROLE on PostgreSQL 16 with thousands of ROLEs
Previous Message Nathan Bossart 2024-03-22 01:52:51 Re: Slow GRANT ROLE on PostgreSQL 16 with thousands of ROLEs

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2024-03-22 02:07:19 Re: Slow GRANT ROLE on PostgreSQL 16 with thousands of ROLEs
Previous Message Nathan Bossart 2024-03-22 01:52:51 Re: Slow GRANT ROLE on PostgreSQL 16 with thousands of ROLEs