From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix more issues with extended statistics on expressions
Date: Sun, 08 Nov 2026 21:30:26 +0000
Message-ID: <E1xQAT4-00000000kLL-3a5b@gemulon.postgresql.org> (raw)
Fix more issues with extended statistics on expressions
When evaluating expressions (through make_build_data()) and building
stats data for expressions (through build_expr_data()), both routines
forgot that examine_expression() could return a NULL result, depending
on the data generated by the typanalyze function assigned to a type.
This would crash the server.
This commit includes some tests added to test_custom_types that are able
to reproduce all these issues with two fancy typanalyze callbacks:
- False result with a valid stats target, for the expression evaluation.
- False result with a valid stats target on second call, for the stats
data build.
No typanalyze callback in core have the idea to do that, and I doubt
that anything out there has the idea to do that. If they do, this
switches the expression stats to fail gracefully instead of crashing,
based on the combinations that are assumed as supported by the core
code.
This is a continuation of 3b7a6fa15720.
Reported-by: Yuelin Wang <1217816127@qq.com>
Author: Shihao Zhong <zhong950419@gmail.com>
Author: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/19763-14da3f96c02f07e8@postgresql.org
Backpatch-through: 14
Branch
------
REL_18_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/4bcd0d31c6878b370cac8c738a35bb7bc5db22c5
Modified Files
--------------
src/backend/statistics/extended_stats.c | 48 ++++++++++++++++++----
src/test/modules/test_custom_types/README | 4 ++
.../expected/test_custom_types.out | 36 ++++++++++++++++
.../test_custom_types/sql/test_custom_types.sql | 28 +++++++++++++
.../test_custom_types/test_custom_types--1.0.sql | 16 ++++++++
.../modules/test_custom_types/test_custom_types.c | 37 +++++++++++++++++
6 files changed, 161 insertions(+), 8 deletions(-)
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: michael@paquier.xyz
Subject: Re: pgsql: Fix more issues with extended statistics on expressions
In-Reply-To: <E1xQAT4-00000000kLL-3a5b@gemulon.postgresql.org>
References: <E1xQAT4-00000000kLL-3a5b@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox