pgsql: Ignore extended statistics for inheritance trees

From: Tomas Vondra <tomas(dot)vondra(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Ignore extended statistics for inheritance trees
Date: 2022-01-15 02:10:59
Message-ID: E1n8YWx-00066D-3T@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Ignore extended statistics for inheritance trees

Since commit 859b3003de we only build extended statistics for individual
relations, ignoring the child relations. This resolved the issue with
updating catalog tuple twice, but we still tried to use the statistics
when calculating estimates for the whole inheritance tree. When the
relations contain very distinct data, it may produce bogus estimates.

This is roughly the same issue 427c6b5b9 addressed ~15 years ago, and we
fix it the same way - by ignoring extended statistics when calculating
estimates for the inheritance tree as a whole. We still consider
extended statistics when calculating estimates for individual child
relations, of course.

This may result in plan changes due to different estimates, but if the
old statistics were not describing the inheritance tree particularly
well it's quite likely the new plans is actually better.

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
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/36c4bc6e725fe3e9b5a6cc7f1f83010534f18e4b

Modified Files
--------------
src/backend/statistics/dependencies.c | 9 ++++++++
src/backend/statistics/extended_stats.c | 9 ++++++++
src/backend/utils/adt/selfuncs.c | 17 ++++++++++++++
src/test/regress/expected/stats_ext.out | 41 +++++++++++++++++++++++++++++++++
src/test/regress/sql/stats_ext.sql | 22 ++++++++++++++++++
5 files changed, 98 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Tomas Vondra 2022-01-15 02:12:45 pgsql: Ignore extended statistics for inheritance trees
Previous Message Peter Geoghegan 2022-01-15 00:54:46 pgsql: Unify VACUUM VERBOSE and autovacuum logging.