pgsql: Fix more issues with extended statistics on expressions

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix more issues with extended statistics on expressions
Date: 2026-11-08 21:30:26
Message-ID: E1xQAT4-00000000kLL-3a5b@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(at)qq(dot)com>
Author: Shihao Zhong <zhong950419(at)gmail(dot)com>
Author: Michael Paquier <michael(at)paquier(dot)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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2026-11-08 21:41:45 pgsql: Release notes for 18.7, 17.12, 16.16, 15.20, 14.25.
Previous Message Peter Eisentraut 2026-11-08 08:28:24 pgsql: Avoid duplicate file references in backend .pot file