From 434a2838fec308b8ba8e4279b4c7f8c51f183438 Mon Sep 17 00:00:00 2001 From: Corey Huinker Date: Tue, 10 Mar 2026 13:51:00 -0400 Subject: [PATCH v7 2/3] Add tableid, statid, attnum, expr_attnum columns to pg_stats views. Add tableid and attnum columns to pg_stats. Add tableid, statid columns to pg_stats_ext. Add tableid, statid, expr_attnum columns to pg_stats_ext_exprs. The primary purpose of this patch is to expose the starelid column of pg_statistic in the pg_stats view. Having this available will allow us to simplify some code in pg_dump which currently has to store arrays of nspname+relname in order to fetch a resonable amount of statistics in one query. Furthermore, the query used in pg_dump requires a redundant qual in the WHERE clause to ensure that it uses a specific index, thus avoiding a hash join and the expensive sequential scan of pg_statistic that that entails. This patch makes simlilar changes to pg_stats_ext and pg_stats_ext_exprs, but there is no immediate need to utlize those changes in pg_dump. --- doc/src/sgml/system-views.sgml | 72 +++++++++ src/backend/catalog/system_views.sql | 171 +++++++++++---------- src/test/regress/expected/rules.out | 121 ++++++++------- src/test/regress/expected/stats_import.out | 150 +++++++++--------- src/test/regress/sql/stats_import.sql | 2 +- 5 files changed, 302 insertions(+), 214 deletions(-) diff --git a/doc/src/sgml/system-views.sgml b/doc/src/sgml/system-views.sgml index e5fe423fc61..199e7747a54 100644 --- a/doc/src/sgml/system-views.sgml +++ b/doc/src/sgml/system-views.sgml @@ -4414,6 +4414,16 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx + + + tableid oid + (references pg_attribute.attrelid) + + + ID of the table + + + attname name @@ -4424,6 +4434,16 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx + + + attnum int2 + (references pg_attribute.attnum) + + + Position of column described by this row + + + inherited bool @@ -4666,6 +4686,16 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx + + + tableid oid + (references pg_statistic_ext.stxrelid) + + + ID of the table + + + statistics_schemaname name @@ -4686,6 +4716,16 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx + + + statid oid + (references pg_statistic_ext.oid) + + + ID of the extended statistics object + + + statistics_owner name @@ -4877,6 +4917,16 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx + + + tableid oid + (references pg_statistic_ext.stxrelid) + + + ID of the table + + + statistics_schemaname name @@ -4897,6 +4947,16 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx + + + statid oid + (references pg_statistic_ext.oid) + + + ID of the extended statistics object + + + statistics_owner name @@ -4916,6 +4976,18 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx + + + expr_attnum int2 + + + Synthetic attnum used to reference this expression in + pg_statistic_ext_data.stxdndistinct + and + pg_statistic_ext_data.stxddependencies + + + inherited bool diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 90d48bc9c80..068e9cdaa43 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -189,9 +189,11 @@ CREATE VIEW pg_sequences AS CREATE VIEW pg_stats WITH (security_barrier) AS SELECT - nspname AS schemaname, - relname AS tablename, - attname AS attname, + n.nspname AS schemaname, + c.relname AS tablename, + a.attrelid AS tableid, + a.attname AS attname, + a.attnum AS attnum, stainherit AS inherited, stanullfrac AS null_frac, stawidth AS avg_width, @@ -278,8 +280,10 @@ REVOKE ALL ON pg_statistic FROM public; CREATE VIEW pg_stats_ext WITH (security_barrier) AS SELECT cn.nspname AS schemaname, c.relname AS tablename, + s.stxrelid AS tableid, sn.nspname AS statistics_schemaname, s.stxname AS statistics_name, + s.oid AS statid, pg_get_userbyid(s.stxowner) AS statistics_owner, ( SELECT array_agg(a.attname ORDER BY a.attnum) FROM unnest(s.stxkeys) k @@ -312,92 +316,97 @@ CREATE VIEW pg_stats_ext WITH (security_barrier) AS CREATE VIEW pg_stats_ext_exprs WITH (security_barrier) AS SELECT cn.nspname AS schemaname, c.relname AS tablename, + s.stxrelid AS tableid, sn.nspname AS statistics_schemaname, s.stxname AS statistics_name, + s.oid AS statid, pg_get_userbyid(s.stxowner) AS statistics_owner, - stat.expr, + expr.expr, + 0 - expr.ordinality AS expr_attnum, sd.stxdinherit AS inherited, - (stat.a).stanullfrac AS null_frac, - (stat.a).stawidth AS avg_width, - (stat.a).stadistinct AS n_distinct, - (CASE - WHEN (stat.a).stakind1 = 1 THEN (stat.a).stavalues1 - WHEN (stat.a).stakind2 = 1 THEN (stat.a).stavalues2 - WHEN (stat.a).stakind3 = 1 THEN (stat.a).stavalues3 - WHEN (stat.a).stakind4 = 1 THEN (stat.a).stavalues4 - WHEN (stat.a).stakind5 = 1 THEN (stat.a).stavalues5 - END) AS most_common_vals, - (CASE - WHEN (stat.a).stakind1 = 1 THEN (stat.a).stanumbers1 - WHEN (stat.a).stakind2 = 1 THEN (stat.a).stanumbers2 - WHEN (stat.a).stakind3 = 1 THEN (stat.a).stanumbers3 - WHEN (stat.a).stakind4 = 1 THEN (stat.a).stanumbers4 - WHEN (stat.a).stakind5 = 1 THEN (stat.a).stanumbers5 - END) AS most_common_freqs, - (CASE - WHEN (stat.a).stakind1 = 2 THEN (stat.a).stavalues1 - WHEN (stat.a).stakind2 = 2 THEN (stat.a).stavalues2 - WHEN (stat.a).stakind3 = 2 THEN (stat.a).stavalues3 - WHEN (stat.a).stakind4 = 2 THEN (stat.a).stavalues4 - WHEN (stat.a).stakind5 = 2 THEN (stat.a).stavalues5 - END) AS histogram_bounds, - (CASE - WHEN (stat.a).stakind1 = 3 THEN (stat.a).stanumbers1[1] - WHEN (stat.a).stakind2 = 3 THEN (stat.a).stanumbers2[1] - WHEN (stat.a).stakind3 = 3 THEN (stat.a).stanumbers3[1] - WHEN (stat.a).stakind4 = 3 THEN (stat.a).stanumbers4[1] - WHEN (stat.a).stakind5 = 3 THEN (stat.a).stanumbers5[1] - END) correlation, - (CASE - WHEN (stat.a).stakind1 = 4 THEN (stat.a).stavalues1 - WHEN (stat.a).stakind2 = 4 THEN (stat.a).stavalues2 - WHEN (stat.a).stakind3 = 4 THEN (stat.a).stavalues3 - WHEN (stat.a).stakind4 = 4 THEN (stat.a).stavalues4 - WHEN (stat.a).stakind5 = 4 THEN (stat.a).stavalues5 - END) AS most_common_elems, - (CASE - WHEN (stat.a).stakind1 = 4 THEN (stat.a).stanumbers1 - WHEN (stat.a).stakind2 = 4 THEN (stat.a).stanumbers2 - WHEN (stat.a).stakind3 = 4 THEN (stat.a).stanumbers3 - WHEN (stat.a).stakind4 = 4 THEN (stat.a).stanumbers4 - WHEN (stat.a).stakind5 = 4 THEN (stat.a).stanumbers5 - END) AS most_common_elem_freqs, - (CASE - WHEN (stat.a).stakind1 = 5 THEN (stat.a).stanumbers1 - WHEN (stat.a).stakind2 = 5 THEN (stat.a).stanumbers2 - WHEN (stat.a).stakind3 = 5 THEN (stat.a).stanumbers3 - WHEN (stat.a).stakind4 = 5 THEN (stat.a).stanumbers4 - WHEN (stat.a).stakind5 = 5 THEN (stat.a).stanumbers5 - END) AS elem_count_histogram, - (CASE - WHEN (stat.a).stakind1 = 6 THEN (stat.a).stavalues1 - WHEN (stat.a).stakind2 = 6 THEN (stat.a).stavalues2 - WHEN (stat.a).stakind3 = 6 THEN (stat.a).stavalues3 - WHEN (stat.a).stakind4 = 6 THEN (stat.a).stavalues4 - WHEN (stat.a).stakind5 = 6 THEN (stat.a).stavalues5 - END) AS range_length_histogram, - (CASE - WHEN (stat.a).stakind1 = 6 THEN (stat.a).stanumbers1[1] - WHEN (stat.a).stakind2 = 6 THEN (stat.a).stanumbers2[1] - WHEN (stat.a).stakind3 = 6 THEN (stat.a).stanumbers3[1] - WHEN (stat.a).stakind4 = 6 THEN (stat.a).stanumbers4[1] - WHEN (stat.a).stakind5 = 6 THEN (stat.a).stanumbers5[1] - END) AS range_empty_frac, - (CASE - WHEN (stat.a).stakind1 = 7 THEN (stat.a).stavalues1 - WHEN (stat.a).stakind2 = 7 THEN (stat.a).stavalues2 - WHEN (stat.a).stakind3 = 7 THEN (stat.a).stavalues3 - WHEN (stat.a).stakind4 = 7 THEN (stat.a).stavalues4 - WHEN (stat.a).stakind5 = 7 THEN (stat.a).stavalues5 - END) AS range_bounds_histogram + a.stanullfrac AS null_frac, + a.stawidth AS avg_width, + a.stadistinct AS n_distinct, + CASE + WHEN a.stakind1 = 1 THEN a.stavalues1 + WHEN a.stakind2 = 1 THEN a.stavalues2 + WHEN a.stakind3 = 1 THEN a.stavalues3 + WHEN a.stakind4 = 1 THEN a.stavalues4 + WHEN a.stakind5 = 1 THEN a.stavalues5 + END AS most_common_vals, + CASE + WHEN a.stakind1 = 1 THEN a.stanumbers1 + WHEN a.stakind2 = 1 THEN a.stanumbers2 + WHEN a.stakind3 = 1 THEN a.stanumbers3 + WHEN a.stakind4 = 1 THEN a.stanumbers4 + WHEN a.stakind5 = 1 THEN a.stanumbers5 + END AS most_common_freqs, + CASE + WHEN a.stakind1 = 2 THEN a.stavalues1 + WHEN a.stakind2 = 2 THEN a.stavalues2 + WHEN a.stakind3 = 2 THEN a.stavalues3 + WHEN a.stakind4 = 2 THEN a.stavalues4 + WHEN a.stakind5 = 2 THEN a.stavalues5 + END AS histogram_bounds, + CASE + WHEN a.stakind1 = 3 THEN a.stanumbers1[1] + WHEN a.stakind2 = 3 THEN a.stanumbers2[1] + WHEN a.stakind3 = 3 THEN a.stanumbers3[1] + WHEN a.stakind4 = 3 THEN a.stanumbers4[1] + WHEN a.stakind5 = 3 THEN a.stanumbers5[1] + END AS correlation, + CASE + WHEN a.stakind1 = 4 THEN a.stavalues1 + WHEN a.stakind2 = 4 THEN a.stavalues2 + WHEN a.stakind3 = 4 THEN a.stavalues3 + WHEN a.stakind4 = 4 THEN a.stavalues4 + WHEN a.stakind5 = 4 THEN a.stavalues5 + END aS most_common_elems, + CASE + WHEN a.stakind1 = 4 THEN a.stanumbers1 + WHEN a.stakind2 = 4 THEN a.stanumbers2 + WHEN a.stakind3 = 4 THEN a.stanumbers3 + WHEN a.stakind4 = 4 THEN a.stanumbers4 + WHEN a.stakind5 = 4 THEN a.stanumbers5 + END aS most_common_elem_freqs, + CASE + WHEN a.stakind1 = 5 THEN a.stanumbers1 + WHEN a.stakind2 = 5 THEN a.stanumbers2 + WHEN a.stakind3 = 5 THEN a.stanumbers3 + WHEN a.stakind4 = 5 THEN a.stanumbers4 + WHEN a.stakind5 = 5 THEN a.stanumbers5 + END aS elem_count_histogram, + CASE + WHEN a.stakind1 = 6 THEN a.stavalues1 + WHEN a.stakind2 = 6 THEN a.stavalues2 + WHEN a.stakind3 = 6 THEN a.stavalues3 + WHEN a.stakind4 = 6 THEN a.stavalues4 + WHEN a.stakind5 = 6 THEN a.stavalues5 + END aS range_length_histogram, + CASE + WHEN a.stakind1 = 6 THEN a.stanumbers1[1] + WHEN a.stakind2 = 6 THEN a.stanumbers2[1] + WHEN a.stakind3 = 6 THEN a.stanumbers3[1] + WHEN a.stakind4 = 6 THEN a.stanumbers4[1] + WHEN a.stakind5 = 6 THEN a.stanumbers5[1] + END aS range_empty_frac, + CASE + WHEN a.stakind1 = 7 THEN a.stavalues1 + WHEN a.stakind2 = 7 THEN a.stavalues2 + WHEN a.stakind3 = 7 THEN a.stavalues3 + WHEN a.stakind4 = 7 THEN a.stavalues4 + WHEN a.stakind5 = 7 THEN a.stavalues5 + END AS range_bounds_histogram FROM pg_statistic_ext s JOIN pg_class c ON (c.oid = s.stxrelid) LEFT JOIN pg_statistic_ext_data sd ON (s.oid = sd.stxoid) LEFT JOIN pg_namespace cn ON (cn.oid = c.relnamespace) LEFT JOIN pg_namespace sn ON (sn.oid = s.stxnamespace) - JOIN LATERAL ( - SELECT unnest(pg_get_statisticsobjdef_expressions(s.oid)) AS expr, - unnest(sd.stxdexpr)::pg_statistic AS a - ) stat ON (stat.expr IS NOT NULL) + JOIN LATERAL unnest(pg_get_statisticsobjdef_expressions(s.oid)) + WITH ORDINALITY AS expr(expr, ordinality) + ON s.stxexprs IS NOT NULL + LEFT JOIN LATERAL unnest(sd.stxdexpr) + WITH ORDINALITY AS a + ON a.ordinality = expr.ordinality WHERE pg_has_role(c.relowner, 'USAGE') AND (c.relrowsecurity = false OR NOT row_security_active(c.oid)); diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index 71d7262049e..d0fd813aa8a 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -2543,7 +2543,9 @@ pg_statio_user_tables| SELECT relid, WHERE ((schemaname <> ALL (ARRAY['pg_catalog'::name, 'information_schema'::name])) AND (schemaname !~ '^pg_toast'::text)); pg_stats| SELECT n.nspname AS schemaname, c.relname AS tablename, + a.attrelid AS tableid, a.attname, + a.attnum, s.stainherit AS inherited, s.stanullfrac AS null_frac, s.stawidth AS avg_width, @@ -2635,8 +2637,10 @@ pg_stats| SELECT n.nspname AS schemaname, 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)))); pg_stats_ext| SELECT cn.nspname AS schemaname, c.relname AS tablename, + s.stxrelid AS tableid, sn.nspname AS statistics_schemaname, s.stxname AS statistics_name, + s.oid AS statid, pg_get_userbyid(s.stxowner) AS statistics_owner, ( SELECT array_agg(a.attname ORDER BY a.attnum) AS array_agg FROM (unnest(s.stxkeys) k(k) @@ -2663,101 +2667,104 @@ pg_stats_ext| SELECT cn.nspname AS schemaname, WHERE (pg_has_role(c.relowner, 'USAGE'::text) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid)))); pg_stats_ext_exprs| SELECT cn.nspname AS schemaname, c.relname AS tablename, + s.stxrelid AS tableid, sn.nspname AS statistics_schemaname, s.stxname AS statistics_name, + s.oid AS statid, pg_get_userbyid(s.stxowner) AS statistics_owner, - stat.expr, + expr.expr, + (0 - expr.ordinality) AS expr_attnum, sd.stxdinherit AS inherited, - (stat.a).stanullfrac AS null_frac, - (stat.a).stawidth AS avg_width, - (stat.a).stadistinct AS n_distinct, + a.stanullfrac AS null_frac, + a.stawidth AS avg_width, + a.stadistinct AS n_distinct, CASE - WHEN ((stat.a).stakind1 = 1) THEN (stat.a).stavalues1 - WHEN ((stat.a).stakind2 = 1) THEN (stat.a).stavalues2 - WHEN ((stat.a).stakind3 = 1) THEN (stat.a).stavalues3 - WHEN ((stat.a).stakind4 = 1) THEN (stat.a).stavalues4 - WHEN ((stat.a).stakind5 = 1) THEN (stat.a).stavalues5 + WHEN (a.stakind1 = 1) THEN a.stavalues1 + WHEN (a.stakind2 = 1) THEN a.stavalues2 + WHEN (a.stakind3 = 1) THEN a.stavalues3 + WHEN (a.stakind4 = 1) THEN a.stavalues4 + WHEN (a.stakind5 = 1) THEN a.stavalues5 ELSE NULL::anyarray END AS most_common_vals, CASE - WHEN ((stat.a).stakind1 = 1) THEN (stat.a).stanumbers1 - WHEN ((stat.a).stakind2 = 1) THEN (stat.a).stanumbers2 - WHEN ((stat.a).stakind3 = 1) THEN (stat.a).stanumbers3 - WHEN ((stat.a).stakind4 = 1) THEN (stat.a).stanumbers4 - WHEN ((stat.a).stakind5 = 1) THEN (stat.a).stanumbers5 + WHEN (a.stakind1 = 1) THEN a.stanumbers1 + WHEN (a.stakind2 = 1) THEN a.stanumbers2 + WHEN (a.stakind3 = 1) THEN a.stanumbers3 + WHEN (a.stakind4 = 1) THEN a.stanumbers4 + WHEN (a.stakind5 = 1) THEN a.stanumbers5 ELSE NULL::real[] END AS most_common_freqs, CASE - WHEN ((stat.a).stakind1 = 2) THEN (stat.a).stavalues1 - WHEN ((stat.a).stakind2 = 2) THEN (stat.a).stavalues2 - WHEN ((stat.a).stakind3 = 2) THEN (stat.a).stavalues3 - WHEN ((stat.a).stakind4 = 2) THEN (stat.a).stavalues4 - WHEN ((stat.a).stakind5 = 2) THEN (stat.a).stavalues5 + WHEN (a.stakind1 = 2) THEN a.stavalues1 + WHEN (a.stakind2 = 2) THEN a.stavalues2 + WHEN (a.stakind3 = 2) THEN a.stavalues3 + WHEN (a.stakind4 = 2) THEN a.stavalues4 + WHEN (a.stakind5 = 2) THEN a.stavalues5 ELSE NULL::anyarray END AS histogram_bounds, CASE - WHEN ((stat.a).stakind1 = 3) THEN (stat.a).stanumbers1[1] - WHEN ((stat.a).stakind2 = 3) THEN (stat.a).stanumbers2[1] - WHEN ((stat.a).stakind3 = 3) THEN (stat.a).stanumbers3[1] - WHEN ((stat.a).stakind4 = 3) THEN (stat.a).stanumbers4[1] - WHEN ((stat.a).stakind5 = 3) THEN (stat.a).stanumbers5[1] + WHEN (a.stakind1 = 3) THEN a.stanumbers1[1] + WHEN (a.stakind2 = 3) THEN a.stanumbers2[1] + WHEN (a.stakind3 = 3) THEN a.stanumbers3[1] + WHEN (a.stakind4 = 3) THEN a.stanumbers4[1] + WHEN (a.stakind5 = 3) THEN a.stanumbers5[1] ELSE NULL::real END AS correlation, CASE - WHEN ((stat.a).stakind1 = 4) THEN (stat.a).stavalues1 - WHEN ((stat.a).stakind2 = 4) THEN (stat.a).stavalues2 - WHEN ((stat.a).stakind3 = 4) THEN (stat.a).stavalues3 - WHEN ((stat.a).stakind4 = 4) THEN (stat.a).stavalues4 - WHEN ((stat.a).stakind5 = 4) THEN (stat.a).stavalues5 + WHEN (a.stakind1 = 4) THEN a.stavalues1 + WHEN (a.stakind2 = 4) THEN a.stavalues2 + WHEN (a.stakind3 = 4) THEN a.stavalues3 + WHEN (a.stakind4 = 4) THEN a.stavalues4 + WHEN (a.stakind5 = 4) THEN a.stavalues5 ELSE NULL::anyarray END AS most_common_elems, CASE - WHEN ((stat.a).stakind1 = 4) THEN (stat.a).stanumbers1 - WHEN ((stat.a).stakind2 = 4) THEN (stat.a).stanumbers2 - WHEN ((stat.a).stakind3 = 4) THEN (stat.a).stanumbers3 - WHEN ((stat.a).stakind4 = 4) THEN (stat.a).stanumbers4 - WHEN ((stat.a).stakind5 = 4) THEN (stat.a).stanumbers5 + WHEN (a.stakind1 = 4) THEN a.stanumbers1 + WHEN (a.stakind2 = 4) THEN a.stanumbers2 + WHEN (a.stakind3 = 4) THEN a.stanumbers3 + WHEN (a.stakind4 = 4) THEN a.stanumbers4 + WHEN (a.stakind5 = 4) THEN a.stanumbers5 ELSE NULL::real[] END AS most_common_elem_freqs, CASE - WHEN ((stat.a).stakind1 = 5) THEN (stat.a).stanumbers1 - WHEN ((stat.a).stakind2 = 5) THEN (stat.a).stanumbers2 - WHEN ((stat.a).stakind3 = 5) THEN (stat.a).stanumbers3 - WHEN ((stat.a).stakind4 = 5) THEN (stat.a).stanumbers4 - WHEN ((stat.a).stakind5 = 5) THEN (stat.a).stanumbers5 + WHEN (a.stakind1 = 5) THEN a.stanumbers1 + WHEN (a.stakind2 = 5) THEN a.stanumbers2 + WHEN (a.stakind3 = 5) THEN a.stanumbers3 + WHEN (a.stakind4 = 5) THEN a.stanumbers4 + WHEN (a.stakind5 = 5) THEN a.stanumbers5 ELSE NULL::real[] END AS elem_count_histogram, CASE - WHEN ((stat.a).stakind1 = 6) THEN (stat.a).stavalues1 - WHEN ((stat.a).stakind2 = 6) THEN (stat.a).stavalues2 - WHEN ((stat.a).stakind3 = 6) THEN (stat.a).stavalues3 - WHEN ((stat.a).stakind4 = 6) THEN (stat.a).stavalues4 - WHEN ((stat.a).stakind5 = 6) THEN (stat.a).stavalues5 + WHEN (a.stakind1 = 6) THEN a.stavalues1 + WHEN (a.stakind2 = 6) THEN a.stavalues2 + WHEN (a.stakind3 = 6) THEN a.stavalues3 + WHEN (a.stakind4 = 6) THEN a.stavalues4 + WHEN (a.stakind5 = 6) THEN a.stavalues5 ELSE NULL::anyarray END AS range_length_histogram, CASE - WHEN ((stat.a).stakind1 = 6) THEN (stat.a).stanumbers1[1] - WHEN ((stat.a).stakind2 = 6) THEN (stat.a).stanumbers2[1] - WHEN ((stat.a).stakind3 = 6) THEN (stat.a).stanumbers3[1] - WHEN ((stat.a).stakind4 = 6) THEN (stat.a).stanumbers4[1] - WHEN ((stat.a).stakind5 = 6) THEN (stat.a).stanumbers5[1] + WHEN (a.stakind1 = 6) THEN a.stanumbers1[1] + WHEN (a.stakind2 = 6) THEN a.stanumbers2[1] + WHEN (a.stakind3 = 6) THEN a.stanumbers3[1] + WHEN (a.stakind4 = 6) THEN a.stanumbers4[1] + WHEN (a.stakind5 = 6) THEN a.stanumbers5[1] ELSE NULL::real END AS range_empty_frac, CASE - WHEN ((stat.a).stakind1 = 7) THEN (stat.a).stavalues1 - WHEN ((stat.a).stakind2 = 7) THEN (stat.a).stavalues2 - WHEN ((stat.a).stakind3 = 7) THEN (stat.a).stavalues3 - WHEN ((stat.a).stakind4 = 7) THEN (stat.a).stavalues4 - WHEN ((stat.a).stakind5 = 7) THEN (stat.a).stavalues5 + WHEN (a.stakind1 = 7) THEN a.stavalues1 + WHEN (a.stakind2 = 7) THEN a.stavalues2 + WHEN (a.stakind3 = 7) THEN a.stavalues3 + WHEN (a.stakind4 = 7) THEN a.stavalues4 + WHEN (a.stakind5 = 7) THEN a.stavalues5 ELSE NULL::anyarray END AS range_bounds_histogram - FROM (((((pg_statistic_ext s + FROM ((((((pg_statistic_ext s JOIN pg_class c ON ((c.oid = s.stxrelid))) LEFT JOIN pg_statistic_ext_data sd ON ((s.oid = sd.stxoid))) LEFT JOIN pg_namespace cn ON ((cn.oid = c.relnamespace))) LEFT JOIN pg_namespace sn ON ((sn.oid = s.stxnamespace))) - JOIN LATERAL ( SELECT unnest(pg_get_statisticsobjdef_expressions(s.oid)) AS expr, - unnest(sd.stxdexpr) AS a) stat ON ((stat.expr IS NOT NULL))) + JOIN LATERAL unnest(pg_get_statisticsobjdef_expressions(s.oid)) WITH ORDINALITY expr(expr, ordinality) ON ((s.stxexprs IS NOT NULL))) + LEFT JOIN LATERAL unnest(sd.stxdexpr) WITH ORDINALITY a(starelid, staattnum, stainherit, stanullfrac, stawidth, stadistinct, stakind1, stakind2, stakind3, stakind4, stakind5, staop1, staop2, staop3, staop4, staop5, stacoll1, stacoll2, stacoll3, stacoll4, stacoll5, stanumbers1, stanumbers2, stanumbers3, stanumbers4, stanumbers5, stavalues1, stavalues2, stavalues3, stavalues4, stavalues5, ordinality) ON ((a.ordinality = expr.ordinality))) WHERE (pg_has_role(c.relowner, 'USAGE'::text) AND ((c.relrowsecurity = false) OR (NOT row_security_active(c.oid)))); pg_tables| SELECT n.nspname AS schemaname, c.relname AS tablename, diff --git a/src/test/regress/expected/stats_import.out b/src/test/regress/expected/stats_import.out index 2f538023f38..33f3defd3b9 100644 --- a/src/test/regress/expected/stats_import.out +++ b/src/test/regress/expected/stats_import.out @@ -4,7 +4,7 @@ CREATE SCHEMA stats_import; -- views. -- CREATE VIEW stats_import.pg_stats_check AS -SELECT schemaname, tablename, attname, inherited, null_frac, avg_width, +SELECT schemaname, tablename, attname, attnum, inherited, null_frac, avg_width, n_distinct, most_common_vals::text AS most_common_vals, most_common_freqs, histogram_bounds::text AS histogram_bounds, correlation, most_common_elems::text AS most_common_elems, most_common_elem_freqs, @@ -78,7 +78,7 @@ SELECT COUNT(*) FROM pg_attribute attnum > 0; count ------- - 15 + 17 (1 row) -- Create a view that is used purely for the type based on pg_stats_ext. @@ -119,7 +119,7 @@ SELECT COUNT(*) FROM pg_attribute attnum > 0; count ------- - 20 + 23 (1 row) -- Create a view that is used purely for the type based on pg_stats_ext_exprs. @@ -660,9 +660,9 @@ WHERE schemaname = 'stats_import' AND tablename = 'test' AND inherited = false AND attname = 'id'; - schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram ---------------+-----------+---------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ - stats_import | test | id | f | 0.2 | 5 | 0.6 | | | | | | | | | | + schemaname | tablename | attname | attnum | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram +--------------+-----------+---------+--------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ + stats_import | test | id | 1 | f | 0.2 | 5 | 0.6 | | | | | | | | | | (1 row) -- @@ -687,9 +687,9 @@ WHERE schemaname = 'stats_import' AND tablename = 'test' AND inherited = false AND attname = 'id'; - schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram ---------------+-----------+---------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ - stats_import | test | id | f | 0.4 | 5 | 0.6 | | | | | | | | | | + schemaname | tablename | attname | attnum | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram +--------------+-----------+---------+--------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ + stats_import | test | id | 1 | f | 0.4 | 5 | 0.6 | | | | | | | | | | (1 row) -- warn: unrecognized argument name, rest get set @@ -712,9 +712,9 @@ WHERE schemaname = 'stats_import' AND tablename = 'test' AND inherited = false AND attname = 'id'; - schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram ---------------+-----------+---------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ - stats_import | test | id | f | 0.2 | 5 | 0.6 | | | | | | | | | | + schemaname | tablename | attname | attnum | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram +--------------+-----------+---------+--------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ + stats_import | test | id | 1 | f | 0.2 | 5 | 0.6 | | | | | | | | | | (1 row) -- warn: mcv / mcf null mismatch part 1, rest get set @@ -738,9 +738,9 @@ WHERE schemaname = 'stats_import' AND tablename = 'test' AND inherited = false AND attname = 'id'; - schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram ---------------+-----------+---------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ - stats_import | test | id | f | 0.21 | 5 | 0.6 | | | | | | | | | | + schemaname | tablename | attname | attnum | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram +--------------+-----------+---------+--------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ + stats_import | test | id | 1 | f | 0.21 | 5 | 0.6 | | | | | | | | | | (1 row) -- warn: mcv / mcf null mismatch part 2, rest get set @@ -764,9 +764,9 @@ WHERE schemaname = 'stats_import' AND tablename = 'test' AND inherited = false AND attname = 'id'; - schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram ---------------+-----------+---------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ - stats_import | test | id | f | 0.21 | 5 | 0.6 | | | | | | | | | | + schemaname | tablename | attname | attnum | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram +--------------+-----------+---------+--------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ + stats_import | test | id | 1 | f | 0.21 | 5 | 0.6 | | | | | | | | | | (1 row) -- warn: mcf type mismatch, mcv-pair fails, rest get set @@ -792,9 +792,9 @@ WHERE schemaname = 'stats_import' AND tablename = 'test' AND inherited = false AND attname = 'id'; - schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram ---------------+-----------+---------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ - stats_import | test | id | f | 0.22 | 5 | 0.6 | | | | | | | | | | + schemaname | tablename | attname | attnum | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram +--------------+-----------+---------+--------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ + stats_import | test | id | 1 | f | 0.22 | 5 | 0.6 | | | | | | | | | | (1 row) -- warn: mcv cast failure, mcv-pair fails, rest get set @@ -819,9 +819,9 @@ WHERE schemaname = 'stats_import' AND tablename = 'test' AND inherited = false AND attname = 'id'; - schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram ---------------+-----------+---------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ - stats_import | test | id | f | 0.23 | 5 | 0.6 | | | | | | | | | | + schemaname | tablename | attname | attnum | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram +--------------+-----------+---------+--------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ + stats_import | test | id | 1 | f | 0.23 | 5 | 0.6 | | | | | | | | | | (1 row) -- ok: mcv+mcf @@ -844,9 +844,9 @@ WHERE schemaname = 'stats_import' AND tablename = 'test' AND inherited = false AND attname = 'id'; - schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram ---------------+-----------+---------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ - stats_import | test | id | f | 0.23 | 5 | 0.6 | {2,1,3} | {0.3,0.25,0.05} | | | | | | | | + schemaname | tablename | attname | attnum | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram +--------------+-----------+---------+--------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ + stats_import | test | id | 1 | f | 0.23 | 5 | 0.6 | {2,1,3} | {0.3,0.25,0.05} | | | | | | | | (1 row) -- warn: NULL in histogram array, rest get set @@ -870,9 +870,9 @@ WHERE schemaname = 'stats_import' AND tablename = 'test' AND inherited = false AND attname = 'id'; - schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram ---------------+-----------+---------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ - stats_import | test | id | f | 0.24 | 5 | 0.6 | {2,1,3} | {0.3,0.25,0.05} | | | | | | | | + schemaname | tablename | attname | attnum | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram +--------------+-----------+---------+--------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ + stats_import | test | id | 1 | f | 0.24 | 5 | 0.6 | {2,1,3} | {0.3,0.25,0.05} | | | | | | | | (1 row) -- ok: histogram_bounds @@ -894,9 +894,9 @@ WHERE schemaname = 'stats_import' AND tablename = 'test' AND inherited = false AND attname = 'id'; - schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram ---------------+-----------+---------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ - stats_import | test | id | f | 0.24 | 5 | 0.6 | {2,1,3} | {0.3,0.25,0.05} | {1,2,3,4} | | | | | | | + schemaname | tablename | attname | attnum | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram +--------------+-----------+---------+--------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ + stats_import | test | id | 1 | f | 0.24 | 5 | 0.6 | {2,1,3} | {0.3,0.25,0.05} | {1,2,3,4} | | | | | | | (1 row) -- warn: elem_count_histogram null element, rest get set @@ -920,9 +920,9 @@ WHERE schemaname = 'stats_import' AND tablename = 'test' AND inherited = false AND attname = 'tags'; - schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram ---------------+-----------+---------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ - stats_import | test | tags | f | 0.25 | 0 | 0 | | | | | | | | | | + schemaname | tablename | attname | attnum | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram +--------------+-----------+---------+--------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ + stats_import | test | tags | 5 | f | 0.25 | 0 | 0 | | | | | | | | | | (1 row) -- ok: elem_count_histogram @@ -945,9 +945,9 @@ WHERE schemaname = 'stats_import' AND tablename = 'test' AND inherited = false AND attname = 'tags'; - schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram ---------------+-----------+---------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------+------------------+------------------------ - stats_import | test | tags | f | 0.26 | 0 | 0 | | | | | | | {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} | | | + schemaname | tablename | attname | attnum | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram +--------------+-----------+---------+--------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------+------------------+------------------------ + stats_import | test | tags | 5 | f | 0.26 | 0 | 0 | | | | | | | {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} | | | (1 row) -- warn: range stats on a scalar type, rest ok @@ -973,9 +973,9 @@ WHERE schemaname = 'stats_import' AND tablename = 'test' AND inherited = false AND attname = 'id'; - schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram ---------------+-----------+---------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ - stats_import | test | id | f | 0.27 | 5 | 0.6 | {2,1,3} | {0.3,0.25,0.05} | {1,2,3,4} | | | | | | | + schemaname | tablename | attname | attnum | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram +--------------+-----------+---------+--------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ + stats_import | test | id | 1 | f | 0.27 | 5 | 0.6 | {2,1,3} | {0.3,0.25,0.05} | {1,2,3,4} | | | | | | | (1 row) -- warn: range_empty_frac range_length_hist null mismatch, rest ok @@ -999,9 +999,9 @@ WHERE schemaname = 'stats_import' AND tablename = 'test' AND inherited = false AND attname = 'arange'; - schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram ---------------+-----------+---------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ - stats_import | test | arange | f | 0.28 | 0 | 0 | | | | | | | | | | + schemaname | tablename | attname | attnum | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram +--------------+-----------+---------+--------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ + stats_import | test | arange | 4 | f | 0.28 | 0 | 0 | | | | | | | | | | (1 row) -- warn: range_empty_frac range_length_hist null mismatch part 2, rest ok @@ -1025,9 +1025,9 @@ WHERE schemaname = 'stats_import' AND tablename = 'test' AND inherited = false AND attname = 'arange'; - schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram ---------------+-----------+---------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ - stats_import | test | arange | f | 0.29 | 0 | 0 | | | | | | | | | | + schemaname | tablename | attname | attnum | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram +--------------+-----------+---------+--------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ + stats_import | test | arange | 4 | f | 0.29 | 0 | 0 | | | | | | | | | | (1 row) -- ok: range_empty_frac + range_length_hist @@ -1050,9 +1050,9 @@ WHERE schemaname = 'stats_import' AND tablename = 'test' AND inherited = false AND attname = 'arange'; - schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram ---------------+-----------+---------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ - stats_import | test | arange | f | 0.29 | 0 | 0 | | | | | | | | {399,499,Infinity} | 0.5 | + schemaname | tablename | attname | attnum | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram +--------------+-----------+---------+--------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ + stats_import | test | arange | 4 | f | 0.29 | 0 | 0 | | | | | | | | {399,499,Infinity} | 0.5 | (1 row) -- warn: range bounds histogram on scalar, rest ok @@ -1077,9 +1077,9 @@ WHERE schemaname = 'stats_import' AND tablename = 'test' AND inherited = false AND attname = 'id'; - schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram ---------------+-----------+---------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ - stats_import | test | id | f | 0.31 | 5 | 0.6 | {2,1,3} | {0.3,0.25,0.05} | {1,2,3,4} | | | | | | | + schemaname | tablename | attname | attnum | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram +--------------+-----------+---------+--------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ + stats_import | test | id | 1 | f | 0.31 | 5 | 0.6 | {2,1,3} | {0.3,0.25,0.05} | {1,2,3,4} | | | | | | | (1 row) -- ok: range_bounds_histogram @@ -1101,9 +1101,9 @@ WHERE schemaname = 'stats_import' AND tablename = 'test' AND inherited = false AND attname = 'arange'; - schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram ---------------+-----------+---------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+-------------------------------------- - stats_import | test | arange | f | 0.29 | 0 | 0 | | | | | | | | {399,499,Infinity} | 0.5 | {"[-1,1)","[0,4)","[1,4)","[1,100)"} + schemaname | tablename | attname | attnum | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram +--------------+-----------+---------+--------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+-------------------------------------- + stats_import | test | arange | 4 | f | 0.29 | 0 | 0 | | | | | | | | {399,499,Infinity} | 0.5 | {"[-1,1)","[0,4)","[1,4)","[1,100)"} (1 row) -- warn: cannot set most_common_elems for range type, rest ok @@ -1129,9 +1129,9 @@ WHERE schemaname = 'stats_import' AND tablename = 'test' AND inherited = false AND attname = 'arange'; - schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram ---------------+-----------+---------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+-------------------------------------- - stats_import | test | arange | f | 0.32 | 0 | 0 | | | | | | | | {399,499,Infinity} | 0.5 | {"[-1,1)","[0,4)","[1,4)","[1,100)"} + schemaname | tablename | attname | attnum | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram +--------------+-----------+---------+--------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+-------------------------------------- + stats_import | test | arange | 4 | f | 0.32 | 0 | 0 | | | | | | | | {399,499,Infinity} | 0.5 | {"[-1,1)","[0,4)","[1,4)","[1,100)"} (1 row) -- warn: scalars can't have mcelem, rest ok @@ -1157,9 +1157,9 @@ WHERE schemaname = 'stats_import' AND tablename = 'test' AND inherited = false AND attname = 'id'; - schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram ---------------+-----------+---------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ - stats_import | test | id | f | 0.33 | 5 | 0.6 | {2,1,3} | {0.3,0.25,0.05} | {1,2,3,4} | | | | | | | + schemaname | tablename | attname | attnum | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram +--------------+-----------+---------+--------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ + stats_import | test | id | 1 | f | 0.33 | 5 | 0.6 | {2,1,3} | {0.3,0.25,0.05} | {1,2,3,4} | | | | | | | (1 row) -- warn: mcelem / mcelem mismatch, rest ok @@ -1183,9 +1183,9 @@ WHERE schemaname = 'stats_import' AND tablename = 'test' AND inherited = false AND attname = 'tags'; - schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram ---------------+-----------+---------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------+------------------+------------------------ - stats_import | test | tags | f | 0.34 | 0 | 0 | | | | | | | {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} | | | + schemaname | tablename | attname | attnum | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram +--------------+-----------+---------+--------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------+------------------+------------------------ + stats_import | test | tags | 5 | f | 0.34 | 0 | 0 | | | | | | | {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} | | | (1 row) -- warn: mcelem / mcelem null mismatch part 2, rest ok @@ -1209,9 +1209,9 @@ WHERE schemaname = 'stats_import' AND tablename = 'test' AND inherited = false AND attname = 'tags'; - schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram ---------------+-----------+---------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------+------------------+------------------------ - stats_import | test | tags | f | 0.35 | 0 | 0 | | | | | | | {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} | | | + schemaname | tablename | attname | attnum | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram +--------------+-----------+---------+--------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------+------------------+------------------------ + stats_import | test | tags | 5 | f | 0.35 | 0 | 0 | | | | | | | {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} | | | (1 row) -- ok: mcelem @@ -1234,9 +1234,9 @@ WHERE schemaname = 'stats_import' AND tablename = 'test' AND inherited = false AND attname = 'tags'; - schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram ---------------+-----------+---------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------+------------------+------------------------ - stats_import | test | tags | f | 0.35 | 0 | 0 | | | | | {one,three} | {0.3,0.2,0.2,0.3,0} | {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} | | | + schemaname | tablename | attname | attnum | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram +--------------+-----------+---------+--------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------+------------------+------------------------ + stats_import | test | tags | 5 | f | 0.35 | 0 | 0 | | | | | {one,three} | {0.3,0.2,0.2,0.3,0} | {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} | | | (1 row) -- warn: scalars can't have elem_count_histogram, rest ok @@ -1261,9 +1261,9 @@ WHERE schemaname = 'stats_import' AND tablename = 'test' AND inherited = false AND attname = 'id'; - schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram ---------------+-----------+---------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ - stats_import | test | id | f | 0.36 | 5 | 0.6 | {2,1,3} | {0.3,0.25,0.05} | {1,2,3,4} | | | | | | | + schemaname | tablename | attname | attnum | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram +--------------+-----------+---------+--------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------+------------------------+------------------+------------------------ + stats_import | test | id | 1 | f | 0.36 | 5 | 0.6 | {2,1,3} | {0.3,0.25,0.05} | {1,2,3,4} | | | | | | | (1 row) -- test for multiranges diff --git a/src/test/regress/sql/stats_import.sql b/src/test/regress/sql/stats_import.sql index c36bdaf78ee..cb0d274fe4b 100644 --- a/src/test/regress/sql/stats_import.sql +++ b/src/test/regress/sql/stats_import.sql @@ -5,7 +5,7 @@ CREATE SCHEMA stats_import; -- views. -- CREATE VIEW stats_import.pg_stats_check AS -SELECT schemaname, tablename, attname, inherited, null_frac, avg_width, +SELECT schemaname, tablename, attname, attnum, inherited, null_frac, avg_width, n_distinct, most_common_vals::text AS most_common_vals, most_common_freqs, histogram_bounds::text AS histogram_bounds, correlation, most_common_elems::text AS most_common_elems, most_common_elem_freqs, -- 2.47.3