🌐 AI搜索 & 代理 主页
Skip to content

Commit 481783e

Browse files
committed
test_custom_stats: Add tests with read/write of auxiliary data
This commit builds upon 4ba012a, giving an example of what can be achieved with the new callbacks. This provides coverage for the new pgstats APIs, while serving as a reference template. Note that built-in stats kinds could use them, we just don't have a use-case there yet. Author: Sami Imseih <samimseih@gmail.com> Co-authored-by: Michael Paquier <michael@paquier.xyz> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Discussion: https://postgr.es/m/CAA5RZ0s9SDOu+Z6veoJCHWk+kDeTktAtC-KY9fQ9Z6BJdDUirQ@mail.gmail.com
1 parent 4ba012a commit 481783e

File tree

3 files changed

+428
-19
lines changed

3 files changed

+428
-19
lines changed

src/test/modules/test_custom_stats/t/001_custom_stats.pl

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929

3030
# Create entries for variable-sized stats.
3131
$node->safe_psql('postgres',
32-
q(select test_custom_stats_var_create('entry1')));
32+
q(select test_custom_stats_var_create('entry1', 'Test entry 1')));
3333
$node->safe_psql('postgres',
34-
q(select test_custom_stats_var_create('entry2')));
34+
q(select test_custom_stats_var_create('entry2', 'Test entry 2')));
3535
$node->safe_psql('postgres',
36-
q(select test_custom_stats_var_create('entry3')));
36+
q(select test_custom_stats_var_create('entry3', 'Test entry 3')));
3737
$node->safe_psql('postgres',
38-
q(select test_custom_stats_var_create('entry4')));
38+
q(select test_custom_stats_var_create('entry4', 'Test entry 4')));
3939

4040
# Update counters: entry1=2, entry2=3, entry3=2, entry4=3, fixed=3
4141
$node->safe_psql('postgres',
@@ -65,16 +65,28 @@
6565
# Test data reports.
6666
my $result = $node->safe_psql('postgres',
6767
q(select * from test_custom_stats_var_report('entry1')));
68-
is($result, "entry1|2", "report for variable-sized data of entry1");
68+
is( $result,
69+
"entry1|2|Test entry 1",
70+
"report for variable-sized data of entry1");
71+
6972
$result = $node->safe_psql('postgres',
7073
q(select * from test_custom_stats_var_report('entry2')));
71-
is($result, "entry2|3", "report for variable-sized data of entry2");
74+
is( $result,
75+
"entry2|3|Test entry 2",
76+
"report for variable-sized data of entry2");
77+
7278
$result = $node->safe_psql('postgres',
7379
q(select * from test_custom_stats_var_report('entry3')));
74-
is($result, "entry3|2", "report for variable-sized data of entry3");
80+
is( $result,
81+
"entry3|2|Test entry 3",
82+
"report for variable-sized data of entry3");
83+
7584
$result = $node->safe_psql('postgres',
7685
q(select * from test_custom_stats_var_report('entry4')));
77-
is($result, "entry4|3", "report for variable-sized data of entry4");
86+
is( $result,
87+
"entry4|3|Test entry 4",
88+
"report for variable-sized data of entry4");
89+
7890
$result = $node->safe_psql('postgres',
7991
q(select * from test_custom_stats_fixed_report()));
8092
is($result, "3|", "report for fixed-sized stats");
@@ -97,7 +109,16 @@
97109

98110
$result = $node->safe_psql('postgres',
99111
q(select * from test_custom_stats_var_report('entry1')));
100-
is($result, "entry1|2", "variable-sized stats persist after clean restart");
112+
is( $result,
113+
"entry1|2|Test entry 1",
114+
"variable-sized stats persist after clean restart");
115+
116+
$result = $node->safe_psql('postgres',
117+
q(select * from test_custom_stats_var_report('entry2')));
118+
is( $result,
119+
"entry2|3|Test entry 2",
120+
"variable-sized stats persist after clean restart");
121+
101122
$result = $node->safe_psql('postgres',
102123
q(select * from test_custom_stats_fixed_report()));
103124
is($result, "3|", "fixed-sized stats persist after clean restart");

src/test/modules/test_custom_stats/test_custom_var_stats--1.0.sql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
44
\echo Use "CREATE EXTENSION test_custom_var_stats" to load this file. \quit
55

6-
CREATE FUNCTION test_custom_stats_var_create(IN name TEXT)
6+
CREATE FUNCTION test_custom_stats_var_create(IN name TEXT, in description TEXT)
77
RETURNS void
88
AS 'MODULE_PATHNAME', 'test_custom_stats_var_create'
99
LANGUAGE C STRICT PARALLEL UNSAFE;
@@ -18,8 +18,9 @@ RETURNS void
1818
AS 'MODULE_PATHNAME', 'test_custom_stats_var_drop'
1919
LANGUAGE C STRICT PARALLEL UNSAFE;
2020

21-
22-
CREATE FUNCTION test_custom_stats_var_report(INOUT name TEXT, OUT calls BIGINT)
21+
CREATE FUNCTION test_custom_stats_var_report(INOUT name TEXT,
22+
OUT calls BIGINT,
23+
OUT description TEXT)
2324
RETURNS SETOF record
2425
AS 'MODULE_PATHNAME', 'test_custom_stats_var_report'
2526
LANGUAGE C STRICT PARALLEL UNSAFE;

0 commit comments

Comments
 (0)