drop table if exists public.test_clone; drop TYPE if exists public.complex_type; drop STATISTICS if exists public.test_stat_clone; CREATE TYPE public.complex_type AS ( a integer, b real, c text, d date, e jsonb); CREATE TABLE public.test_clone( id INTEGER PRIMARY KEY, name text, comp public.complex_type, arange int4range, tags text[] ) WITH (autovacuum_enabled = false); --CREATE INDEX is_odd_clone ON public.test_clone(((comp).a % 2 = 1)); CREATE STATISTICS public.test_stat_clone ON name, comp, lower(arange), array_length(tags,1) FROM public.test_clone; --`most_common_vals_kind` is not specified, so it defaults to 1-STATISTIC_KIND_MCV. The import succeeds. SELECT pg_catalog.pg_restore_extended_stats( 'schemaname', 'public', 'relname', 'test_clone', 'statistics_schemaname', 'public', 'statistics_name', 'test_stat_clone', 'inherited', false, 'exprs', '[ { "most_common_vals": "{1,2,3}", "most_common_freqs": "{0.1,0.2,0.3}" }, { "most_common_vals": "{11,22,33}", "most_common_freqs": "{0.11,0.22,0.33}" } ]'::jsonb); 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 statistics_id, pg_get_userbyid(s.stxowner) AS statistics_owner, stat.expr, 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 1 WHEN (stat.a).stakind2 = 1 THEN 1 WHEN (stat.a).stakind3 = 1 THEN 1 WHEN (stat.a).stakind4 = 1 THEN 1 WHEN (stat.a).stakind5 = 1 THEN 1 WHEN (stat.a).stakind1 = 8 THEN 8 WHEN (stat.a).stakind2 = 8 THEN 8 WHEN (stat.a).stakind3 = 8 THEN 8 WHEN (stat.a).stakind4 = 8 THEN 8 WHEN (stat.a).stakind5 = 8 THEN 8 else -1 END) AS most_common_kind, (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 (stat.a).stakind1 = 8 THEN (stat.a).stavalues1 WHEN (stat.a).stakind2 = 8 THEN (stat.a).stavalues2 WHEN (stat.a).stakind3 = 8 THEN (stat.a).stavalues3 WHEN (stat.a).stakind4 = 8 THEN (stat.a).stavalues4 WHEN (stat.a).stakind5 = 8 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 WHEN (stat.a).stakind1 = 8 THEN (stat.a).stanumbers1 WHEN (stat.a).stakind2 = 8 THEN (stat.a).stanumbers2 WHEN (stat.a).stakind3 = 8 THEN (stat.a).stanumbers3 WHEN (stat.a).stakind4 = 8 THEN (stat.a).stanumbers4 WHEN (stat.a).stakind5 = 8 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 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) WHERE pg_has_role(c.relowner, 'USAGE') AND (c.relrowsecurity = false OR NOT row_security_active(c.oid)) and sn.nspname = 'public' and s.stxname = 'test_stat_clone'\gx -[ RECORD 1 ]----------+---------------------- schemaname | public tablename | test_clone tableid | 16667 statistics_schemaname | public statistics_name | test_stat_clone statistics_id | 16675 statistics_owner | xman expr | lower(arange) inherited | f null_frac | 0 avg_width | 0 n_distinct | 0 most_common_kind | 1 most_common_vals | {1,2,3} most_common_freqs | {0.1,0.2,0.3} histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram | -[ RECORD 2 ]----------+---------------------- schemaname | public tablename | test_clone tableid | 16667 statistics_schemaname | public statistics_name | test_stat_clone statistics_id | 16675 statistics_owner | xman expr | array_length(tags, 1) inherited | f null_frac | 0 avg_width | 0 n_distinct | 0 most_common_kind | 1 most_common_vals | {11,22,33} most_common_freqs | {0.11,0.22,0.33} histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram | xman7=# --Specifying 1-STATISTIC_KIND_MCV succeeds. xman7=# SELECT pg_catalog.pg_restore_extended_stats( 'schemaname', 'public', 'relname', 'test_clone', 'statistics_schemaname', 'public', 'statistics_name', 'test_stat_clone', 'inherited', false, 'exprs', '[ { "most_common_vals": "{11,22,33}", "most_common_freqs": "{0.11,0.22,0.3}", "most_common_vals_kind":"1" }, { "most_common_vals": "{101,202,302}", "most_common_freqs": "{0.101,0.202,0.303}" } ]'::jsonb); pg_restore_extended_stats --------------------------- t (1 row) xman7=# 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 statistics_id, pg_get_userbyid(s.stxowner) AS statistics_owner, stat.expr, 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 1 WHEN (stat.a).stakind2 = 1 THEN 1 WHEN (stat.a).stakind3 = 1 THEN 1 WHEN (stat.a).stakind4 = 1 THEN 1 WHEN (stat.a).stakind5 = 1 THEN 1 WHEN (stat.a).stakind1 = 8 THEN 8 WHEN (stat.a).stakind2 = 8 THEN 8 WHEN (stat.a).stakind3 = 8 THEN 8 WHEN (stat.a).stakind4 = 8 THEN 8 WHEN (stat.a).stakind5 = 8 THEN 8 else -1 END) AS most_common_kind, (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 (stat.a).stakind1 = 8 THEN (stat.a).stavalues1 WHEN (stat.a).stakind2 = 8 THEN (stat.a).stavalues2 WHEN (stat.a).stakind3 = 8 THEN (stat.a).stavalues3 WHEN (stat.a).stakind4 = 8 THEN (stat.a).stavalues4 WHEN (stat.a).stakind5 = 8 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 WHEN (stat.a).stakind1 = 8 THEN (stat.a).stanumbers1 WHEN (stat.a).stakind2 = 8 THEN (stat.a).stanumbers2 WHEN (stat.a).stakind3 = 8 THEN (stat.a).stanumbers3 WHEN (stat.a).stakind4 = 8 THEN (stat.a).stanumbers4 WHEN (stat.a).stakind5 = 8 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 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) WHERE pg_has_role(c.relowner, 'USAGE') AND (c.relrowsecurity = false OR NOT row_security_active(c.oid)) and sn.nspname = 'public' and s.stxname = 'test_stat_clone'\gx -[ RECORD 1 ]----------+---------------------- schemaname | public tablename | test_clone tableid | 16667 statistics_schemaname | public statistics_name | test_stat_clone statistics_id | 16675 statistics_owner | xman expr | lower(arange) inherited | f null_frac | 0 avg_width | 0 n_distinct | 0 most_common_kind | 1 most_common_vals | {11,22,33} most_common_freqs | {0.11,0.22,0.3} histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram | -[ RECORD 2 ]----------+---------------------- schemaname | public tablename | test_clone tableid | 16667 statistics_schemaname | public statistics_name | test_stat_clone statistics_id | 16675 statistics_owner | xman expr | array_length(tags, 1) inherited | f null_frac | 0 avg_width | 0 n_distinct | 0 most_common_kind | 1 most_common_vals | {101,202,302} most_common_freqs | {0.101,0.202,0.303} histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram | xman7=# --Specifying 8-STATISTIC_KIND_MCV_VALUE_SORTED succeeds. xman7=# SELECT pg_catalog.pg_restore_extended_stats( 'schemaname', 'public', 'relname', 'test_clone', 'statistics_schemaname', 'public', 'statistics_name', 'test_stat_clone', 'inherited', false, 'exprs', '[ { "most_common_vals": "{11,12,13}", "most_common_freqs": "{0.11,0.12,0.13}", "most_common_vals_kind":"8" }, { "most_common_vals": "{41,42,43}", "most_common_freqs": "{0.011,0.022,0.033}","most_common_vals_kind":"8" } ]'::jsonb); pg_restore_extended_stats --------------------------- t (1 row) xman7=# 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 statistics_id, pg_get_userbyid(s.stxowner) AS statistics_owner, stat.expr, 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 1 WHEN (stat.a).stakind2 = 1 THEN 1 WHEN (stat.a).stakind3 = 1 THEN 1 WHEN (stat.a).stakind4 = 1 THEN 1 WHEN (stat.a).stakind5 = 1 THEN 1 WHEN (stat.a).stakind1 = 8 THEN 8 WHEN (stat.a).stakind2 = 8 THEN 8 WHEN (stat.a).stakind3 = 8 THEN 8 WHEN (stat.a).stakind4 = 8 THEN 8 WHEN (stat.a).stakind5 = 8 THEN 8 else -1 END) AS most_common_vals_kind, (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 and sn.nspname = 'public' and s.stxname = 'test_stat_clone'\gx row_security_active(c.oid)))) AS expr, -[ RECORD 1 ]----------+---------------------- schemaname | public tablename | test_clone tableid | 16667 statistics_schemaname | public statistics_name | test_stat_clone statistics_id | 16675 statistics_owner | xman expr | lower(arange) inherited | f null_frac | 0 avg_width | 0 n_distinct | 0 most_common_kind | 8 most_common_vals | {11,12,13} most_common_freqs | {0.11,0.12,0.13} histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram | -[ RECORD 2 ]----------+---------------------- schemaname | public tablename | test_clone tableid | 16667 statistics_schemaname | public statistics_name | test_stat_clone statistics_id | 16675 statistics_owner | xman expr | array_length(tags, 1) inherited | f null_frac | 0 avg_width | 0 n_distinct | 0 most_common_kind | 8 most_common_vals | {41,42,43} most_common_freqs | {0.011,0.022,0.033} histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram | xman7=# --Importing 1-STATISTIC_KIND_MCV succeeds. xman7=# SELECT pg_catalog.pg_restore_extended_stats( 'schemaname', 'public', 'relname', 'test_clone', 'statistics_schemaname', 'public', 'statistics_name', 'test_stat_clone', 'inherited', false, 'exprs', '[ { "most_common_vals": "{13,12,11}", "most_common_freqs": "{0.13,0.12,0.11}", "most_common_vals_kind":"1" }, { "most_common_vals": "{43,42,41}", "most_common_freqs": "{0.033,0.022,0.011}","most_common_vals_kind":"1" } ]'::jsonb); pg_restore_extended_stats --------------------------- t (1 row) xman7=# 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 statistics_id, pg_get_userbyid(s.stxowner) AS statistics_owner, stat.expr, 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 1 WHEN (stat.a).stakind2 = 1 THEN 1 WHEN (stat.a).stakind3 = 1 THEN 1 WHEN (stat.a).stakind4 = 1 THEN 1 WHEN (stat.a).stakind5 = 1 THEN 1 WHEN (stat.a).stakind1 = 8 THEN 8 WHEN (stat.a).stakind2 = 8 THEN 8 WHEN (stat.a).stakind3 = 8 THEN 8 WHEN (stat.a).stakind4 = 8 THEN 8 WHEN (stat.a).stakind5 = 8 THEN 8 else -1 END) AS most_common_kind, (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 (stat.a).stakind1 = 8 THEN (stat.a).stavalues1 WHEN (stat.a).stakind2 = 8 THEN (stat.a).stavalues2 WHEN (stat.a).stakind3 = 8 THEN (stat.a).stavalues3 WHEN (stat.a).stakind4 = 8 THEN (stat.a).stavalues4 WHEN (stat.a).stakind5 = 8 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 WHEN (stat.a).stakind1 = 8 THEN (stat.a).stanumbers1 WHEN (stat.a).stakind2 = 8 THEN (stat.a).stanumbers2 WHEN (stat.a).stakind3 = 8 THEN (stat.a).stanumbers3 WHEN (stat.a).stakind4 = 8 THEN (stat.a).stanumbers4 WHEN (stat.a).stakind5 = 8 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 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) WHERE pg_has_role(c.relowner, 'USAGE') AND (c.relrowsecurity = false OR NOT row_security_active(c.oid)) and sn.nspname = 'public' and s.stxname = 'test_stat_clone'\gx -[ RECORD 1 ]----------+---------------------- schemaname | public tablename | test_clone tableid | 16667 statistics_schemaname | public statistics_name | test_stat_clone statistics_id | 16675 statistics_owner | xman expr | lower(arange) inherited | f null_frac | 0 avg_width | 0 n_distinct | 0 most_common_kind | 1 most_common_vals | {13,12,11} most_common_freqs | {0.13,0.12,0.11} histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram | -[ RECORD 2 ]----------+---------------------- schemaname | public tablename | test_clone tableid | 16667 statistics_schemaname | public statistics_name | test_stat_clone statistics_id | 16675 statistics_owner | xman expr | array_length(tags, 1) inherited | f null_frac | 0 avg_width | 0 n_distinct | 0 most_common_kind | 1 most_common_vals | {43,42,41} most_common_freqs | {0.033,0.022,0.011} histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram | range_length_histogram | range_empty_frac | range_bounds_histogram | xman7=#