Hi,
On Fri, Oct 16, 2026 Richard Guo wrote:
> v2-0001 extends v1 to relabel a rebuilt NULLIF to its original typmod
> as well, [...] v2-0002 fixes that by looking through the RelabelType
> there.
I ran a differential sweep of v2 on REL_19_STABLE against 18:
COALESCE/CASE/NULLIF shapes x 15 types (typmod, domain, array, ICU
nondeterministic) x inlining modes x ON CONFLICT sites, plus result
and FULL JOIN USING checks. v2 fixes every ON CONFLICT failure that
REL_19_STABLE has in that matrix and restores the FULL JOIN pushdown
that 0001 alone loses. No result differs from 18 except where 18 is
wrong.
One case still fails, on current REL_19_STABLE and with v2. Bisect
points at e2debb64380, "Reduce Var IS [NOT] NULL quals during constant
folding"; 18 accepts it:
CREATE FUNCTION f(varchar) RETURNS varchar
LANGUAGE sql IMMUTABLE AS 'SELECT $1';
CREATE TABLE t (a varchar(20) NOT NULL, b varchar(20));
CREATE UNIQUE INDEX ON t ((f((CASE WHEN a IS NULL THEN b END)::varchar(3))));
INSERT INTO t VALUES ('x', 'y')
ON CONFLICT ((f((CASE WHEN a IS NULL THEN b END)::varchar(3)))) DO NOTHING;
ERROR: there is no unique or exclusion constraint matching the ON CONFLICT
specification
The NullTest fold added there runs only when eval_const_expressions()
has a PlannerInfo. RelationGetIndexExpressions() simplifies the index
expression with root = NULL, so the CASE is not reduced: f() is inlined
and the cast's typmod (3) stays visible, and infer_arbiter_indexes()
later folds it to a Const of typmod 3. The ON CONFLICT expression is
simplified once, with root, so its argument folds first and f() is
evaluated to a Const of typmod -1. equal() then sees typmod 3 vs -1.
A non-null constant and numeric fail the same way; a STABLE f() works,
since it is never pre-evaluated.
Comparing the two expressions in infer_arbiter_indexes() without
typmod-only decorations (a RelabelType that keeps type and collation,
and Const typmod) closes it, passes the regression tests, and changes
nothing else in the sweep; it sits on top of v2. I can post it if you
want it.
Regards,
Manu