]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Add test for pg_stat_reset_single_table_counters() on index
authorMichael Paquier <michael@paquier.xyz>
Mon, 6 Oct 2025 05:34:45 +0000 (14:34 +0900)
committerMichael Paquier <michael@paquier.xyz>
Mon, 6 Oct 2025 05:34:45 +0000 (14:34 +0900)
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

src/test/regress/expected/stats.out
src/test/regress/sql/stats.sql

index 605f50703769a3e7cfaa2ef09ff5978c8c6d1728..ea3c4287ca7c03bca54e3e2ef3f34435e53a2587 100644 (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
 -----
index 54e7286634452bc853f484f970bb84dec2882ce3..73bdd11d65440c546997f770d2adc9f99edeb684 100644 (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
 -----