From 4264f11d67d25c6d4a2398961c3f5a879810c33e Mon Sep 17 00:00:00 2001 From: Shinya Kato Date: Fri, 2 May 2025 16:42:00 +0900 Subject: [PATCH v3 5/9] Make pg_stat_reset_single_function_counters() return the reset time --- doc/src/sgml/monitoring.sgml | 4 ++-- src/backend/utils/adt/pgstatfuncs.c | 5 +++-- src/include/catalog/pg_proc.dat | 2 +- src/test/isolation/expected/stats.out | 16 ++++++++-------- src/test/isolation/expected/stats_1.out | 16 ++++++++-------- src/test/isolation/specs/stats.spec | 4 ++-- 6 files changed, 24 insertions(+), 23 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index bfe6145c1d6..60ece8b02a8 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -5193,11 +5193,11 @@ description | Waiting for a newly initialized WAL file to reach durable storage pg_stat_reset_single_function_counters pg_stat_reset_single_function_counters ( oid ) - void + timestamp with time zone Resets statistics for a single function in the current database to - zero. + zero, and returns the time of the reset. This function is restricted to superusers by default, but other users diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index 18c8286dc7f..b3d3d7f027d 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -1954,10 +1954,11 @@ Datum pg_stat_reset_single_function_counters(PG_FUNCTION_ARGS) { Oid funcoid = PG_GETARG_OID(0); + TimestampTz ts; - pgstat_reset(PGSTAT_KIND_FUNCTION, MyDatabaseId, funcoid); + ts = pgstat_reset(PGSTAT_KIND_FUNCTION, MyDatabaseId, funcoid); - PG_RETURN_VOID(); + PG_RETURN_TIMESTAMPTZ(ts); } /* diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat index 6548bc89a27..b05e96c5994 100644 --- a/src/include/catalog/pg_proc.dat +++ b/src/include/catalog/pg_proc.dat @@ -6174,7 +6174,7 @@ { oid => '3777', descr => 'statistics: reset collected statistics for a single function in the current database', proname => 'pg_stat_reset_single_function_counters', provolatile => 'v', - prorettype => 'void', proargtypes => 'oid', + prorettype => 'timestamptz', proargtypes => 'oid', prosrc => 'pg_stat_reset_single_function_counters' }, { oid => '6387', descr => 'statistics: reset statistics for a single backend', proname => 'pg_stat_reset_backend_stats', provolatile => 'v', diff --git a/src/test/isolation/expected/stats.out b/src/test/isolation/expected/stats.out index 89dcca903eb..3b50447179d 100644 --- a/src/test/isolation/expected/stats.out +++ b/src/test/isolation/expected/stats.out @@ -1146,10 +1146,10 @@ has_stats_reset f (1 row) -step s1_func_stats_reset: SELECT pg_stat_reset_single_function_counters('test_stat_func'::regproc); -pg_stat_reset_single_function_counters --------------------------------------- - +step s1_func_stats_reset: SELECT pg_stat_reset_single_function_counters('test_stat_func'::regproc) IS NOT NULL AS t; +t +- +t (1 row) step s1_func_stats: @@ -1218,10 +1218,10 @@ pg_stat_get_function_calls (1 row) -step s1_func_stats_reset_nonexistent: SELECT pg_stat_reset_single_function_counters(12000); -pg_stat_reset_single_function_counters --------------------------------------- - +step s1_func_stats_reset_nonexistent: SELECT pg_stat_reset_single_function_counters(12000) IS NOT NULL AS t; +t +- +t (1 row) step s1_func_stats_nonexistent: diff --git a/src/test/isolation/expected/stats_1.out b/src/test/isolation/expected/stats_1.out index ea6f4aebbc0..6960faa2930 100644 --- a/src/test/isolation/expected/stats_1.out +++ b/src/test/isolation/expected/stats_1.out @@ -1146,10 +1146,10 @@ has_stats_reset f (1 row) -step s1_func_stats_reset: SELECT pg_stat_reset_single_function_counters('test_stat_func'::regproc); -pg_stat_reset_single_function_counters --------------------------------------- - +step s1_func_stats_reset: SELECT pg_stat_reset_single_function_counters('test_stat_func'::regproc) IS NOT NULL AS t; +t +- +t (1 row) step s1_func_stats: @@ -1218,10 +1218,10 @@ pg_stat_get_function_calls (1 row) -step s1_func_stats_reset_nonexistent: SELECT pg_stat_reset_single_function_counters(12000); -pg_stat_reset_single_function_counters --------------------------------------- - +step s1_func_stats_reset_nonexistent: SELECT pg_stat_reset_single_function_counters(12000) IS NOT NULL AS t; +t +- +t (1 row) step s1_func_stats_nonexistent: diff --git a/src/test/isolation/specs/stats.spec b/src/test/isolation/specs/stats.spec index a8705926fa6..a9f4e741d37 100644 --- a/src/test/isolation/specs/stats.spec +++ b/src/test/isolation/specs/stats.spec @@ -57,12 +57,12 @@ step s1_track_funcs_all { SET track_functions = 'all'; } step s1_track_funcs_none { SET track_functions = 'none'; } step s1_func_call { SELECT test_stat_func(); } step s1_func_drop { DROP FUNCTION test_stat_func(); } -step s1_func_stats_reset { SELECT pg_stat_reset_single_function_counters('test_stat_func'::regproc); } +step s1_func_stats_reset { SELECT pg_stat_reset_single_function_counters('test_stat_func'::regproc) IS NOT NULL AS t; } step s1_func_stats_reset_check { SELECT pg_stat_get_function_stat_reset_time('test_stat_func'::regproc) IS NOT NULL AS has_stats_reset; } -step s1_func_stats_reset_nonexistent { SELECT pg_stat_reset_single_function_counters(12000); } +step s1_func_stats_reset_nonexistent { SELECT pg_stat_reset_single_function_counters(12000) IS NOT NULL AS t; } step s1_reset { SELECT pg_stat_reset() IS NOT NULL AS t; } step s1_func_stats { SELECT -- 2.47.3