public inbox for [email protected]
help / color / mirror / Atom feedFrom: Gabriel Sánchez <[email protected]>
To: Postgres General <[email protected]>
Subject: Speeding up ANALYZE on large partitioned tables
Date: Wed, 1 Apr 2026 11:04:43 -0400
Message-ID: <CANHuRqGh4x4OAXwePkjhcN2QqCPFHoKxP7astnOUQRB8P0Eyag@mail.gmail.com> (raw)
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
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: Speeding up ANALYZE on large partitioned tables
In-Reply-To: <CANHuRqGh4x4OAXwePkjhcN2QqCPFHoKxP7astnOUQRB8P0Eyag@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox