public inbox for pgsql-bugs@postgresql.org  
help / color / mirror / Atom feed
From: Andrei Lepikhov <lepihov@gmail.com>
To: yankairong@ruc.edu.cn
To: pgsql-bugs@lists.postgresql.org
To: PG Bug reporting form <noreply@postgresql.org>
Subject: Re: BUG #19481: multivariate MCV expression stats not applied for equivalent predicates on nullable side of LEFT JOI
Date: Mon, 18 May 2026 08:40:39 +0200
Message-ID: <77c94271-4552-4797-9fc4-ec2c3817e53f@gmail.com> (raw)
In-Reply-To: <19481-4afc34accc9043fe@postgresql.org>
References: <19481-4afc34accc9043fe@postgresql.org>

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






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 using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: lepihov@gmail.com, yankairong@ruc.edu.cn, pgsql-bugs@lists.postgresql.org, noreply@postgresql.org
  Subject: Re: BUG #19481: multivariate MCV expression stats not applied for equivalent predicates on nullable side of LEFT JOI
  In-Reply-To: <77c94271-4552-4797-9fc4-ec2c3817e53f@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox