postgresql/src
Richard Guo 0a37961254 Optimize IS DISTINCT FROM with non-nullable inputs
The IS DISTINCT FROM construct compares values acting as though NULL
were a normal data value, rather than "unknown".  Semantically, "x IS
DISTINCT FROM y" yields true if the values differ or if exactly one is
NULL, and false if they are equal or both NULL.  Unlike ordinary
comparison operators, it never returns NULL.

Previously, the planner only simplified this construct if all inputs
were constants, folding it to a constant boolean result.  This patch
extends the optimization to cases where inputs are non-constant but
proven to be non-nullable.  Specifically, "x IS DISTINCT FROM NULL"
folds to constant TRUE if "x" is known to be non-nullable.  For cases
where both inputs are guaranteed not to be NULL, the expression
becomes semantically equivalent to "x <> y", and the DistinctExpr is
converted into an inequality OpExpr.

This transformation provides several benefits.  It converts the
comparison into a standard operator, allowing the use of partial
indexes and constraint exclusion.  Furthermore, if the clause is
negated (i.e., "IS NOT DISTINCT FROM"), it simplifies to an equality
operator.  This enables the planner to generate better plans using
index scans, merge joins, hash joins, and EC-based qual deduction.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Tender Wang <tndrwang@gmail.com>
Discussion: https://postgr.es/m/CAMbWs49BMAOWvkdSHxpUDnniqJcEcGq3_8dd_5wTR4xrQY8urA@mail.gmail.com
2026-02-10 10:17:45 +09:00
..
backend Optimize IS DISTINCT FROM with non-nullable inputs 2026-02-10 10:17:45 +09:00
bin pg_upgrade: Fix handling of pg_largeobject_metadata. 2026-02-09 14:58:02 -06:00
common Fix mb2wchar functions on short input. 2026-02-09 12:08:58 +13:00
fe_utils Force standard_conforming_strings to always be ON. 2026-01-21 15:08:38 -05:00
include Remove HeapTupleheaderSetXminCommitted/Invalid functions 2026-02-09 19:15:20 +01:00
interfaces libpq: Prepare for protocol grease during 19beta 2026-02-06 10:31:45 -08:00
makefiles tests: Add a test C++ extension module 2026-01-20 16:42:30 +01:00
pl Refactor att_align_nominal() to improve performance. 2026-02-02 14:39:50 -05:00
port Fix accidentally cast away qualifiers 2026-01-26 16:02:31 +01:00
template Remove traces of support for Sun Studio compiler 2025-09-12 07:39:05 +02:00
test Optimize IS DISTINCT FROM with non-nullable inputs 2026-02-10 10:17:45 +09:00
timezone Update time zone data files to tzdata release 2025c. 2026-01-18 14:54:33 -05:00
tools Harden _int_matchsel() against being attached to the wrong operator. 2026-02-09 10:14:22 -05:00
tutorial Force standard_conforming_strings to always be ON. 2026-01-21 15:08:38 -05:00
.gitignore
DEVELOPERS
Makefile Remove distprep 2023-11-06 15:18:04 +01:00
Makefile.global.in tests: Add a test C++ extension module 2026-01-20 16:42:30 +01:00
Makefile.shlib Use exported symbols list on macOS for loadable modules as well 2025-06-10 07:04:43 +02:00
meson.build Update copyright for 2026 2026-01-01 13:24:10 -05:00
nls-global.mk Fix update-po for the PGXS case 2025-10-16 20:21:05 +02:00