agora inbox for pgsql-bugs@postgresql.org  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: imchifan@163.com
Subject: BUG #19715: pg_restore_attribute_stats() rejects range statistics for a domain over int4multirange
Date: Tue, 22 Sep 2026 16:10:04 +0000
Message-ID: <19715-b8be35083016f289@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      19715
Logged by:          Qifan Liu
Email address:      imchifan@163.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().







view thread (14+ messages)  latest in thread

Message-ID: <19715-b8be35083016f289@postgresql.org>
Permalink:  ../19715-b8be35083016f289@postgresql.org/
Also on:    postgresql.org/message-id/19715-b8be35083016f289@postgresql.org

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, imchifan@163.com
  Subject: Re: BUG #19715: pg_restore_attribute_stats() rejects range statistics for a domain over int4multirange
  In-Reply-To: <19715-b8be35083016f289@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox