mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2026-10-30 16:20:04 -05:00
Update the query that fetches roles to be faster with many roles.
This changes the query that fetches roles from using the pg_catalog.shobj_description function to using an explicit join on pg_catalog.pg_shdescription. In my specific case, in a production system with over 20k roles, this reduces the query time down from 8 minutes(!) down to ~40ms. Just in case it was a locking issue, I did use pg_activity to investigate locks, and nothing was being blocked during the 8 minutes. This fixes a problem that exists only for certain users, and specifically in my case where the user that runs the query is themselves a member (directly and indirectly) of a high number of roles. Running the existing query as a user that has a low number of roles (and specifically, the master user in an AWS RDS database), the existing query is fairly performant. My best explanation as to the performance difference comes from the definition of shobj_description https://github.com/postgres/postgres/blob/2a8a00674e973dec4d7d74d5e16c7d7cdedf2be5/src/backend/catalog/system_functions.sql#L303-L312. Each time it's called it runs a query against pg_shdescription and pg_class, and so in my case runs 20k times, compared to the equivalent of once when doing the explicit join on pg_shdescription. It should also be noted that in my case pg_class is quite big - currently about 500k rows (although it has grown to ~5 million in the past, but that was borderline a mistake). See https://github.com/pgadmin-org/pgadmin4/pull/8457#issue-2853052114 for EXPLAIN ANALYZE results of the existing query and the updated query.
This commit is contained in:
1 parent
5c257fe1b9
commit
83ade5dcc2
1 file changed
+4
-4
+4
-4
@@ -1,8 +1,8 @@
|
||||
SELECT
|
||||
r.oid, r.rolname, r.rolcanlogin, r.rolsuper,
|
||||
pg_catalog.shobj_description(r.oid, 'pg_authid') AS description
|
||||
FROM
|
||||
pg_catalog.pg_roles r
|
||||
r.oid, r.rolname, r.rolcanlogin, r.rolsuper, d.description
|
||||
FROM pg_catalog.pg_roles r
|
||||
LEFT JOIN pg_catalog.pg_shdescription d
|
||||
ON d.objoid = r.oid AND d.classoid = 'pg_catalog.pg_authid'::regclass
|
||||
{% if rid %}
|
||||
WHERE r.oid = {{ rid|qtLiteral(conn) }}::oid
|
||||
{% endif %}
|
||||
|
||||
Reference in new issue
Block a user