pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: alpkeles99@gmail.com
Subject: BUG #19789: "expression not found in statistics object" for a boolean domain column in an MCV statistics object
Date: Thu, 22 Oct 2026 14:03:45 +0000
Message-ID: <19789-b6592eeba8c6f6e1@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      19789
Logged by:          Alperen Keles
Email address:      alpkeles99@gmail.com
PostgreSQL version: 18.6
Operating system:   macOS 26.7 arm64
Description:        

Hello,

If a column whose type is a domain over boolean is part of an MCV
extended statistics object, a query that uses that column as a
boolean condition together with another clause on the object's
columns fails in the planner with an internal error:

  CREATE DOMAIN db AS bool;
  CREATE TABLE t (a int8, b db);
  INSERT INTO t VALUES (1, true);
  CREATE STATISTICS t_s (mcv) ON a, b FROM t;
  ANALYZE t;

  SELECT * FROM t WHERE a = 1 AND b;
  ERROR:  expression not found in statistics object

The same error occurs with NOT b, b = true, b = false, b <> false,
b::bool, a = 1 OR b, for EXPLAIN and DELETE, with two columns of the
domain (WHERE b1 AND b2), with a domain over that domain, and with
statistics created without a kind list (so including mcv). It does
not occur with a plain boolean column, with a domain over int4 or
text compared to a constant, with b IS TRUE or b IS NULL, with only
ndistinct or dependencies statistics, or before ANALYZE.

Reproduced on 18.6 (REL_18_STABLE a85b5523e67) and master
158b6d5109f, both with --enable-cassert, on macOS arm64. 13.23 fails
on the same statements with "ERROR:  unknown clause type: 125"
(T_RelabelType). The message changed with e33ae53ddec (the 14.5 fix
for MCV statistics on boolean expressions), but the failure remains.

As far as I can tell, the domain column used as a boolean is a
RelabelType over the Var. statext_is_compatible_clause_internal()
strips the RelabelType and accepts the clause as a plain column
reference, but mcv_get_match_bitmap() gets the unstripped clause.
That clause is not a Var, so it goes to the bare boolean expression
branch, and mcv_match_expression() does not find it among the
statistics object's expressions.

Found with a query fuzzer.

Regards,
Alperen Keles








view thread (2+ messages)  latest in thread

Message-ID: <19789-b6592eeba8c6f6e1@postgresql.org>
Permalink:  ../19789-b6592eeba8c6f6e1@postgresql.org/
Also on:    postgresql.org/message-id/19789-b6592eeba8c6f6e1@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-bugs@postgresql.org
  Cc: noreply@postgresql.org, alpkeles99@gmail.com
  Subject: Re: BUG #19789: "expression not found in statistics object" for a boolean domain column in an MCV statistics object
  In-Reply-To: <19789-b6592eeba8c6f6e1@postgresql.org>
  References: <19789-b6592eeba8c6f6e1@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