Re: Hash-based MCV matching for large IN-lists

Ilia Evdokimov <ilya.evdokimov@tantorlabs.com>

From: Ilia Evdokimov <ilya.evdokimov@tantorlabs.com>
To: Zsolt Parragi <zsolt.parragi@percona.com>
Cc: David Geier <geidav.pg@gmail.com>, Chengpeng Yan <chengpeng_yan@outlook.com>, Tatsuya Kawata <kawatatatsuya0913@gmail.com>, "pgsql-hackers@lists.postgresql.org" <pgsql-hackers@lists.postgresql.org>
Date: 2026-03-20T15:58:43Z
Lists: pgsql-hackers

Attachments

On 3/11/26 11:01, Zsolt Parragi wrote:

> + /*
> + * For ALL semantics, if the array contains NULL, assume
> + * operator is strict. The ScalarArrayOpExpr cannot
> + * evaluate to TRUE, so return zero.
> + */
>
>
>
> + nonconst_sel = var_eq_non_const(&vardata, operator,
> + clause->inputcollid,
> + other_op, var_on_left,
> + isInequality);
>
> + if (isInequality)
> + individual_s = 1.0 - individual_s - nullfrac;
>
> Isn't this the double negation issue again, which was once
> mentioned/fixed earlier?

Right. I fixed it by using 'invert' for non-constant case. If there is a 
more elegant way to structure this, suggestions are very welcome.


> + int count; /* number of occurrences of current value in */
>
> That's a truncated comment

Fixed.


After the commit c95cd29 I have rebased this patch. During the rebase, I 
also add the NUL-handling path. In particular, I added an Assert(useOr) 
in the relevant branch to document and enforce the expected execution flow.

Additionally after the 374a639 I prepared a set of regression-style 
tests to verify that the selectivity estimates remain unchanged before 
and after applying the patch. However, these tests rely on stable row 
estimates from EXPLAIN, which are not guaranteed to be consistent across 
platforms. For that reason, they are not suitable for inclusion in the 
upstream test suite. I will keep these tests locally to validate 
correctness before and after the patch.


-- 
Best regards,
Ilia Evdokimov,
Tantor Labs LLC,
https://tantorlabs.com/

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Short-circuit row estimation in NOT IN containing NULL consts