BUG #19789: "expression not found in statistics object" for a boolean domain column in an MCV statistics object

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: alpkeles99(at)gmail(dot)com
Subject: BUG #19789: "expression not found in statistics object" for a boolean domain column in an MCV statistics object
Date: 2026-10-22 14:03:45
Message-ID: 19789-b6592eeba8c6f6e1@postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 19789
Logged by: Alperen Keles
Email address: alpkeles99(at)gmail(dot)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

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2026-10-22 14:05:57 BUG #19790: "cannot start a subtransaction ... inval messages" after "ALTER DOMAIN ... DROP CONSTRAINT"
Previous Message Nitin Motiani 2026-10-22 13:00:04 Re: BUG #19767: pg_get_viewdef prints ORDER BY (- '3'::int4) as (- 3), which reparses as column position -3