]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Build inherited extended stats on partitioned tables
authorTomas Vondra <tomas.vondra@postgresql.org>
Sat, 15 Jan 2022 17:17:20 +0000 (18:17 +0100)
committerTomas Vondra <tomas.vondra@postgresql.org>
Sat, 15 Jan 2022 17:30:45 +0000 (18:30 +0100)
commit9211c2e38f099d97d14b5556d7afc76bef083783
tree1bbe3712d10f423658459b2988f6114aee812930
parentff0e7c7e840122419054d72a7884fa17ce1a4ab9
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
src/backend/commands/analyze.c
src/backend/statistics/dependencies.c
src/backend/utils/adt/selfuncs.c
src/test/regress/expected/stats_ext.out
src/test/regress/sql/stats_ext.sql