Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bc3c8db

Browse filesBrowse files
committed
Display length and bounds histograms in pg_stats
Values corresponding to STATISTIC_KIND_RANGE_LENGTH_HISTOGRAM and STATISTIC_KIND_BOUNDS_HISTOGRAM were not exposed to pg_stats when these slot kinds were introduced in 918eee0. This commit adds the missing fields to pg_stats. Catversion is bumped. Discussion: https://postgr.es/m/flat/b67d8b57-9357-7e82-a2e7-f6ce6eaeec67@postgrespro.ru Author: Egor Rogov, Soumyadeep Chakraborty Reviewed-by: Tomas Vondra, Justin Pryzby, Jian He
1 parent 441c8a3 commit bc3c8db
Copy full SHA for bc3c8db

File tree

4 files changed

+87
-3
lines changed
Filter options

4 files changed

+87
-3
lines changed

‎doc/src/sgml/system-views.sgml

Copy file name to clipboardExpand all lines: doc/src/sgml/system-views.sgml
+39
Original file line numberDiff line numberDiff line change
@@ -3799,6 +3799,45 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx
37993799
non-null elements. (Null for scalar types.)
38003800
</para></entry>
38013801
</row>
3802+
3803+
<row>
3804+
<entry role="catalog_table_entry"><para role="column_definition">
3805+
<structfield>range_length_histogram</structfield> <type>anyarray</type>
3806+
</para>
3807+
<para>
3808+
A histogram of the lengths of non-empty and non-null range values of a
3809+
range type column. (Null for non-range types.)
3810+
</para>
3811+
<para>
3812+
This histogram is calculated using the <literal>subtype_diff</literal>
3813+
range function regardless of whether range bounds are inclusive.
3814+
</para></entry>
3815+
</row>
3816+
3817+
<row>
3818+
<entry role="catalog_table_entry"><para role="column_definition">
3819+
<structfield>range_empty_frac</structfield> <type>float4</type>
3820+
</para>
3821+
<para>
3822+
Fraction of column entries whose values are empty ranges.
3823+
(Null for non-range types.)
3824+
</para></entry>
3825+
</row>
3826+
3827+
<row>
3828+
<entry role="catalog_table_entry"><para role="column_definition">
3829+
<structfield>range_bounds_histogram</structfield> <type>anyarray</type>
3830+
</para>
3831+
<para>
3832+
A histogram of lower and upper bounds of non-empty and non-null range
3833+
values. (Null for non-range types.)
3834+
</para>
3835+
<para>
3836+
These two histograms are represented as a single array of ranges, whose
3837+
lower bounds represent the histogram of lower bounds, and upper bounds
3838+
represent the histogram of upper bounds.
3839+
</para></entry>
3840+
</row>
38023841
</tbody>
38033842
</tgroup>
38043843
</table>

‎src/backend/catalog/system_views.sql

Copy file name to clipboardExpand all lines: src/backend/catalog/system_views.sql
+22-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,28 @@ CREATE VIEW pg_stats WITH (security_barrier) AS
243243
WHEN stakind3 = 5 THEN stanumbers3
244244
WHEN stakind4 = 5 THEN stanumbers4
245245
WHEN stakind5 = 5 THEN stanumbers5
246-
END AS elem_count_histogram
246+
END AS elem_count_histogram,
247+
CASE
248+
WHEN stakind1 = 6 THEN stavalues1
249+
WHEN stakind2 = 6 THEN stavalues2
250+
WHEN stakind3 = 6 THEN stavalues3
251+
WHEN stakind4 = 6 THEN stavalues4
252+
WHEN stakind5 = 6 THEN stavalues5
253+
END AS range_length_histogram,
254+
CASE
255+
WHEN stakind1 = 6 THEN stanumbers1[1]
256+
WHEN stakind2 = 6 THEN stanumbers2[1]
257+
WHEN stakind3 = 6 THEN stanumbers3[1]
258+
WHEN stakind4 = 6 THEN stanumbers4[1]
259+
WHEN stakind5 = 6 THEN stanumbers5[1]
260+
END AS range_empty_frac,
261+
CASE
262+
WHEN stakind1 = 7 THEN stavalues1
263+
WHEN stakind2 = 7 THEN stavalues2
264+
WHEN stakind3 = 7 THEN stavalues3
265+
WHEN stakind4 = 7 THEN stavalues4
266+
WHEN stakind5 = 7 THEN stavalues5
267+
END AS range_bounds_histogram
247268
FROM pg_statistic s JOIN pg_class c ON (c.oid = s.starelid)
248269
JOIN pg_attribute a ON (c.oid = attrelid AND attnum = s.staattnum)
249270
LEFT JOIN pg_namespace n ON (n.oid = c.relnamespace)

‎src/include/catalog/catversion.h

Copy file name to clipboardExpand all lines: src/include/catalog/catversion.h
+1-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
*/
5858

5959
/* yyyymmddN */
60-
#define CATALOG_VERSION_NO 202311142
60+
#define CATALOG_VERSION_NO 202311271
6161

6262
#endif

‎src/test/regress/expected/rules.out

Copy file name to clipboardExpand all lines: src/test/regress/expected/rules.out
+25-1
Original file line numberDiff line numberDiff line change
@@ -2466,7 +2466,31 @@ pg_stats| SELECT n.nspname AS schemaname,
24662466
WHEN (s.stakind4 = 5) THEN s.stanumbers4
24672467
WHEN (s.stakind5 = 5) THEN s.stanumbers5
24682468
ELSE NULL::real[]
2469-
END AS elem_count_histogram
2469+
END AS elem_count_histogram,
2470+
CASE
2471+
WHEN (s.stakind1 = 6) THEN s.stavalues1
2472+
WHEN (s.stakind2 = 6) THEN s.stavalues2
2473+
WHEN (s.stakind3 = 6) THEN s.stavalues3
2474+
WHEN (s.stakind4 = 6) THEN s.stavalues4
2475+
WHEN (s.stakind5 = 6) THEN s.stavalues5
2476+
ELSE NULL::anyarray
2477+
END AS range_length_histogram,
2478+
CASE
2479+
WHEN (s.stakind1 = 6) THEN s.stanumbers1[1]
2480+
WHEN (s.stakind2 = 6) THEN s.stanumbers2[1]
2481+
WHEN (s.stakind3 = 6) THEN s.stanumbers3[1]
2482+
WHEN (s.stakind4 = 6) THEN s.stanumbers4[1]
2483+
WHEN (s.stakind5 = 6) THEN s.stanumbers5[1]
2484+
ELSE NULL::real
2485+
END AS range_empty_frac,
2486+
CASE
2487+
WHEN (s.stakind1 = 7) THEN s.stavalues1
2488+
WHEN (s.stakind2 = 7) THEN s.stavalues2
2489+
WHEN (s.stakind3 = 7) THEN s.stavalues3
2490+
WHEN (s.stakind4 = 7) THEN s.stavalues4
2491+
WHEN (s.stakind5 = 7) THEN s.stavalues5
2492+
ELSE NULL::anyarray
2493+
END AS range_bounds_histogram
24702494
FROM (((pg_statistic s
24712495
JOIN pg_class c ON ((c.oid = s.starelid)))
24722496
JOIN pg_attribute a ON (((c.oid = a.attrelid) AND (a.attnum = s.staattnum))))

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.