Re: BUG #19481: multivariate MCV expression stats not applied for equivalent predicates on nullable side of LEFT JOI

From: Andrei Lepikhov <lepihov(at)gmail(dot)com>
To: yankairong(at)ruc(dot)edu(dot)cn, pgsql-bugs(at)lists(dot)postgresql(dot)org, PG Bug reporting form <noreply(at)postgresql(dot)org>
Subject: Re: BUG #19481: multivariate MCV expression stats not applied for equivalent predicates on nullable side of LEFT JOI
Date: 2026-05-18 06:40:39
Message-ID: 77c94271-4552-4797-9fc4-ec2c3817e53f@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 16/05/2026 12:07, PG Bug reporting form wrote:
> That strongly suggests the extended expression MCV stats are still not being
> matched for equivalent predicates on the nullable side of the outer join.
The query explain tells the whole story:

Nested Loop Left Join
Filter: ((COALESCE(mod(m.a, 20), 1) = 1) AND (COALESCE(mod(m.b, 10), 1) = 1)
AND (COALESCE(mod(m.c, 5), 1) = 1))
-> Result
-> Seq Scan on mcv_bug m

As you can see, this clause is a JOIN clause. Your coalesce filter applies to
the result of the join. But m.a,m.b, and m.c might be changed (nullified) in
this join. So, your extended statistic isn't applicable here. To be relevant, it
should calculate the number of not-matched LHS tuples and account for them.

In your case, the ON clause is 'true', so all tuples will be matched. It is a
degenerate case and might potentially be improved, but it doesn't look like a bug.

--
regards, Andrei Lepikhov,
pgEdge

In response to

Browse pgsql-bugs by date

  From Date Subject
Previous Message Japin Li 2026-05-18 03:10:04 Re: BUG #19478: `dblink_close` can be used for injection.