postgresql/contrib
Tom Lane 1e1d07792e btree_gist: fix NaN handling in float4/float8 opclasses.
The float4 and float8 btree_gist opclasses compared keys with raw C
operators (==, <, >).  IEEE 754 makes every comparison involving NaN
false, so GiST disagreed with the regular float comparison operators
and with the btree opclass, which uses float[4|8]_cmp_internal()
(so that all NaNs are equal and NaN sorts after every non-NaN value).

In addition, the penalty and distance functions were not careful
about NaNs, and the penalty functions could also misbehave for IEEE
infinities.  Wrong answers from the penalty functions would probably
do no more than make the index non-optimal, but the distance mistakes
were visible from SQL.

To fix, make the comparison functions rely on the same NaN-aware
comparison functions the core code uses, and rewrite the penalty
and distance functions to follow the rules that NaNs are equal
but maximally far away from non-NaNs.  The penalty_num() code was
formerly shared between integral and float cases, but I chose to make
two copies so that the integral cases are not saddled with the extra
logic for NaNs and infinities/overflows.  I also rewrote it as static
inline functions instead of an unreadable and uncommented macro.

The float penalty functions were previously unreached by the
regression tests, so add new test cases to exercise them.

There's no on-disk format change, but users who have NaN entries
in a btree_gist index would be well advised to reindex it.

Bug: #19501
Bug: #19524
Reported-by: Man Zeng <zengman@halodbtech.com>
Reported-by: Yuelin Wang <3020001251@tju.edu.cn>
Author: Bill Kim <billkimjh@gmail.com>
Co-authored-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/19501-3bff3bbc97f1e7c9@postgresql.org
Discussion: https://postgr.es/m/19524-9559d302c8455664@postgresql.org
Discussion: https://postgr.es/m/CAMQXxcgbtD2LXfX0tpgvOizxP-XxrCHV2ZDy4By_TZnJMsxXWQ@mail.gmail.com
Backpatch-through: 14
2026-07-01 13:27:22 -04:00
..
amcheck amcheck: Use correct varlena size accessor in bt_normalize_tuple() 2026-06-14 04:05:50 +03:00
auth_delay Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
auto_explain Allow resetting unknown custom GUCs with reserved prefixes. 2025-08-01 16:52:11 -05:00
basebackup_to_shell Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
basic_archive basic_archive: Allow archive directory to be missing at startup. 2026-03-02 13:12:25 -06:00
bloom Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
bool_plperl Fix erroneous construction of functions' dependencies on transforms. 2025-04-07 13:31:37 -04:00
btree_gin Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
btree_gist btree_gist: fix NaN handling in float4/float8 opclasses. 2026-07-01 13:27:22 -04:00
citext Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
cube Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
dblink postgres_fdw, dblink: Validate use_scram_passthrough values 2026-05-28 20:58:45 +09:00
dict_int Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
dict_xsyn Replace pg_mblen() with bounds-checked versions. 2026-02-09 12:43:42 +13:00
earthdistance Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
file_fdw Fix bogus ctid requirement for dummy-root partitioned targets 2026-01-23 10:23:26 +09:00
fuzzystrmatch Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
hstore hstore: Fix NULL pointer dereference with receive function 2026-02-17 08:41:30 +09:00
hstore_plperl hstore_plperl: Add CHECK_FOR_INTERRUPTS() in reference-unwinding loop. 2026-06-18 12:22:55 -04:00
hstore_plpython plpython: Fix NULL pointer dereferences for broken sequence and mapping objects 2026-06-29 11:39:50 +09:00
intagg Update copyright for 2025 2025-01-01 11:21:55 -05:00
intarray Fix missed ReleaseVariableStats() in intarray's _int_matchsel(). 2026-05-25 18:15:49 -04:00
isn Revert a few small patches that were intended for version 19. 2025-06-11 15:10:12 -07:00
jsonb_plperl jsonb_plperl, jsonb_plpython: Fix unguarded recursion and loops. 2026-06-17 11:04:41 -04:00
jsonb_plpython plpython: Fix NULL pointer dereferences for broken sequence and mapping objects 2026-06-29 11:39:50 +09:00
lo Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
ltree Fix int32 overflow in ltree_compare() 2026-06-16 09:31:08 +03:00
ltree_plpython Remove circular #include's between plpython.h and plpy_util.h. 2025-04-27 11:43:02 -04:00
oid2name Update copyright for 2025 2025-01-01 11:21:55 -05:00
pageinspect Replace pg_mblen() with bounds-checked versions. 2026-02-09 12:43:42 +13:00
passwordcheck Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
pg_buffercache pgindent fix for 3fccbd94cb 2026-01-27 00:28:01 +01:00
pg_freespacemap Prevent assertion failure in contrib/pg_freespacemap. 2025-03-27 13:20:23 -04:00
pg_logicalinspect Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
pg_overexplain Fix pg_overexplain to emit valid output with RANGE_TABLE option. 2026-04-16 13:49:39 +09:00
pg_prewarm Fix out-of-bounds access in autoprewarm worker 2026-06-26 19:48:20 +02:00
pg_stat_statements Avoid memory leak on error while parsing pg_stat_statements dump file 2026-03-27 12:21:29 +02:00
pg_surgery pg_surgery: Fix off-by-one bug with heap offset 2026-06-06 08:16:40 +09:00
pg_trgm Fix expanding 'bounds' in pg_trgm's calc_word_similarity() function 2026-02-20 11:56:50 +02:00
pg_visibility read_stream: Introduce and use optional batchmode support 2025-03-30 18:36:41 -04:00
pg_walinspect Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
pgcrypto pgcrypto: avoid recursive ResourceOwnerForget(). 2026-06-22 12:59:16 -04:00
pgrowlocks Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
pgstattuple pgstattuple: Improve reports generated for indexes (hash, gist, btree) 2025-10-02 11:09:10 +09:00
postgres_fdw Re-index ModifyTable FDW arrays when pruning result relations 2026-06-23 21:08:50 +09:00
seg seg: Fix seg_out() to preserve the upper boundary's certainty indicator 2026-06-11 12:34:26 +03:00
sepgsql Update expected output for contrib/sepgsql's regression tests. 2025-10-23 17:47:10 -04:00
spi refint: Remove plan cache. 2026-06-05 12:08:05 -05:00
sslinfo Fix compilation with OpenSSL 4 2026-06-12 13:57:22 +02:00
start-scripts Remove gratuitous references to postmaster program 2023-01-26 10:48:32 +01:00
tablefunc Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
tcn Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
test_decoding Fix re-distributing previously distributed invalidation messages during logical decoding. 2025-06-16 17:36:01 -07:00
tsm_system_rows Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
tsm_system_time Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
unaccent Replace pg_mblen() with bounds-checked versions. 2026-02-09 12:43:42 +13:00
uuid-ossp Use PG_MODULE_MAGIC_EXT in our installable shared libraries. 2025-03-26 11:11:02 -04:00
vacuumlo Update copyright for 2025 2025-01-01 11:21:55 -05:00
xml2 xml2: Fix crash with namespace nodes in xpath_nodeset() 2026-06-11 14:29:22 +09: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 pg_overexplain: Additional EXPLAIN options for debugging. 2025-03-26 13:52:21 -04:00
README

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.