postgresql/contrib
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
..
amcheck amcheck: Fix snapshot usage in bt_index_parent_check 2026-01-21 18:55:43 +01:00
auth_delay Update copyright for 2026 2026-01-01 13:24:10 -05:00
auto_explain instrumentation: Keep time fields as instrtime, convert in callers 2026-01-09 13:38:00 -05:00
basebackup_to_shell Update copyright for 2026 2026-01-01 13:24:10 -05:00
basic_archive Update copyright for 2026 2026-01-01 13:24:10 -05:00
bloom Move instrumentation-related structs to instrument_node.h 2026-01-12 16:59:28 +01:00
bool_plperl Update copyright for 2026 2026-01-01 13:24:10 -05:00
btree_gin Update copyright for 2026 2026-01-01 13:24:10 -05:00
btree_gist Replace pg_mblen() with bounds-checked versions. 2026-02-09 12:44:04 +13:00
citext Update copyright for 2026 2026-01-01 13:24:10 -05:00
cube Mark commented out code as unused 2026-01-22 12:44:07 +01:00
dblink Refactor att_align_nominal() to improve performance. 2026-02-02 14:39:50 -05:00
dict_int Update copyright for 2026 2026-01-01 13:24:10 -05:00
dict_xsyn Replace pg_mblen() with bounds-checked versions. 2026-02-09 12:44:04 +13:00
earthdistance Update copyright for 2026 2026-01-01 13:24:10 -05:00
file_fdw Fix bogus ctid requirement for dummy-root partitioned targets 2026-01-23 10:23:30 +09:00
fuzzystrmatch fuzzystrmatch: use pg_ascii_toupper(). 2026-01-12 08:54:04 -08:00
hstore Replace pg_mblen() with bounds-checked versions. 2026-02-09 12:44:04 +13:00
hstore_plperl Change StaticAssertVariableIsOfType to be a declaration 2026-02-03 08:46:02 +01:00
hstore_plpython Change StaticAssertVariableIsOfType to be a declaration 2026-02-03 08:46:02 +01:00
intagg Update copyright for 2026 2026-01-01 13:24:10 -05:00
intarray Harden _int_matchsel() against being attached to the wrong operator. 2026-02-09 10:14:22 -05:00
isn Update copyright for 2026 2026-01-01 13:24:10 -05:00
jsonb_plperl Update copyright for 2026 2026-01-01 13:24:10 -05:00
jsonb_plpython Change StaticAssertVariableIsOfType to be a declaration 2026-02-03 08:46:02 +01:00
lo Update copyright for 2026 2026-01-01 13:24:10 -05:00
ltree Replace pg_mblen() with bounds-checked versions. 2026-02-09 12:44:04 +13:00
ltree_plpython Change StaticAssertVariableIsOfType to be a declaration 2026-02-03 08:46:02 +01:00
oid2name oid2name: Add relation path to the information provided by -x/--extended 2026-02-05 09:02:12 +09:00
pageinspect Replace pg_mblen() with bounds-checked versions. 2026-02-09 12:44:04 +13:00
passwordcheck Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_buffercache pgindent fix for 3fccbd94cb 2026-01-27 00:26:36 +01:00
pg_freespacemap Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_logicalinspect Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_overexplain Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_prewarm bufmgr: Change BufferDesc.state to be a 64-bit atomic 2026-01-15 14:20:41 -05:00
pg_stat_statements pg_stat_statements: Fix test instability with cache-clobbering builds 2026-01-25 19:01:23 +09:00
pg_surgery Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_trgm Code coverage for most pg_mblen* calls. 2026-02-09 12:44:12 +13:00
pg_visibility Fix flakiness in the pg_visibility VM-only vacuum test by using a temporary table. 2026-02-02 17:45:27 -05:00
pg_walinspect Update copyright for 2026 2026-01-01 13:24:10 -05:00
pgcrypto Fix test "NUL byte in text decrypt" for --without-zlib builds. 2026-02-09 09:08:10 -08:00
pgrowlocks Update copyright for 2026 2026-01-01 13:24:10 -05:00
pgstattuple Use relation_close() more consistently in contrib/ 2026-01-06 16:17:59 +09:00
postgres_fdw Optimize IS DISTINCT FROM with non-nullable inputs 2026-02-10 10:17:45 +09:00
seg Mark commented out code as unused 2026-01-22 12:44:07 +01:00
sepgsql Update copyright for 2026 2026-01-01 13:24:10 -05:00
spi Update copyright for 2026 2026-01-01 13:24:10 -05:00
sslinfo Update copyright for 2026 2026-01-01 13:24:10 -05:00
start-scripts Remove gratuitous references to postmaster program 2023-01-26 10:48:32 +01:00
tablefunc Update copyright for 2026 2026-01-01 13:24:10 -05:00
tcn Update copyright for 2026 2026-01-01 13:24:10 -05:00
test_decoding Standardize replication origin naming to use "ReplOrigin". 2026-01-28 11:03:29 -08:00
tsm_system_rows Update copyright for 2026 2026-01-01 13:24:10 -05:00
tsm_system_time Update copyright for 2026 2026-01-01 13:24:10 -05:00
unaccent Replace pg_mblen() with bounds-checked versions. 2026-02-09 12:44:04 +13:00
uuid-ossp Fix accidentally cast away qualifiers 2026-01-26 16:02:31 +01:00
vacuumlo Update copyright for 2026 2026-01-01 13:24:10 -05:00
xml2 Update copyright for 2026 2026-01-01 13:24:10 -05:00
contrib-global.mk Respect TEMP_CONFIG when pg_regress_check and friends are called 2016-02-27 12:28:21 -05:00
Makefile pg_overexplain: Additional EXPLAIN options for debugging. 2025-03-26 13:52:21 -04:00
meson.build Update copyright for 2026 2026-01-01 13:24:10 -05:00
README Rename 'gmake' to 'make' in docs and recommended commands 2014-02-12 17:29:19 -05:00

The PostgreSQL contrib tree
---------------------------

This subtree contains porting tools, analysis utilities, and plug-in
features that are not part of the core PostgreSQL system, mainly
because they address a limited audience or are too experimental to be
part of the main source tree.  This does not preclude their
usefulness.

User documentation for each module appears in the main SGML
documentation.

When building from the source distribution, these modules are not
built automatically, unless you build the "world" target.  You can
also build and install them all by running "make all" and "make
install" in this directory; or to build and install just one selected
module, do the same in that module's subdirectory.

Some directories supply new user-defined functions, operators, or
types.  To make use of one of these modules, after you have installed
the code you need to register the new SQL objects in the database
system by executing a CREATE EXTENSION command.  In a fresh database,
you can simply do

    CREATE EXTENSION module_name;

See the PostgreSQL documentation for more information about this
procedure.