Hosoya-san,
Thanks for the new patch.
On Wed, Feb 26, 2020 at 11:33 AM yuzuko <yuzukohosoya@gmail.com> wrote:
> Attach the v5 patch. In this patch, pgstat_report_analyze() always reports 0 as
> msg.m_live_tuples and m_dead_tuples when the relation is partitioned.
Some comments:
+ * PgStat_MsgPartAnalyze Sent by the backend or autovacuum daemon
+ * after ANALYZE for partitioned tables
Looking at the way this message is used, it does not seem to be an
"analyze" message and also it's not sent "after ANALYZE of partitioned
tables", but really after ANALYZE of leaf partitions. Analyze (for
both partitioned tables and leaf partitions) is reported as a
PgStat_MsgAnalyze message as before. It seems that
PgStat_MsgPartAnalyze is only sent to update a leaf partition's
parent's (and recursively any grandparents') changes_since_analyze
counters, so maybe we should find a different name for it. Maybe,
PgStat_MsgPartChanges and accordingly the message type enum value.
/*
- * Report ANALYZE to the stats collector, too. However, if doing
- * inherited stats we shouldn't report, because the stats collector only
- * tracks per-table stats. Reset the changes_since_analyze counter only
- * if we analyzed all columns; otherwise, there is still work for
- * auto-analyze to do.
+ * Report ANALYZE to the stats collector, too. If the table is a
+ * partition, report changes_since_analyze of its parent because
+ * autovacuum process for partitioned tables needs it. Reset the
+ * changes_since_analyze counter only if we analyzed all columns;
+ * otherwise, there is still work for auto-analyze to do.
*/
The new comment says "partitions", which we typically use to refer to
a child table, but this comment really talks about parent tables. Old
comment says we don't report "inherited stats", presumably because
stats collector lacks the infrastructure to distinguish a table's
inherited stats and own stats, at least in the case of traditional
inheritance. With this patch, we are making an exception for
partitioned tables, because we are also teaching the stats collector
to maintain at least changes_since_analyze for them that accumulates
counts of changed tuples from partitions.
It seems Alvaro already reported some of the other issues I had with
the patch, such as why partanalyze messages are only sent from a
autovacuum worker.
Thanks,
Amit