Skip to content

Commit dfb01c8

Browse files
l-wangoppenheimer01
authored andcommitted
Add gp_stat_progress_%_summary system views
Added the following views: gp_stat_progress_vacuum_summary gp_stat_progress_analyze_summary gp_stat_progress_cluster_summary gp_stat_progress_create_index_summary Also replaced pg_stat_progress_* views with gp_stat_progress_* views for existing tests.
1 parent 4fd461c commit dfb01c8

12 files changed

Lines changed: 537 additions & 230 deletions

src/backend/catalog/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ endif
204204
$(INSTALL_DATA) $(srcdir)/system_functions.sql '$(DESTDIR)$(datadir)/system_functions.sql'
205205
$(INSTALL_DATA) $(srcdir)/system_views.sql '$(DESTDIR)$(datadir)/system_views.sql'
206206
$(INSTALL_DATA) $(srcdir)/$(GP_SYSVIEW_SQL) '$(DESTDIR)$(datadir)/$(GP_SYSVIEW_SQL)'
207+
$(INSTALL_DATA) $(srcdir)/system_views_gp_summary.sql '$(DESTDIR)$(datadir)/system_views_gp_summary.sql'
207208
$(INSTALL_DATA) $(srcdir)/information_schema.sql '$(DESTDIR)$(datadir)/information_schema.sql'
208209
$(INSTALL_DATA) $(call vpathsearch,cdb_schema.sql) '$(DESTDIR)$(datadir)/cdb_init.d/cdb_schema.sql'
209210
$(INSTALL_DATA) $(srcdir)/sql_features.txt '$(DESTDIR)$(datadir)/sql_features.txt'
@@ -215,7 +216,7 @@ installdirs:
215216

