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
Regular per-column statistics are stored in pg_statistics catalog, which
is however rather difficult to read, so we also have pg_stats view with
a human-reablable version of the data.
For extended statistic the catalog was fairly easy to read, so we did
not have such human-readable view so far. Commit 9b6babfa2d however did
split the catalog into two, which makes querying harder. Furthermore,
we want to show the multi-column MCV list in a way similar to per-column
stats (and not as a bytea value).
This commit introduces pg_stats_ext view, joining the two catalogs and
massaging the data to produce human-readable output similar to pg_stats.
It also considers RLS and access privileges - the data is shown only when
the user has access to all columns the extended statistic is defined on.
Bumped CATVERSION due to adding new system view.
Author: Dean Rasheed, with improvements by me
Reviewed-by: Dean Rasheed, John Naylor
Discussion: https://postgr.es/m/CAEZATCUhT9rt7Ui%3DVdx4N%3D%3DVV5XOK5dsXfnGgVOz_JhAicB%3DZA%40mail.gmail.com
Copy file name to clipboardExpand all lines: src/test/regress/expected/rules.out
+29
Original file line number
Diff line number
Diff line change
@@ -2284,6 +2284,35 @@ pg_stats| SELECT n.nspname AS schemaname,
2284
2284
JOIN pg_attribute a ON (((c.oid = a.attrelid) AND (a.attnum = s.staattnum))))
2285
2285
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
2286
2286
WHERE ((NOT a.attisdropped) AND has_column_privilege(c.oid, a.attnum, 'select'::text) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid))));
2287
+
pg_stats_ext| SELECT cn.nspname AS schemaname,
2288
+
c.relname AS tablename,
2289
+
sn.nspname AS statistics_schemaname,
2290
+
s.stxname AS statistics_name,
2291
+
pg_get_userbyid(s.stxowner) AS statistics_owner,
2292
+
( SELECT array_agg(a.attname ORDER BY a.attnum) AS array_agg
2293
+
FROM (unnest(s.stxkeys) k(k)
2294
+
JOIN pg_attribute a ON (((a.attrelid = s.stxrelid) AND (a.attnum = k.k))))) AS attnames,
2295
+
s.stxkind AS kinds,
2296
+
sd.stxdndistinct AS n_distinct,
2297
+
sd.stxddependencies AS dependencies,
2298
+
m.most_common_vals,
2299
+
m.most_common_val_nulls,
2300
+
m.most_common_freqs,
2301
+
m.most_common_base_freqs
2302
+
FROM (((((pg_statistic_ext s
2303
+
JOIN pg_class c ON ((c.oid = s.stxrelid)))
2304
+
JOIN pg_statistic_ext_data sd ON ((s.oid = sd.stxoid)))
2305
+
LEFT JOIN pg_namespace cn ON ((cn.oid = c.relnamespace)))
2306
+
LEFT JOIN pg_namespace sn ON ((sn.oid = s.stxnamespace)))
2307
+
LEFT JOIN LATERAL ( SELECT array_agg(pg_mcv_list_items."values") AS most_common_vals,
2308
+
array_agg(pg_mcv_list_items.nulls) AS most_common_val_nulls,
2309
+
array_agg(pg_mcv_list_items.frequency) AS most_common_freqs,
2310
+
array_agg(pg_mcv_list_items.base_frequency) AS most_common_base_freqs
2311
+
FROM pg_mcv_list_items(sd.stxdmcv) pg_mcv_list_items(index, "values", nulls, frequency, base_frequency)) m ON ((sd.stxdmcv IS NOT NULL)))
2312
+
WHERE ((NOT (EXISTS ( SELECT 1
2313
+
FROM (unnest(s.stxkeys) k(k)
2314
+
JOIN pg_attribute a ON (((a.attrelid = s.stxrelid) AND (a.attnum = k.k))))
2315
+
WHERE (NOT has_column_privilege(c.oid, a.attnum, 'select'::text))))) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid))));
0 commit comments