Re: Incorrect selectivity estimates for NOT on nullable boolean columns

From: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
To: Ilia Evdokimov <ilya(dot)evdokimov(at)tantorlabs(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org, ZizhuanLiu X-MAN <44973863(at)qq(dot)com>, solai v <solai(dot)cdac(at)gmail(dot)com>, Pierre Forstmann <pierre(dot)forstmann(at)gmail(dot)com>
Subject: Re: Incorrect selectivity estimates for NOT on nullable boolean columns
Date: 2026-12-03 22:36:13
Message-ID: CAN4CZFN3tmHepFU1n_6Yoj+ESda78BNbEi-+npC-KRFRTkgO7w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

hELLO

An LLM-based tetsing of the patch found that while the patch improves
some cases, it also causes at least two regressions:

1. DISTINCT with 100% true 50% not true

CREATE TABLE t AS SELECT true AS a, i AS b FROM
generate_series(1,10000) AS g(i);
ANALYZE t;
EXPLAIN ANALYZE WITH s AS MATERIALIZED (SELECT DISTINCT a,b FROM t)
SELECT * FROM s WHERE NOT a;
-- patched: CTE Scan on s ... rows=5000 ... actual rows=0.00
-- master: CTE Scan on s ... rows=1 ... actual rows=0.00

2. NOT inside BooleanTest (IS FALSE / IS NOT FALSE) regresses on
nullable booleans

CREATE TABLE t (id int, deleted boolean) WITH (autovacuum_enabled = off);
INSERT INTO t
SELECT i, CASE WHEN i <= 9500 THEN NULL WHEN i <= 9900 THEN true ELSE false END
FROM generate_series(1, 10000) AS g(i);
ANALYZE t;
CREATE VIEW v AS SELECT id, NOT deleted AS active FROM t;

EXPLAIN ANALYZE SELECT * FROM v WHERE active IS FALSE;
-- patched: rows=9900 (actual rows=400.00)
-- master: rows=400 (actual rows=400.00)

EXPLAIN ANALYZE SELECT * FROM v WHERE active IS NOT FALSE;
-- patched: rows=100 (actual rows=9600.00)
-- master: rows=9600 (actual rows=9600.00)

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Zsolt Parragi 2026-12-03 22:52:32 Re: DROP USER MAPPING doesn't acquire lock on its server
Previous Message Masahiko Sawada 2026-12-03 22:28:15 Re: Add a hook for handling logical decoding messages on subscribers.