mirror of
https://github.com/postgres/postgres.git
synced 2026-10-23 13:29:09 +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 ince207d2a79, 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(). Note that this has been originally applied asd4504d6f60in v19 and newer branches. This will be used for the test of a follow-up commit. Author: Corey Huinker <corey.huinker@gmail.com> Discussion: https://postgr.es/m/CADkLM=c3JivzHNXLt-X_JicYknRYwLTiOCHOPiKagm2_vdrFUg@mail.gmail.com Security: CVE-2026-16238 Backpatch-through: 18
This commit is contained in:
committed by
Noah Misch
parent
203a48209a
commit
8d428c6e67
@@ -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',
|
||||
@@ -1227,6 +1232,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
|
||||
@@ -1503,9 +1529,10 @@ AND attname = 'i';
|
||||
|
||||
DROP TABLE stats_temp;
|
||||
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
|
||||
|
||||
@@ -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',
|
||||
@@ -844,6 +850,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
|
||||
|
||||
Reference in New Issue
Block a user