pgsql: Reject pseudo-types in extended statistics expressions.

From: Noah Misch <noah(at)leadboat(dot)com>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Reject pseudo-types in extended statistics expressions.
Date: 2026-11-09 14:21:59
Message-ID: E1xQQFz-000000003eT-1SsG@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Reject pseudo-types in extended statistics expressions.

Previously, CREATE STATISTICS accepted an expression of a pseudo-type.
So the statistics were built on a value whose row type is identified
only by a typmod assigned locally in the backend that ran ANALYZE.
Therefore, other sessions could read the statistics as the wrong data
type, which can crash the server or return wrong results.

Reject such expressions at CREATE STATISTICS time, including a type
that contains a pseudo-type, such as a composite type with an anyarray
column. An expression whose collation can't be determined is now
rejected too, but ANALYZE fails on such statistics anyway.

Since a statistics expression has no column name, teach the column type
check to report an error without one.

A statistics object built this way on an older minor release can still
exist on v18 and older, so in those branches also error out when such
statistics are used by the planner, their contents are read, or ANALYZE
builds them. Those objects should be dropped.

Backpatch to 14, where statistics on expressions were introduced.

Reported-by: Mehmet D. INCE <mehmet(at)mehmetince(dot)net>
Reviewed-by: Michael Paquier <michael(at)paquier(dot)xyz>
Reviewed-by: Andres Freund <andres(at)anarazel(dot)de>
Backpatch-through: 14
Security: CVE-2026-120148

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/74a999de18d442a3fecf752dceff2144110e75c4
Author: Masahiko Sawada <msawada(at)postgresql(dot)org>

Modified Files
--------------
src/backend/catalog/heap.c | 22 ++++++++++++++++++++--
src/backend/commands/statscmds.c | 11 ++++++++++-
src/backend/statistics/extended_stats.c | 19 +++++++++++++++++++
src/backend/statistics/mcv.c | 17 +++++++++++++++++
src/backend/utils/adt/ruleutils.c | 14 ++++++++++++++
src/backend/utils/adt/selfuncs.c | 17 +++++++++++++++++
src/test/regress/expected/stats_ext.out | 22 ++++++++++++++++++++++
src/test/regress/sql/stats_ext.sql | 16 ++++++++++++++++
8 files changed, 135 insertions(+), 3 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Noah Misch 2026-11-09 14:22:00 pgsql: Enforce view row visibility for INSERT ... ON CONFLICT target ro
Previous Message Noah Misch 2026-11-09 14:21:58 pgsql: Handle composite type changes in ExecEvalFieldStore[De]Form