216217
.PHONY: uninstall-data
217218
uninstall-data:
218-
rm -f $(addprefix '$(DESTDIR)$(datadir)'/, postgres.bki system_constraints.sql system_functions.sql system_views.sql information_schema.sql cdb_init.d/cdb_schema.sql cdb_init.d/gp_toolkit.sql sql_features.txt fix-CVE-2024-4317.sql)
219+
rm -f $(addprefix '$(DESTDIR)$(datadir)'/, postgres.bki system_constraints.sql system_functions.sql system_views.sql system_views_gp_summary.sql information_schema.sql cdb_init.d/cdb_schema.sql cdb_init.d/gp_toolkit.sql sql_features.txt fix-CVE-2024-4317.sql)
219220
ifeq ($(USE_INTERNAL_FTS_FOUND), false)
220221
rm -f $(addprefix '$(DESTDIR)$(datadir)'/, external_fts.sql)
221222
endif
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Greenplum System Summary Views
3+
*
4+
* Portions Copyright (c) 2006-2010, Greenplum inc.
5+
* Portions Copyright (c) 2012-Present VMware, Inc. or its affiliates.
6+
* Copyright (c) 1996-2019, PostgreSQL Global Development Group
7+
*
8+
* src/backend/catalog/system_views_gp_summary.sql
9+
*
10+
11+
* This file contains summary views for various Greenplum system catalog
12+
* views. These summary views are designed to provide aggregated or averaged
13+
* information for partitioned and replicated tables, considering multiple
14+
* segments in a Greenplum database.
15+
*
16+
* Note: this file is read in single-user -j mode, which means that the
17+
* command terminator is semicolon-newline-newline; whenever the backend
18+
* sees that, it stops and executes what it's got. If you write a lot of
19+
* statements without empty lines between, they'll all get quoted to you
20+
* in any error message about one of them, so don't do that. Also, you
21+
* cannot write a semicolon immediately followed by an empty line in a
22+
* string literal (including a function body!) or a multiline comment.
23+
*/
24+
25+
CREATE VIEW gp_stat_progress_vacuum_summary AS
26+
SELECT
27+
max(coalesce(a1.pid, 0)) as pid,
28+
a.datid,
29+
a.datname,
30+
a.relid,
31+
a.phase,
32+
case when d.policytype = 'r' then (sum(a.heap_blks_total)/d.numsegments)::bigint else sum(a.heap_blks_total) end heap_blks_total,
33+
case when d.policytype = 'r' then (sum(a.heap_blks_scanned)/d.numsegments)::bigint else sum(a.heap_blks_scanned) end heap_blks_scanned,
34+
case when d.policytype = 'r' then (sum(a.heap_blks_vacuumed)/d.numsegments)::bigint else sum(a.heap_blks_vacuumed) end heap_blks_vacuumed,
35+
case when d.policytype = 'r' then (sum(a.index_vacuum_count)/d.numsegments)::bigint else sum(a.index_vacuum_count) end index_vacuum_count,
36+
case when d.policytype = 'r' then (sum(a.max_dead_tuples)/d.numsegments)::bigint else sum(a.max_dead_tuples) end max_dead_tuples,
37+
case when d.policytype = 'r' then (sum(a.num_dead_tuples)/d.numsegments)::bigint else sum(a.num_dead_tuples) end num_dead_tuples
38+
FROM gp_stat_progress_vacuum a
39+
JOIN pg_class c ON a.relid = c.oid
40+
LEFT JOIN gp_distribution_policy d ON c.oid = d.localoid
41+
LEFT JOIN gp_stat_progress_vacuum a1 ON a.pid = a1.pid AND a1.gp_segment_id = -1
42+
WHERE a.gp_segment_id > -1
43+
GROUP BY a.datid, a.datname, a.relid, a.phase, d.policytype, d.numsegments;
44+
45+
CREATE OR REPLACE VIEW gp_stat_progress_analyze_summary AS
46+
SELECT
47+
max(coalesce(a1.pid, 0)) as pid,
48+
a.datid,
49+
a.datname,
50+
a.relid,
51+
a.phase,
52+
case when d.policytype = 'r' then (sum(a.sample_blks_total)/d.numsegments)::bigint else sum(a.sample_blks_total) end sample_blks_total,
53+
case when d.policytype = 'r' then (sum(a.sample_blks_scanned)/d.numsegments)::bigint else sum(a.sample_blks_scanned) end sample_blks_scanned,
54+
case when d.policytype = 'r' then (sum(a.ext_stats_total)/d.numsegments)::bigint else sum(a.ext_stats_total) end ext_stats_total,
55+
case when d.policytype = 'r' then (sum(a.ext_stats_computed)/d.numsegments)::bigint else sum(a.ext_stats_computed) end ext_stats_computed,
56+
case when d.policytype = 'r' then (sum(a.child_tables_total)/d.numsegments)::bigint else sum(a.child_tables_total) end child_tables_total,
57+
case when d.policytype = 'r' then (sum(a.child_tables_done)/d.numsegments)::bigint else sum(a.child_tables_done) end child_tables_done
58+
FROM gp_stat_progress_analyze a
59+
JOIN pg_class c ON a.relid = c.oid
60+
LEFT JOIN gp_distribution_policy d ON c.oid = d.localoid
61+
LEFT JOIN gp_stat_progress_analyze a1 ON a.pid = a1.pid AND a1.gp_segment_id = -1
62+
WHERE a.gp_segment_id > -1
63+
GROUP BY a.datid, a.datname, a.relid, a.phase, d.policytype, d.numsegments;
64+
65+
CREATE OR REPLACE VIEW gp_stat_progress_cluster_summary AS
66+
SELECT
67+
max(coalesce(a1.pid, 0)) as pid,
68+
a.datid,
69+
a.datname,
70+
a.relid,
71+
a.command,
72+
a.phase,
73+
a.cluster_index_relid,
74+
case when d.policytype = 'r' then (sum(a.heap_tuples_scanned)/d.numsegments)::bigint else sum(a.heap_tuples_scanned) end heap_tuples_scanned,
75+
case when d.policytype = 'r' then (sum(a.heap_tuples_written)/d.numsegments)::bigint else sum(a.heap_tuples_written) end heap_tuples_written,
76+
case when d.policytype = 'r' then (sum(a.heap_blks_total)/d.numsegments)::bigint else sum(a.heap_blks_total) end heap_blks_total,
77+
case when d.policytype = 'r' then (sum(a.heap_blks_scanned)/d.numsegments)::bigint else sum(a.heap_blks_scanned) end heap_blks_scanned,
78+
case when d.policytype = 'r' then (sum(a.index_rebuild_count)/d.numsegments)::bigint else sum(a.index_rebuild_count) end index_rebuild_count
79+
FROM gp_stat_progress_cluster a
80+
JOIN pg_class c ON a.relid = c.oid
81+
LEFT JOIN gp_distribution_policy d ON c.oid = d.localoid
82+
LEFT JOIN gp_stat_progress_cluster a1 ON a.pid = a1.pid AND a1.gp_segment_id = -1
83+
WHERE a.gp_segment_id > -1
84+
GROUP BY a.datid, a.datname, a.relid, a.command, a.phase, a.cluster_index_relid, d.policytype, d.numsegments;
85+
86+
CREATE OR REPLACE VIEW gp_stat_progress_create_index_summary AS
87+
SELECT
88+
max(coalesce(a1.pid, 0)) as pid,
89+
a.datid,
90+
a.datname,
91+
a.relid,
92+
a.index_relid,
93+
a.command,
94+
a.phase,
95+
case when d.policytype = 'r' then (sum(a.lockers_total)/d.numsegments)::bigint else sum(a.lockers_total) end lockers_total,
96+
case when d.policytype = 'r' then (sum(a.lockers_done)/d.numsegments)::bigint else sum(a.lockers_done) end lockers_done,
97+
max(a.current_locker_pid) as current_locker_pid,
98+
case when d.policytype = 'r' then (sum(a.blocks_total)/d.numsegments)::bigint else sum(a.blocks_total) end blocks_total,
99+
case when d.policytype = 'r' then (sum(a.blocks_done)/d.numsegments)::bigint else sum(a.blocks_done) end blocks_done,
100+
case when d.policytype = 'r' then (sum(a.tuples_total)/d.numsegments)::bigint else sum(a.tuples_total) end tuples_total,
101+
case when d.policytype = 'r' then (sum(a.tuples_done)/d.numsegments)::bigint else sum(a.tuples_done) end tuples_done,
102+
case when d.policytype = 'r' then (sum(a.partitions_total)/d.numsegments)::bigint else sum(a.partitions_total) end partitions_total,
103+
case when d.policytype = 'r' then (sum(a.partitions_done)/d.numsegments)::bigint else sum(a.partitions_done) end partitions_done
104+
FROM gp_stat_progress_create_index a
105+
JOIN pg_class c ON a.relid = c.oid
106+
LEFT JOIN gp_distribution_policy d ON c.oid = d.localoid
107+
LEFT JOIN gp_stat_progress_create_index a1 ON a.pid = a1.pid AND a1.gp_segment_id = -1
108+
WHERE a.gp_segment_id > -1
109+
GROUP BY a.datid, a.datname, a.relid, a.index_relid, a.command, a.phase, d.policytype, d.numsegments;

src/backend/commands/analyze.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,6 +1875,7 @@ acquire_sample_rows(Relation onerel, int elevel,
18751875

18761876
pgstat_progress_update_param(PROGRESS_ANALYZE_BLOCKS_DONE,
18771877
++blksdone);
1878+
SIMPLE_FAULT_INJECTOR("analyze_block");
18781879
}
18791880

18801881
ExecDropSingleTupleTableSlot(slot);

src/bin/initdb/initdb.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ static char *external_fts_files;
193193
static char *system_functions_file;
194194
static char *system_views_file;
195195
static char *system_views_gp_file;
196+
static char *system_views_gp_summary_file;
196197
static bool success = false;
197198
static bool made_new_pgdata = false;
198199
static bool found_existing_pgdata = false;
@@ -1767,8 +1768,6 @@ setup_run_file(FILE *cmdfd, const char *filename)
17671768
}
17681769

17691770
PG_CMD_PUTS("\n\n");
1770-
1771-
free(lines);
17721771
}
17731772

17741773
/*
@@ -3037,6 +3036,7 @@ setup_data_file_paths(void)
30373036
set_input(&system_functions_file, "system_functions.sql");
30383037
set_input(&system_views_file, "system_views.sql");
30393038
set_input(&system_views_gp_file, "system_views_gp.sql");
3039+
set_input(&system_views_gp_summary_file, "system_views_gp_summary.sql");
30403040

30413041
set_input(&cdb_init_d_dir, "cdb_init.d");
30423042

@@ -3071,6 +3071,7 @@ setup_data_file_paths(void)
30713071
check_input(system_functions_file);
30723072
check_input(system_views_file);
30733073
check_input(system_views_gp_file);
3074+
check_input(system_views_gp_summary_file);
30743075
}
30753076

30763077

@@ -3401,6 +3402,7 @@ initialize_data_directory(void)
34013402

34023403
setup_run_file(cmdfd, system_views_file);
34033404
setup_run_file(cmdfd, system_views_gp_file);
3405+
setup_run_file(cmdfd, system_views_gp_summary_file);
34043406

34053407
setup_description(cmdfd);
34063408

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
-- Test gp_stat_progress_analyze_summary
2+
-- setup hash distributed table
3+
CREATE TABLE t_analyze_part (a INT, b INT) DISTRIBUTED BY (a);
4+
CREATE
5+
INSERT INTO t_analyze_part SELECT i, i FROM generate_series(1, 100000) i;
6+
INSERT 100000
7+
8+
-- Suspend analyze after scanning 20 blocks on each segment
9+
SELECT gp_inject_fault('analyze_block', 'suspend', '', '', '', 20, 20, 0, dbid) FROM gp_segment_configuration WHERE content > -1 AND role = 'p';
10+
gp_inject_fault
11+
-----------------
12+
Success:
13+
Success:
14+
Success:
15+
(3 rows)
16+
17+
-- session 1: analyze the table
18+
1&: ANALYZE t_analyze_part; <waiting ...>
19+
SELECT gp_wait_until_triggered_fault('analyze_block', 1, dbid) FROM gp_segment_configuration WHERE content > -1 AND role = 'p';
20+
gp_wait_until_triggered_fault
21+
-------------------------------
22+
Success:
23+
Success:
24+
Success:
25+
(3 rows)
26+
27+
-- session 2: query pg_stat_progress_analyze while the analyze is running, the view should indicate 60 blocks have been scanned as aggregated progress of 3 segments
28+
2: SELECT pid IS NOT NULL as has_pid, datname, relid::regclass, phase, sample_blks_total, sample_blks_scanned FROM gp_stat_progress_analyze_summary;
29+
has_pid | datname | relid | phase | sample_blks_total | sample_blks_scanned
30+
---------+----------------+----------------+-----------------------+-------------------+---------------------
31+
t | isolation2test | t_analyze_part | acquiring sample rows | 111 | 60
32+
(1 row)
33+
34+
-- Reset fault injector
35+
SELECT gp_inject_fault('analyze_block', 'reset', dbid) FROM gp_segment_configuration WHERE content > -1 AND role = 'p';
36+
gp_inject_fault
37+
-----------------
38+
Success:
39+
Success:
40+
Success:
41+
(3 rows)
42+
1<: <... completed>
43+
ANALYZE
44+
45+
-- teardown
46+
DROP TABLE t_analyze_part;
47+
DROP
48+
49+
-- setup replicated table
50+
CREATE TABLE t_analyze_repl (a INT, b INT) DISTRIBUTED REPLICATED;
51+
CREATE
52+
INSERT INTO t_analyze_repl SELECT i, i FROM generate_series(1, 100000) i;
53+
INSERT 100000
54+
55+
-- Suspend analyze after scanning 20 blocks on each segment
56+
SELECT gp_inject_fault('analyze_block', 'suspend', '', '', '', 20, 20, 0, dbid) FROM gp_segment_configuration WHERE content > -1 AND role = 'p';
57+
gp_inject_fault
58+
-----------------
59+
Success:
60+
Success:
61+
Success:
62+
(3 rows)
63+
64+
-- session 1: analyze the table
65+
1&: ANALYZE t_analyze_repl; <waiting ...>
66+
SELECT gp_wait_until_triggered_fault('analyze_block', 1, dbid) FROM gp_segment_configuration WHERE content > -1 AND role = 'p';
67+
gp_wait_until_triggered_fault
68+
-------------------------------
69+
Success:
70+
Success:
71+
Success:
72+
(3 rows)
73+
74+
-- session 2: query pg_stat_progress_analyze while the analyze is running, the view should indicate 20 blocks have been scanned as average progress of 3 segments
75+
2: SELECT pid IS NOT NULL as has_pid, datname, relid::regclass, phase, sample_blks_total, sample_blks_scanned FROM gp_stat_progress_analyze_summary;
76+
has_pid | datname | relid | phase | sample_blks_total | sample_blks_scanned
77+
---------+----------------+----------------+-----------------------+-------------------+---------------------
78+
t | isolation2test | t_analyze_repl | acquiring sample rows | 111 | 20
79+
(1 row)
80+
81+
-- Reset fault injector
82+
SELECT gp_inject_fault('analyze_block', 'reset', dbid) FROM gp_segment_configuration WHERE content > -1 AND role = 'p';
83+
gp_inject_fault
84+
-----------------
85+
Success:
86+
Success:
87+
Success:
88+
(3 rows)
89+
1<: <... completed>
90+
ANALYZE
91+
92+
-- teardown
93+
DROP TABLE t_analyze_repl;
94+
DROP
95+

0 commit comments

Comments
 (0)