| From: | PG Bug reporting form <noreply(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Cc: | imchifan(at)163(dot)com |
| Subject: | BUG #19715: pg_restore_attribute_stats() rejects range statistics for a domain over int4multirange |
| Date: | 2026-09-22 16:10:04 |
| Message-ID: | 19715-b8be35083016f289@postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
The following bug has been logged on the website:
Bug reference: 19715
Logged by: Qifan Liu
Email address: imchifan(at)163(dot)com
PostgreSQL version: 18.6
Operating system: Linux/amd64
Description:
pg_restore_attribute_stats() rejects range length and bounds histograms for
a column whose type is a domain over int4multirange. It returns false and
warns that the column is not a range type. However, ANALYZE generates both
range-specific statistic kinds 6 and 7 for a column of the same domain type.
As a result, statistics exported for a domain over a multirange type cannot
be faithfully restored to an equivalent column.
Steps to reproduce
------------------
Run the following input with psql -X:
\set ON_ERROR_STOP on
CREATE DOMAIN restore_stats_mr AS int4multirange;
CREATE TABLE restore_stats_src (v restore_stats_mr);
CREATE TABLE restore_stats_dst (v restore_stats_mr);
INSERT INTO restore_stats_src VALUES
('{[1,3)}'), ('{[5,9)}'), ('{[11,15)}');
ANALYZE restore_stats_src;
SELECT array_agg(k ORDER BY k) AS analyze_range_kinds
FROM (
SELECT unnest(ARRAY[stakind1, stakind2, stakind3, stakind4, stakind5]) AS
k
FROM pg_statistic
WHERE starelid = 'restore_stats_src'::regclass
AND staattnum = 1
) s
WHERE k IN (6, 7);
SELECT pg_catalog.pg_restore_attribute_stats(
'schemaname', 'public',
'relname', 'restore_stats_dst',
'attname', 'v',
'inherited', false,
'range_length_histogram', '{2,4,4}'::text,
'range_empty_frac', 0::real,
'range_bounds_histogram', ARRAY['[1,3)', '[5,9)', '[11,15)']::text
) AS restore_ok;
SELECT count(*) = 2 AS restored_both_range_kinds
FROM (
SELECT unnest(ARRAY[stakind1, stakind2, stakind3, stakind4, stakind5]) AS
k
FROM pg_statistic
WHERE starelid = 'restore_stats_dst'::regclass
AND staattnum = 1
) s
WHERE k IN (6, 7);
Actual result
-------------
analyze_range_kinds
---------------------
{6,7}
WARNING: column "v" is not a range type
DETAIL: Cannot set STATISTIC_KIND_RANGE_LENGTH_HISTOGRAM or
STATISTIC_KIND_BOUNDS_HISTOGRAM.
restore_ok
------------
f
restored_both_range_kinds
---------------------------
f
Expected result
---------------
pg_restore_attribute_stats() should return true and restore statistic kinds
6 and 7. ANALYZE produces those range statistics for the same domain type,
so the restoration path should not reject them as belonging to a non-range
column.
Additional information
----------------------
The issue was reproduced on PostgreSQL 20devel and PostgreSQL 18.6.
PostgreSQL 17.11 does not provide pg_restore_attribute_stats().
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2026-09-22 16:19:43 | Re: BUG #19712: MultiXact Recovery Deadlock |
| Previous Message | PG Bug reporting form | 2026-09-22 16:05:30 | BUG #19714: pgcrypto pgp_sym_encrypt accepts nonnumeric s2k-mode as mode 0 |