Skip to content

Commit 3c99230

Browse files
committed
psql: Display stats target of extended statistics
The stats target can be set since commit d06215d, but wasn't shown by psql. Author: Justin Pryzby <justin@telsasoft.com> Discussion: https://postgr.es/m/20200831050047.GG5450@telsasoft.com Reviewed-by: Georgios Kokolatos <gkokolatos@protonmail.com> Reviewed-by: Tatsuro Yamada <tatsuro.yamada.tf@nttcom.co.jp>
1 parent 10095ca commit 3c99230

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/bin/psql/describe.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,8 +2683,13 @@ describeOneTableDetails(const char *schemaname,
26832683
" a.attnum = s.attnum AND NOT attisdropped)) AS columns,\n"
26842684
" 'd' = any(stxkind) AS ndist_enabled,\n"
26852685
" 'f' = any(stxkind) AS deps_enabled,\n"
2686-
" 'm' = any(stxkind) AS mcv_enabled\n"
2687-
"FROM pg_catalog.pg_statistic_ext stat "
2686+
" 'm' = any(stxkind) AS mcv_enabled,\n");
2687+
2688+
if (pset.sversion >= 130000)
2689+
appendPQExpBufferStr(&buf, " stxstattarget\n");
2690+
else
2691+
appendPQExpBufferStr(&buf, " -1 AS stxstattarget\n");
2692+
appendPQExpBuffer(&buf, "FROM pg_catalog.pg_statistic_ext stat\n"
26882693
"WHERE stxrelid = '%s'\n"
26892694
"ORDER BY 1;",
26902695
oid);
@@ -2732,6 +2737,11 @@ describeOneTableDetails(const char *schemaname,
27322737
PQgetvalue(result, i, 4),
27332738
PQgetvalue(result, i, 1));
27342739

2740+
/* Show the stats target if it's not default */
2741+
if (strcmp(PQgetvalue(result, i, 8), "-1") != 0)
2742+
appendPQExpBuffer(&buf, "; STATISTICS %s",
2743+
PQgetvalue(result, i, 8));
2744+
27352745
printTableAddFooter(&cont, buf.data);
27362746
}
27372747
}

src/test/regress/expected/stats_ext.out

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ WARNING: statistics object "public.ab1_a_b_stats" could not be computed for rel
102102
ALTER TABLE ab1 ALTER a SET STATISTICS -1;
103103
-- setting statistics target 0 skips the statistics, without printing any message, so check catalog
104104
ALTER STATISTICS ab1_a_b_stats SET STATISTICS 0;
105+
\d ab1
106+
Table "public.ab1"
107+
Column | Type | Collation | Nullable | Default
108+
--------+---------+-----------+----------+---------
109+
a | integer | | |
110+
b | integer | | |
111+
Statistics objects:
112+
"public"."ab1_a_b_stats" (ndistinct, dependencies, mcv) ON a, b FROM ab1; STATISTICS 0
113+
105114
ANALYZE ab1;
106115
SELECT stxname, stxdndistinct, stxddependencies, stxdmcv
107116
FROM pg_statistic_ext s, pg_statistic_ext_data d
@@ -113,6 +122,15 @@ SELECT stxname, stxdndistinct, stxddependencies, stxdmcv
113122
(1 row)
114123

115124
ALTER STATISTICS ab1_a_b_stats SET STATISTICS -1;
125+
\d+ ab1
126+
Table "public.ab1"
127+
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
128+
--------+---------+-----------+----------+---------+---------+--------------+-------------
129+
a | integer | | | | plain | |
130+
b | integer | | | | plain | |
131+
Statistics objects:
132+
"public"."ab1_a_b_stats" (ndistinct, dependencies, mcv) ON a, b FROM ab1
133+
116134
-- partial analyze doesn't build stats either
117135
ANALYZE ab1 (a);
118136
WARNING: statistics object "public.ab1_a_b_stats" could not be computed for relation "public.ab1"

src/test/regress/sql/stats_ext.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@ ANALYZE ab1;
7272
ALTER TABLE ab1 ALTER a SET STATISTICS -1;
7373
-- setting statistics target 0 skips the statistics, without printing any message, so check catalog
7474
ALTER STATISTICS ab1_a_b_stats SET STATISTICS 0;
75+
\d ab1
7576
ANALYZE ab1;
7677
SELECT stxname, stxdndistinct, stxddependencies, stxdmcv
7778
FROM pg_statistic_ext s, pg_statistic_ext_data d
7879
WHERE s.stxname = 'ab1_a_b_stats'
7980
AND d.stxoid = s.oid;
8081
ALTER STATISTICS ab1_a_b_stats SET STATISTICS -1;
82+
\d+ ab1
8183
-- partial analyze doesn't build stats either
8284
ANALYZE ab1 (a);
8385
ANALYZE ab1;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy