Hi,

While reviewing "autoanalyze on partitioned table" patch, I realized
that pg_stat_xxx_tables.n_mod_since_analyze is not reset at TRUNCATE.
On the other hand, n_ins_since_vacuum is reset. I think it should be
reset because otherwise we end up unnecessarily triggering autoanalyze
even when the actual number of newly inserted tuples is less than the
autoanalyze thresholds.

Steps to reproduce:

=# create table t (c int);
=# insert into t values (1), (2), (3);
=# update t set c = 999;
=# select relname, n_mod_since_analyze, n_ins_since_vacuum from
pg_stat_user_tables;
 relname | n_mod_since_analyze | n_ins_since_vacuum
---------+---------------------+--------------------
 t       |                   6 |                  3
(1 row)

=# truncate t;
=# select relname, n_mod_since_analyze, n_ins_since_vacuum from
pg_stat_user_tables;
 relname | n_mod_since_analyze | n_ins_since_vacuum
---------+---------------------+--------------------
 t       |                   6 |                  0
(1 row)

I've attached a small patch to fix this. Please review it.

Regards,

-- 
Masahiko Sawada
EDB:  https://www.enterprisedb.com/

Attachment: reset_n_mod_since_analyze.patch
Description: Binary data

Reply via email to