You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In pg_dump, avoid doing per-table queries for RLS policies.
For no particularly good reason, getPolicies() queried pg_policy
separately for each table. We can collect all the policies in
a single query instead, and attach them to the correct TableInfo
objects using findTableByOid() lookups. On the regression
database, this reduces the number of queries substantially, and
provides a visible savings even when running against a local
server.
Per complaint from Hubert Depesz Lubaczewski. Since this is such
a simple fix and can have a visible performance benefit, back-patch
to all supported branches.
Discussion: https://postgr.es/m/20210826084430.GA26282@depesz.com
" pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, "
3743
-
"pg_catalog.pg_get_expr(pol.polqual, pol.polrelid) AS polqual, "
3744
-
"pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid) AS polwithcheck "
3745
-
"FROM pg_catalog.pg_policy pol "
3746
-
"WHERE polrelid = '%u'",
3747
-
tbinfo->dobj.catId.oid);
3748
-
else
3749
-
appendPQExpBuffer(query,
3750
-
"SELECT oid, tableoid, pol.polname, pol.polcmd, 't' as polpermissive, "
3751
-
"CASE WHEN pol.polroles = '{0}' THEN NULL ELSE "
3752
-
" pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, "
3753
-
"pg_catalog.pg_get_expr(pol.polqual, pol.polrelid) AS polqual, "
3754
-
"pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid) AS polwithcheck "
3755
-
"FROM pg_catalog.pg_policy pol "
3756
-
"WHERE polrelid = '%u'",
3757
-
tbinfo->dobj.catId.oid);
3758
-
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
3728
+
/*
3729
+
* Now, read all RLS policies, and create PolicyInfo objects for all those
appendPQExpBuffer(query, "'t' as polpermissive, ");
3740
+
appendPQExpBuffer(query,
3741
+
"CASE WHEN pol.polroles = '{0}' THEN NULL ELSE "
3742
+
" pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, "
3743
+
"pg_catalog.pg_get_expr(pol.polqual, pol.polrelid) AS polqual, "
3744
+
"pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid) AS polwithcheck "
3745
+
"FROM pg_catalog.pg_policy pol");
3761
3746
3762
-
if (ntups == 0)
3763
-
{
3764
-
/*
3765
-
* No explicit policies to handle (only the default-deny policy,
3766
-
* which is handled as part of the table definition). Clean up
3767
-
* and return.
3768
-
*/
3769
-
PQclear(res);
3770
-
continue;
3771
-
}
3747
+
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
0 commit comments