postgres.git / summary / log / commit / refs
commit d4504d6f60e07516cd3b0311054e6f8e74496281
Author: Michael Paquier <michael@paquier.xyz>
Date: Mon Jan 26 04:32:17 2026 +0000
Add test with multirange type for pg_restore_attribute_stats()
This commit adds a test for pg_restore_attribute_stats() with the
injection of statistics related to a multirange type. This case is
supported in statatt_get_type() since its introduction in ce207d2a7901,
but there was no test in the main regression test suite to check for the
case where attribute stats is restored for a multirange type, as done by
multirange_typanalyze().
Author: Corey Huinker <corey.huinker@gmail.com>
Discussion: https://postgr.es/m/CADkLM=c3JivzHNXLt-X_JicYknRYwLTiOCHOPiKagm2_vdrFUg@mail.gmail.com
src/test/regress/expected/stats_import.out | 29 ++++++++++++++++++++++++++++-
src/test/regress/sql/stats_import.sql | 24 ++++++++++++++++++++++++
2 files changed, 52 insertions(+), 1 deletion(-)
diff --git a/src/test/regress/expected/stats_import.out b/src/test/regress/expected/stats_import.out
index d61ab92d17b..3fd77879e13 100644
--- a/src/test/regress/expected/stats_import.out
+++ b/src/test/regress/expected/stats_import.out
@@ -12,6 +12,11 @@ CREATE TABLE stats_import.test(
arange int4range,
tags text[]
) WITH (autovacuum_enabled = false);
+CREATE TABLE stats_import.test_mr(
+ id INTEGER PRIMARY KEY,
+ name text,
+ mrange int4multirange
+) WITH (autovacuum_enabled = false);
SELECT
pg_catalog.pg_restore_relation_stats(
'schemaname', 'stats_import',
@@ -1095,6 +1100,27 @@ AND attname = 'id';
stats_import | test | id | f | 0.36 | 5 | 0.6 | {2,1,3} | {0.3,0.25,0.05} | {1,2,3,4} | | | | | | |
(1 row)
+-- test for multiranges
+INSERT INTO stats_import.test_mr
+VALUES
+ (1, 'red', '{[1,3),[5,9),[20,30)}'::int4multirange),
+ (2, 'red', '{[11,13),[15,19),[20,30)}'::int4multirange),
+ (3, 'red', '{[21,23),[25,29),[120,130)}'::int4multirange);
+-- ensure that we set attribute stats for a multirange
+SELECT pg_catalog.pg_restore_attribute_stats(
+ 'schemaname', 'stats_import',
+ 'relname', 'test_mr',
+ 'attname', 'mrange',
+ 'inherited', false,
+ 'range_length_histogram', '{19,29,109}'::text,
+ 'range_empty_frac', '0'::real,
+ 'range_bounds_histogram', '{"[1,30)","[11,30)","[21,130)"}'::text
+);
+ pg_restore_attribute_stats
+----------------------------
+ t
+(1 row)
+
--
-- Test the ability to exactly copy data from one table to an identical table,
-- correctly reconstructing the stakind order as well as the staopN and
@@ -1565,9 +1591,10 @@ REVOKE MAINTAIN ON stats_import.test FROM regress_test_extstat_clear;
REVOKE ALL ON SCHEMA stats_import FROM regress_test_extstat_clear;
DROP ROLE regress_test_extstat_clear;
DROP SCHEMA stats_import CASCADE;
-NOTICE: drop cascades to 6 other objects
+NOTICE: drop cascades to 7 other objects
DETAIL: drop cascades to type stats_import.complex_type
drop cascades to table stats_import.test
+drop cascades to table stats_import.test_mr
drop cascades to table stats_import.part_parent
drop cascades to sequence stats_import.testseq
drop cascades to view stats_import.testview
diff --git a/src/test/regress/sql/stats_import.sql b/src/test/regress/sql/stats_import.sql
index d1934a8a42b..c2d927203d5 100644
--- a/src/test/regress/sql/stats_import.sql
+++ b/src/test/regress/sql/stats_import.sql
@@ -15,6 +15,12 @@ CREATE TABLE stats_import.test(
tags text[]
) WITH (autovacuum_enabled = false);
+CREATE TABLE stats_import.test_mr(
+ id INTEGER PRIMARY KEY,
+ name text,
+ mrange int4multirange
+) WITH (autovacuum_enabled = false);
+
SELECT
pg_catalog.pg_restore_relation_stats(
'schemaname', 'stats_import',
@@ -764,6 +770,24 @@ AND tablename = 'test'
AND inherited = false
AND attname = 'id';
+-- test for multiranges
+INSERT INTO stats_import.test_mr
+VALUES
+ (1, 'red', '{[1,3),[5,9),[20,30)}'::int4multirange),
+ (2, 'red', '{[11,13),[15,19),[20,30)}'::int4multirange),
+ (3, 'red', '{[21,23),[25,29),[120,130)}'::int4multirange);
+
+-- ensure that we set attribute stats for a multirange
+SELECT pg_catalog.pg_restore_attribute_stats(
+ 'schemaname', 'stats_import',
+ 'relname', 'test_mr',
+ 'attname', 'mrange',
+ 'inherited', false,
+ 'range_length_histogram', '{19,29,109}'::text,
+ 'range_empty_frac', '0'::real,
+ 'range_bounds_histogram', '{"[1,30)","[11,30)","[21,130)"}'::text
+);
+
--
-- Test the ability to exactly copy data from one table to an identical table,
-- correctly reconstructing the stakind order as well as the staopN and
[parent: c100340729b6]