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

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

I wrote:
> It looks like part of the blame might be ascribable to catcache.c,
> as if you look at the problem microscopically you find that
> roles_is_member_of is causing catcache to make a ton of AUTHMEMMEMROLE
> catcache lists, and SearchSysCacheList is just iterating linearly
> through the cache's list-of-lists, so that search is where the O(N^2)
> time is actually getting taken. Up to now that code has assumed that
> any one catcache would not have very many catcache lists. Maybe it's
> time to make that smarter; but since we've gotten away with this
> implementation for decades, I can't help feeling that the real issue
> is with roles_is_member_of's usage pattern.

I wrote a quick finger exercise to make catcache.c use a hash table
instead of a single list for CatCLists, modeling it closely on the
existing hash logic for simple catcache entries. This helps a good
deal, but I still see the problematic GRANT taking ~250ms, compared
to 5ms in v15. roles_is_member_of is clearly on the hook for that.

regards, tom lane

Attachment Content-Type Size
v1-use-hash-table-for-CatCLists.patch text/x-diff 10.2 KB

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2024-03-21 20:31:45 Re: Slow GRANT ROLE on PostgreSQL 16 with thousands of ROLEs
Previous Message veem v 2024-03-21 19:12:42 Re: Not able to purge partition

Browse pgsql-hackers by date

  From Date Subject
Next Message David Christensen 2024-03-21 19:42:24 Re: Avoiding inadvertent debugging mode for pgbench
Previous Message Corey Huinker 2024-03-21 19:33:29 Re: Statistics Import and Export