postgresql/src/backend
Tomas Vondra 20b9fa308e 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
2022-01-15 19:06:48 +01:00
..
access Unify VACUUM VERBOSE and autovacuum logging. 2022-01-14 16:50:34 -08:00
bootstrap Update copyright for 2022 2022-01-07 19:04:57 -05:00
catalog Fix memory leak in indexUnchanged hint mechanism. 2022-01-12 15:41:04 -08:00
commands Build inherited extended stats on partitioned tables 2022-01-15 19:06:48 +01:00
executor Fix memory leak in indexUnchanged hint mechanism. 2022-01-12 15:41:04 -08:00
foreign Update copyright for 2022 2022-01-07 19:04:57 -05:00
jit Update copyright for 2022 2022-01-07 19:04:57 -05:00
lib Update copyright for 2022 2022-01-07 19:04:57 -05:00
libpq Improve error handling of HMAC computations 2022-01-13 16:17:21 +09:00
main Update copyright for 2022 2022-01-07 19:04:57 -05:00
nodes Rename value node fields 2022-01-14 11:26:08 +01:00
optimizer Consider fractional paths in generate_orderedappend_paths 2022-01-12 22:27:24 +01:00
parser Rename value node fields 2022-01-14 11:26:08 +01:00
partitioning Update copyright for 2022 2022-01-07 19:04:57 -05:00
po
port Update copyright for 2022 2022-01-07 19:04:57 -05:00
postmaster Enhance pg_log_backend_memory_contexts() for auxiliary processes. 2022-01-11 23:19:59 +09:00
regex Update copyright for 2022 2022-01-07 19:04:57 -05:00
replication Improve error handling of cryptohash computations 2022-01-11 09:55:16 +09:00
rewrite Update copyright for 2022 2022-01-07 19:04:57 -05:00
snowball Update copyright for 2022 2022-01-07 19:04:57 -05:00
statistics Build inherited extended stats on partitioned tables 2022-01-15 19:06:48 +01:00
storage Improve warning message in pg_signal_backend() 2022-01-11 12:56:26 -05:00
tcop Update copyright for 2022 2022-01-07 19:04:57 -05:00
tsearch Update copyright for 2022 2022-01-07 19:04:57 -05:00
utils Build inherited extended stats on partitioned tables 2022-01-15 19:06:48 +01:00
.gitignore
common.mk
Makefile Update copyright for 2022 2022-01-07 19:04:57 -05:00
nls.mk Report progress of startup operations that take a long time. 2021-10-25 11:51:57 -04:00