pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix more issues with extended statistics on expressions
Date: Fri, 30 Oct 2026 08:30:25 +0000
Message-ID: <E1xMi0H-00000001NN7-2SzJ@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_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/8b517a30c832d2614d00e1dbe53fe06216adf548

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(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1xMi0H-00000001NN7-2SzJ@gemulon.postgresql.org>
Permalink:  ../E1xMi0H-00000001NN7-2SzJ@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xMi0H-00000001NN7-2SzJ@gemulon.postgresql.org

 · 

reply

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: <E1xMi0H-00000001NN7-2SzJ@gemulon.postgresql.org>
  References: <E1xMi0H-00000001NN7-2SzJ@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