| From: | ZizhuanLiu X-MAN <44973863(at)qq(dot)com> |
|---|---|
| To: | shihao zhong <zhong950419(at)gmail(dot)com> |
| Cc: | Greg Burd <greg(at)burd(dot)me>, rahul <rahul(at)rhyadav(dot)dev>, pgsql-bugs <pgsql-bugs(at)postgresql(dot)org>, rpsalmi <rpsalmi(at)gmail(dot)com>, pgsql-bugs <pgsql-bugs(at)lists(dot)postgresql(dot)org>, guofenglinux <guofenglinux(at)gmail(dot)com> |
| Subject: | Re: BUG #17545: Incorrect selectivity for IS NOT DISTINCT FROM and NULLs |
| Date: | 2026-11-24 08:05:41 |
| Message-ID: | tencent_ECBEC0CFB5F9D1564C6C7E9758F253E7350A@qq.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
Original
>From: shihao zhong <zhong950419(at)gmail(dot)com>
>Date: 2026-11-24 10:00
>To: ZizhuanLiu X-MAN <44973863(at)qq(dot)com>
>Cc: Greg Burd <greg(at)burd(dot)me>, rahul <rahul(at)rhyadav(dot)dev>, pgsql-bugs <pgsql-bugs(at)postgresql(dot)org>, rpsalmi <rpsalmi(at)gmail(dot)com>, pgsql-bugs <pgsql-bugs(at)lists(dot)postgresql(dot)org>, guofenglinux <guofenglinux(at)gmail(dot)com>
>Subject: Re: BUG #17545: Incorrect selectivity for IS NOT DISTINCT FROM and NULLs
>
>Hi Zizhuan,
>
>Thanks for the patch, and thanks Greg for testing.
>
>In my tests, v3 and v2 give the same IS NOT DISTINCT FROM estimates.
>v3 is better for IS DISTINCT FROM semi and anti joins and for <>.
>
>Could you post those two parts as separate patches on top of v2?
>The <> change can alter existing plans, and the sixth estimator
>argument is a new interface. Both deserve their own review, and
>splitting them lets this small fix go in without waiting.
>
>I'm happy to review them.
>
>Thanks,
>Shihao
Hi Shihao,
Thanks for testing v3 and for offering to review the follow-up patches.
Before splitting the follow-up work, I would like to clarify an architectural
point about where NULL-safe join selectivity should be handled.
In v2, clausesel.c adjusts the result of the ordinary equality estimator for
IS NOT DISTINCT FROM. In v3, the comparison semantics are passed down to
the built-in join estimators, and the correction is performed there. These paths
should not be combined: if the lower estimator returns the NULL-safe result,
the corresponding upper-level correction from v2 must be removed or bypassed.
The v3 implementation started with IS NOT DISTINCT FROM. I first considered
treating NULL as an additional MCV category throughout the equality estimation
helpers, but later simplified that part to calculations similar to v2 while keeping
the correction in eqjoinsel().
Further testing showed that IS DISTINCT FROM and ordinary <> also need
separate handling for SEMI/ANTI joins, and that ordinary <> join selectivity
is wrong when NULLs are present. The SEMI/ANTI implementation reuses
the equality MCV matching and hash logic to identify unequal partners.
Ordinary <> and IS DISTINCT FROM share neqjoinsel() in the current design,
so an additional comparison-mode argument is needed to distinguish their
NULL semantics.
The sixth argument is only a draft interface. Its purpose is to avoid introducing
another catalog-visible estimator while allowing the existing estimator to
distinguish ordinary and NULL-safe comparison. I am open to replacing it with
an internal helper interface or another design.
I am not proposing to block v2. My concern is that v2 and the current v3 approach
assign the IS NOT DISTINCT FROM correction to different layers. If v2 is committed first,
a later lower-level implementation would need to replace or bypass that logic. It would
be useful to get feedback on this boundary before I reorganize the follow-up patches.
If the community prefers the v2 layering, I can follow that design. If the lower-level approach
is preferred, I will rebase the follow-up patches accordingly and refine the interface.
regards,
--
ZizhuanLiu (X-MAN)
44973863(at)qq(dot)com
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Álvaro Herrera | 2026-11-24 08:10:37 | Re: BUG #19932: `repack (concurrently)` does not work in `psql` with `AUTOCOMMIT` set to `off` |
| Previous Message | Philip Hofstetter | 2026-11-24 07:39:03 | Re: BUG #19932: `repack (concurrently)` does not work in `psql` with `AUTOCOMMIT` set to `off` |