1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-16 17:07:43 +03:00

Add test for pg_stat_reset_single_table_counters() on index

stats.sql is already doing some tests coverage on index statistics, by
retrieving for example idx_scan and friends in pg_stat_all_tables.
pg_stat_reset_single_table_counters() is supported for an index for a
long time, but the case was never covered.

This commit closes the gap, by using this reset function on an index,
cross-checking the contents of pg_stat_all_indexes.

Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Discussion: https://postgr.es/m/aN8l182jKxEq1h9f@paquier.xyz
This commit is contained in:
Michael Paquier
2025-10-06 14:34:45 +09:00
parent 0c7f103028
commit c173aaff98
2 changed files with 30 additions and 0 deletions

View File

@@ -850,6 +850,27 @@ FROM pg_stat_all_tables WHERE relid = 'test_last_scan'::regclass;
2 | t | 3 | t
(1 row)
-- check the stats in pg_stat_all_indexes
SELECT idx_scan, :'test_last_idx' < last_idx_scan AS idx_ok
FROM pg_stat_all_indexes WHERE indexrelid = 'test_last_scan_pkey'::regclass;
idx_scan | idx_ok
----------+--------
3 | t
(1 row)
-- check that the stats in pg_stat_all_indexes are reset
SELECT pg_stat_reset_single_table_counters('test_last_scan_pkey'::regclass);
pg_stat_reset_single_table_counters
-------------------------------------
(1 row)
SELECT idx_scan FROM pg_stat_all_indexes WHERE indexrelid = 'test_last_scan_pkey'::regclass;
idx_scan
----------
0
(1 row)
-----
-- Test reset of some stats for shared table
-----

View File

@@ -382,6 +382,15 @@ COMMIT;
SELECT seq_scan, :'test_last_seq' = last_seq_scan AS seq_ok, idx_scan, :'test_last_idx' < last_idx_scan AS idx_ok
FROM pg_stat_all_tables WHERE relid = 'test_last_scan'::regclass;
-- check the stats in pg_stat_all_indexes
SELECT idx_scan, :'test_last_idx' < last_idx_scan AS idx_ok
FROM pg_stat_all_indexes WHERE indexrelid = 'test_last_scan_pkey'::regclass;
-- check that the stats in pg_stat_all_indexes are reset
SELECT pg_stat_reset_single_table_counters('test_last_scan_pkey'::regclass);
SELECT idx_scan FROM pg_stat_all_indexes WHERE indexrelid = 'test_last_scan_pkey'::regclass;
-----
-- Test reset of some stats for shared table
-----