drop table if exists public.t_attribute_stats; CREATE TABLE public.t_attribute_stats( id INTEGER PRIMARY KEY, name text, comp stats_import.complex_type, arange int4range, tags text[] ) WITH (autovacuum_enabled = false); analyze public.t_attribute_stats; select * from pg_catalog.pg_statistic where starelid =(select oid from pg_catalog.pg_class where relname = 't_attribute_stats') \gx SELECT pg_catalog.pg_restore_attribute_stats( 'schemaname', 'public', 'relname', 't_attribute_stats', 'attname', 'id', 'inherited', false::boolean, 'most_common_vals', '{1,2,3}'::text, 'most_common_freqs', '{0.3,0.25,0.05}'::real[] ); =============================== xman7=# drop table if exists public.t_attribute_stats; CREATE TABLE public.t_attribute_stats( id INTEGER PRIMARY KEY, name text, comp stats_import.complex_type, arange int4range, tags text[] ) WITH (autovacuum_enabled = false); DROP TABLE CREATE TABLE xman7=# xman7=# xman7=# select * from pg_catalog.pg_statistic where starelid =(select oid from pg_catalog.pg_class where relname = 't_attribute_stats') \gx (0 rows) xman7=# analyze public.t_attribute_stats; ANALYZE xman7=# select * from pg_catalog.pg_statistic where starelid =(select oid from pg_catalog.pg_class where relname = 't_attribute_stats') \gx (0 rows) -- If most_common_kind is not specified, default to 1-STATISTIC_KIND_MCV, and the import succeeds. xman7=# SELECT pg_catalog.pg_restore_attribute_stats( 'schemaname', 'public', 'relname', 't_attribute_stats', 'attname', 'id', 'inherited', false::boolean, 'most_common_vals', '{1,2,3}'::text, 'most_common_freqs', '{0.3,0.25,0.05}'::real[]); pg_restore_attribute_stats ---------------------------- t (1 row) xman7=# select * from pg_catalog.pg_statistic where starelid =(select oid from pg_catalog.pg_class where relname = 't_attribute_stats')\gx -[ RECORD 1 ]---------------- starelid | 16614 staattnum | 1 stainherit | f stanullfrac | 0 stawidth | 0 stadistinct | 0 stakind1 | 1 stakind2 | 0 stakind3 | 0 stakind4 | 0 stakind5 | 0 staop1 | 96 staop2 | 0 staop3 | 0 staop4 | 0 staop5 | 0 stacoll1 | 0 stacoll2 | 0 stacoll3 | 0 stacoll4 | 0 stacoll5 | 0 stanumbers1 | {0.3,0.25,0.05} stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | {1,2,3} stavalues2 | stavalues3 | stavalues4 | stavalues5 | xman7=# --If most_common_kind is neither 1 (STATISTIC_KIND_MCV) nor 8 (STATISTIC_KIND_MCV_VALUE_SORTED), the import fails and the existing statistics remain unchanged. SELECT pg_catalog.pg_restore_attribute_stats( 'schemaname', 'public', 'relname', 't_attribute_stats', 'attname', 'id', 'inherited', false::boolean, 'most_common_vals', '{1,2,3}'::text, 'most_common_freqs', '{0.3,0.25,0.05}'::real[], 'most_common_kind', 2::smallint); xman7=# SELECT pg_catalog.pg_restore_attribute_stats( 'schemaname', 'public', 'relname', 't_attribute_stats', 'attname', 'id', 'inherited', false::boolean, 'most_common_vals', '{1,2,3}'::text, 'most_common_freqs', '{0.3,0.25,0.05}'::real[], 'most_common_vals_kind', 0::smallint); WARNING: could not parse "most_common_vals_kind": it should be 1 or 8 pg_restore_attribute_stats ---------------------------- f (1 row) xman7=# select * from pg_catalog.pg_statistic where starelid =(select oid from pg_catalog.pg_class where relname = 't_attribute_stats')\gx -[ RECORD 1 ]---------------- starelid | 16614 staattnum | 1 stainherit | f stanullfrac | 0 stawidth | 0 stadistinct | 0 stakind1 | 1 stakind2 | 0 stakind3 | 0 stakind4 | 0 stakind5 | 0 staop1 | 96 staop2 | 0 staop3 | 0 staop4 | 0 staop5 | 0 stacoll1 | 0 stacoll2 | 0 stacoll3 | 0 stacoll4 | 0 stacoll5 | 0 stanumbers1 | {0.3,0.25,0.05} stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | {1,2,3} stavalues2 | stavalues3 | stavalues4 | stavalues5 | xman7=# Importing `most_common_kind = 1-STATISTIC_KIND_MCV succeeds. xman7=# SELECT pg_catalog.pg_restore_attribute_stats( 'schemaname', 'public', 'relname', 't_attribute_stats', 'attname', 'id', 'inherited', false::boolean, 'most_common_vals', '{11,22,33}'::text, 'most_common_freqs', '{0.33,0.2525,0.0505}'::real[], 'most_common_vals_kind', 1::smallint); pg_restore_attribute_stats ---------------------------- t (1 row) xman7=# select * from pg_catalog.pg_statistic where starelid =(select oid from pg_catalog.pg_class where relname = 't_attribute_stats')\gx -[ RECORD 1 ]--------------------- starelid | 16642 staattnum | 1 stainherit | f stanullfrac | 0 stawidth | 0 stadistinct | 0 stakind1 | 1 stakind2 | 0 stakind3 | 0 stakind4 | 0 stakind5 | 0 staop1 | 96 staop2 | 0 staop3 | 0 staop4 | 0 staop5 | 0 stacoll1 | 0 stacoll2 | 0 stacoll3 | 0 stacoll4 | 0 stacoll5 | 0 stanumbers1 | {0.33,0.2525,0.0505} stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | {11,22,33} stavalues2 | stavalues3 | stavalues4 | stavalues5 | xman7=# --Importing 8-STATISTIC_KIND_MCV_VALUE_SORTED succeeds. xman7=# SELECT pg_catalog.pg_restore_attribute_stats( 'schemaname', 'public', 'relname', 't_attribute_stats', 'attname', 'id', 'inherited', false::boolean, 'most_common_vals', '{1,2,3}'::text, 'most_common_freqs', '{0.3,0.25,0.05}'::real[], 'most_common_vals_kind', 8::smallint); pg_restore_attribute_stats ---------------------------- t (1 row) xman7=# select * from pg_catalog.pg_statistic where starelid =(select oid from pg_catalog.pg_class where relname = 't_attribute_stats')\gx -[ RECORD 1 ]---------------- starelid | 16642 staattnum | 1 stainherit | f stanullfrac | 0 stawidth | 0 stadistinct | 0 stakind1 | 8 stakind2 | 0 stakind3 | 0 stakind4 | 0 stakind5 | 0 staop1 | 96 staop2 | 0 staop3 | 0 staop4 | 0 staop5 | 0 stacoll1 | 0 stacoll2 | 0 stacoll3 | 0 stacoll4 | 0 stacoll5 | 0 stanumbers1 | {0.3,0.25,0.05} stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | {1,2,3} stavalues2 | stavalues3 | stavalues4 | stavalues5 | xman7=# --Importing 8-STATISTIC_KIND_MCV_VALUE_SORTED succeeds. xman7=# SELECT pg_catalog.pg_restore_attribute_stats( 'schemaname', 'public', 'relname', 't_attribute_stats', 'attname', 'id', 'inherited', false::boolean, 'most_common_vals', '{111,222,333}'::text, 'most_common_freqs', '{0.333,0.252525,0.050505}'::real[], 'most_common_vals_kind', 8::smallint); pg_restore_attribute_stats ---------------------------- t (1 row) xman7=# select * from pg_catalog.pg_statistic where starelid =(select oid from pg_catalog.pg_class where relname = 't_attribute_stats')\gx -[ RECORD 1 ]-------------------------- starelid | 16630 staattnum | 1 stainherit | f stanullfrac | 0 stawidth | 0 stadistinct | 0 stakind1 | 8 stakind2 | 0 stakind3 | 0 stakind4 | 0 stakind5 | 0 staop1 | 96 staop2 | 0 staop3 | 0 staop4 | 0 staop5 | 0 stacoll1 | 0 stacoll2 | 0 stacoll3 | 0 stacoll4 | 0 stacoll5 | 0 stanumbers1 | {0.333,0.252525,0.050505} stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | {111,222,333} stavalues2 | stavalues3 | stavalues4 | stavalues5 | xman7=# --If most_common_vals_kind is not specified, it defaults to 1-STATISTIC_KIND_MCV, and the import succeeds. xman7=# SELECT pg_catalog.pg_restore_attribute_stats( 'schemaname', 'public', 'relname', 't_attribute_stats', 'attname', 'id', 'inherited', false::boolean, 'most_common_vals', '{11,22,33}'::text, 'most_common_freqs', '{0.33,0.2525,0.0505}'::real[]); pg_restore_attribute_stats ---------------------------- t (1 row) xman7=# select * from pg_catalog.pg_statistic where starelid =(select oid from pg_catalog.pg_class where relname = 't_attribute_stats')\gx -[ RECORD 1 ]--------------------- starelid | 16642 staattnum | 1 stainherit | f stanullfrac | 0 stawidth | 0 stadistinct | 0 stakind1 | 1 stakind2 | 0 stakind3 | 0 stakind4 | 0 stakind5 | 0 staop1 | 96 staop2 | 0 staop3 | 0 staop4 | 0 staop5 | 0 stacoll1 | 0 stacoll2 | 0 stacoll3 | 0 stacoll4 | 0 stacoll5 | 0 stanumbers1 | {0.33,0.2525,0.0505} stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | {11,22,33} stavalues2 | stavalues3 | stavalues4 | stavalues5 | xman7=# --Importing 8-STATISTIC_KIND_MCV_VALUE_SORTED succeeds. xman7=# SELECT pg_catalog.pg_restore_attribute_stats( 'schemaname', 'public', 'relname', 't_attribute_stats', 'attname', 'id', 'inherited', false::boolean, 'most_common_vals', '{111,222,333}'::text, 'most_common_freqs', '{0.333,0.252525,0.050505}'::real[], 'most_common_vals_kind', 8::smallint); pg_restore_attribute_stats ---------------------------- t (1 row) xman7=# select * from pg_catalog.pg_statistic where starelid =(select oid from pg_catalog.pg_class where relname = 't_attribute_stats')\gx -[ RECORD 1 ]-------------------------- starelid | 16642 staattnum | 1 stainherit | f stanullfrac | 0 stawidth | 0 stadistinct | 0 stakind1 | 8 stakind2 | 0 stakind3 | 0 stakind4 | 0 stakind5 | 0 staop1 | 96 staop2 | 0 staop3 | 0 staop4 | 0 staop5 | 0 stacoll1 | 0 stacoll2 | 0 stacoll3 | 0 stacoll4 | 0 stacoll5 | 0 stanumbers1 | {0.333,0.252525,0.050505} stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | {111,222,333} stavalues2 | stavalues3 | stavalues4 | stavalues5 | xman7=# --If most_common_vals_kind is not specified, it defaults to 1-STATISTIC_KIND_MCV, and the import succeeds. xman7=# SELECT pg_catalog.pg_restore_attribute_stats( 'schemaname', 'public', 'relname', 't_attribute_stats', 'attname', 'id', 'inherited', false::boolean, 'most_common_vals', '{11,22,33}'::text, 'most_common_freqs', '{0.33,0.2525,0.0505}'::real[]); pg_restore_attribute_stats ---------------------------- t (1 row) xman7=# select * from pg_catalog.pg_statistic where starelid =(select oid from pg_catalog.pg_class where relname = 't_attribute_stats')\gx -[ RECORD 1 ]--------------------- starelid | 16642 staattnum | 1 stainherit | f stanullfrac | 0 stawidth | 0 stadistinct | 0 stakind1 | 1 stakind2 | 0 stakind3 | 0 stakind4 | 0 stakind5 | 0 staop1 | 96 staop2 | 0 staop3 | 0 staop4 | 0 staop5 | 0 stacoll1 | 0 stacoll2 | 0 stacoll3 | 0 stacoll4 | 0 stacoll5 | 0 stanumbers1 | {0.33,0.2525,0.0505} stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | {11,22,33} stavalues2 | stavalues3 | stavalues4 | stavalues5 | xman7=#