Speeding up ANALYZE on large partitioned tables - Mailing list pgsql-general

From Gabriel Sánchez
Subject Speeding up ANALYZE on large partitioned tables
Date
Msg-id CANHuRqGh4x4OAXwePkjhcN2QqCPFHoKxP7astnOUQRB8P0Eyag@mail.gmail.com
Whole thread Raw
List pgsql-general
Hi PostgreSQL community,

I have a database with several very large tables (for example, 86 GB) that are partitioned by year, sub-partitioned by month, and sub-sub-partitioned by day. Each day a new partition is added, and that partition is immediately ANALYZEd by my process. 

However I noticed that sometimes the query plans for queries on the top-level partitioned table don't make much sense, and I read in the documentation that ANALYEing the leaf partitions doesn't update the statistics of the parent and grandparent tables. So I have to run ANALYZE on the top-level table, and when I do that the query plan makes more sense. But it takes quite a while to ANALYZE the 86 GB table with hundreds of sub-sub=partitions, because that ANALYZE triggers an ANALYZE on each partition down the tree. Since leaf tables are always ANALYZED when created, isn't there a way to update the statistics of the parent and grandparent tables based on the statistics already calculated for the partitions? Maybe with an ANALYZE ONLY [top-level table]?

Thanks,
Gabriel

pgsql-general by date:

Previous
From: Gabriel Sánchez
Date:
Subject: How to query with more workers on a large table with many partitions
Next
From: Greg Hennessy
Date:
Subject: Re: How to query with more workers on a large table with many partitions