他的回复:
我提取了视图information_schema.table_privileges的代码,将其精简了一下,因为我只需要向用户提示有多少个权限就可以,具体的内容让他们自己去查,所以最后改成了这样,达到了预期效果,执行下来12秒左右吧。不知道还能不能加再加速一下。SELECT count(*)FROM (SELECT pg_class.oid, pg_class.relkind,(aclexplode(COALESCE(pg_class.relacl, acldefault('r' :: "char", pg_class.relowner)))).grantee AS granteeFROM pg_class ) c(oid, relkind, grantee),(SELECT pg_authid.oid, pg_authid.rolname FROM pg_authidUNION ALLSELECT 0 :: oid AS oid, 'PUBLIC' :: name AS "?column?") grantee(oid, rolname) WHERE c.relkind = ANY(ARRAY [ 'r' :: "char", 'v' :: "char" ])AND c.grantee = grantee.oid AND(pg_has_role(grantee.oid, 'USAGE' :: text) OR grantee.rolname = 'PUBLIC' :: name)and grantee.rolname='账号名称';