-
Notifications
You must be signed in to change notification settings - Fork 4.1k
sql: has_column_privilege makes graphile introspection query slow #65551
Description
Graphile uses this big introspection query: https://gist.githubusercontent.com/benjie/914776880c85d2ac7a3c260e08aa29b7/raw/b3993e17e4c56999c7470452a7a401437db2b2ac/introspection_query_cut_down_for_cockroach.sql
With #65550 this query now runs but it takes a very long time (20-30s).
I have narrowed the problem (or at least a problem) to the attribute_partial CTE; in particular the use of has_column_privilege:
exists(select 1 from accessible_roles where has_column_privilege(accessible_roles.oid, att.attrelid, att.attname, 'SELECT')) as "aclSelectable",
exists(select 1 from accessible_roles where has_column_privilege(accessible_roles.oid, att.attrelid, att.attname, 'INSERT')) as "aclInsertable",
exists(select 1 from accessible_roles where has_column_privilege(accessible_roles.oid, att.attrelid, att.attname, 'UPDATE')) as "aclUpdatable",
It looks like every single evaluation of this function internally spawns multiple internal queries! The optimizer is trying to decorrelate and creates nested joins, with these expressions pushed down (which is making the problem worse). But even a manual rewrite that keeps these at the top is still pretty slow: https://gist.github.com/RaduBerinde/51a348331e5a019e2c25dbf3c4be7241#file-graphile-1-sql
We can pull on two threads here:
- how can we make
has_column_privilegefaster? - is there a better way to obtain the information that this query is trying to obtain?