pgsql: Build inherited extended stats on partitioned tables - Mailing list pgsql-committers

From Tomas Vondra
Subject pgsql: Build inherited extended stats on partitioned tables
Date
Msg-id E1n8nmJ-00041t-HI@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Build inherited extended stats on partitioned tables

Commit 859b3003de disabled building of extended stats for inheritance
trees, to prevent updating the same catalog row twice. While that
resolved the issue, it also means there are no extended stats for
declaratively partitioned tables, because there are no data in the
non-leaf relations.

That also means declaratively partitioned tables were not affected by
the issue 859b3003de addressed, which means this is a regression
affecting queries that calculate estimates for the whole inheritance
tree as a whole (which includes e.g. GROUP BY queries).

But because partitioned tables are empty, we can invert the condition
and build statistics only for the case with inheritance, without losing
anything. And we can consider them when calculating estimates.

It may be necessary to run ANALYZE on partitioned tables, to collect
proper statistics. For declarative partitioning there should no prior
statistics, and it might take time before autoanalyze is triggered. For
tables partitioned by inheritance the statistics may include data from
child relations (if built 859b3003de), contradicting the current code.

Report and patch by Justin Pryzby, minor fixes and cleanup by me.
Backpatch all the way back to PostgreSQL 10, where extended statistics
were introduced (same as 859b3003de).

Author: Justin Pryzby
Reported-by: Justin Pryzby
Backpatch-through: 10
Discussion: https://postgr.es/m/20210923212624.GI831%40telsasoft.com

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/491182e52909564ce2fe9bc9c5f8ae6640682b30

Modified Files
--------------
src/backend/commands/analyze.c          | 18 +++++++++++++++++-
src/backend/statistics/dependencies.c   | 10 +++++++---
src/backend/utils/adt/selfuncs.c        | 20 ++++++++++++--------
src/test/regress/expected/stats_ext.out | 19 +++++++++++++++++++
src/test/regress/sql/stats_ext.sql      | 10 ++++++++++
5 files changed, 65 insertions(+), 12 deletions(-)


pgsql-committers by date:

Previous
From: Tomas Vondra
Date:
Subject: pgsql: Build inherited extended stats on partitioned tables
Next
From: Tomas Vondra
Date:
Subject: pgsql: Build inherited extended stats on partitioned tables