1
0
mirror of https://github.com/postgres/postgres.git synced 2026-01-26 09:41:40 +03:00

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 ce207d2a79,
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
This commit is contained in:
Michael Paquier
2026-01-26 13:32:17 +09:00
parent c100340729
commit d4504d6f60
2 changed files with 52 additions and 1 deletions

View File

@@ -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

View File

@@ -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