pg_stats and range statistics

From: Egor Rogov <e(dot)rogov(at)postgrespro(dot)ru>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: pg_stats and range statistics
Date: 2021-06-18 16:22:51
Message-ID: b67d8b57-9357-7e82-a2e7-f6ce6eaeec67@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Statistics for range types are not currently exposed in pg_stats view
(i.e. STATISTIC_KIND_RANGE_LENGTH_HISTOGRAM and
STATISTIC_KIND_BOUNDS_HISTOGRAM).

Shouldn't they? If so, here is a patch for adding them.

The following is a simple example of what it looks like:

CREATE TABLE test(r int4range);
INSERT INTO test
    SELECT int4range((random()*10)::integer,(10+random()*10)::integer)
    FROM generate_series(1,10000);
SET default_statistics_target = 10;
ANALYZE test;

SELECT range_length_histogram, range_length_empty_frac,
range_bounds_histogram
FROM pg_stats
WHERE tablename = 'test' \gx

-[ RECORD 1
]-----------+------------------------------------------------------------------------------------------------------
range_length_histogram  | {1,4,6,8,9,10,11,12,14,16,20}
range_length_empty_frac | {0.0036666666}
range_bounds_histogram  |
{"[0,10)","[1,11)","[2,12)","[3,13)","[4,14)","[5,15)","[6,16)","[7,17)","[8,18)","[9,19)","[10,20)"}

Regards,
Egor Rogov.

Attachment Content-Type Size
pgstats.patch text/plain 4.6 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message John Naylor 2021-06-18 16:32:29 Re: disfavoring unparameterized nested loops
Previous Message Yugo NAGATA 2021-06-18 15:46:05 Re: pgbench bug candidate: negative "initial connection time"