Skip to content

sql: has_column_privilege makes graphile introspection query slow #65551

@RaduBerinde

Description

@RaduBerinde

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_privilege faster?
  • is there a better way to obtain the information that this query is trying to obtain?

CC @rafiss @jordanlewis

Metadata

Metadata

Assignees

Labels

A-tools-graphileIssues relating to graphile compatibilityC-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.T-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions