postgresql/contrib
Tom Lane 255bce4488 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
..
adminpack tests: Rename conflicting role names 2025-12-12 08:46:15 +09:00
amcheck amcheck: Use correct varlena size accessor in bt_normalize_tuple() 2026-06-14 04:06:43 +03:00
auth_delay Update copyright for 2021 2021-01-02 13:06:25 -05:00
auto_explain Fix EXPLAIN ANALYZE for async-capable nodes. 2021-05-12 14:00:00 +09:00
bloom Count contrib/bloom index scans in pgstat view. 2024-11-12 20:57:37 -05:00
bool_plperl Fix broken ruleutils support for function TRANSFORM clauses. 2021-01-25 13:03:43 -05:00
btree_gin btree_gin: Fix calculation of leftmost interval value. 2023-10-29 11:14:34 +00:00
btree_gist btree_gist: fix NaN handling in float4/float8 opclasses. 2026-07-01 13:27:22 -04:00
citext CREATE INDEX: use the original userid for more ACL checks. 2022-06-25 09:07:44 -07:00
cube Add binary I/O capability for cube datatype. 2021-03-06 12:04:05 -05:00
dblink Avoid resource leaks when a dblink connection fails. 2025-05-29 10:39:55 -04:00
dict_int Update copyright for 2021 2021-01-02 13:06:25 -05:00
dict_xsyn Replace pg_mblen() with bounds-checked versions. 2026-02-09 12:39:01 +13:00
earthdistance Make contrib modules' installation scripts more secure. 2020-08-10 10:44:42 -04:00
file_fdw Fix bogus ctid requirement for dummy-root partitioned targets 2026-01-23 10:23:10 +09:00
fuzzystrmatch Ensure Soundex difference() function handles empty input sanely. 2023-05-16 10:53:42 -04:00
hstore hstore: Fix NULL pointer dereference with receive function 2026-02-17 08:41:37 +09:00
hstore_plperl hstore_plperl: Add CHECK_FOR_INTERRUPTS() in reference-unwinding loop. 2026-06-18 12:22:55 -04:00
hstore_plpython Use plpythonu in plpython tests added by commit 0b7719f74 2026-06-29 14:21:15 +09:00
intagg Make contrib modules' installation scripts more secure. 2020-08-10 10:44:42 -04:00
intarray Fix missed ReleaseVariableStats() in intarray's _int_matchsel(). 2026-05-25 18:15:49 -04:00
isn Update copyright for 2021 2021-01-02 13:06:25 -05:00
jsonb_plperl jsonb_plperl, jsonb_plpython: Fix unguarded recursion and loops. 2026-06-17 11:04:41 -04:00
jsonb_plpython Use plpythonu in plpython tests added by commit 0b7719f74 2026-06-29 14:21:15 +09:00
lo Repair incorrect handling of AfterTriggerSharedData.ats_modifiedcols. 2025-01-22 11:58:20 -05:00
ltree Fix int32 overflow in ltree_compare() 2026-06-16 09:31:23 +03:00
ltree_plpython Improve error messages in ltree_in and lquery_in. 2020-03-31 11:14:42 -04:00
oid2name Add a copyright notice to perl files lacking one. 2021-05-07 10:56:14 -04:00
old_snapshot Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
pageinspect Replace pg_mblen() with bounds-checked versions. 2026-02-09 12:39:01 +13:00
passwordcheck tests: Rename conflicting role names 2025-12-12 08:46:15 +09:00
pg_buffercache Add CHECK_FOR_INTERRUPTS in contrib/pg_buffercache functions. 2025-08-19 12:11:29 -07:00
pg_freespacemap Prevent assertion failure in contrib/pg_freespacemap. 2025-03-27 13:20:23 -04:00
pg_prewarm Fix privilege checks for pg_prewarm() on indexes. 2025-10-17 11:36:50 -05:00
pg_stat_statements Avoid memory leak on error while parsing pg_stat_statements dump file 2026-03-27 12:23:38 +02:00
pg_surgery pg_surgery: Fix off-by-one bug with heap offset 2026-06-06 08:16:46 +09:00
pg_trgm Code coverage for most pg_mblen* calls. 2026-02-09 12:39:16 +13:00
pg_visibility Restore smgrtruncate() prototype in back-branches. 2025-01-08 10:48:01 +13:00
pgcrypto pgcrypto: Tweak error message for incorrect session key length 2026-02-16 12:18:34 +09:00
pgrowlocks Adjust the order of the prechecks in pgrowlocks() 2023-10-31 16:43:28 +13:00
pgstattuple pgstattuple: Improve reports generated for indexes (hash, gist, btree) 2025-10-02 11:09:17 +09:00
postgres_fdw postgres_fdw: Fix handling of abort-cleanup-failed connections. 2026-05-05 18:55:06 +09:00
seg seg: Fix seg_out() to preserve the upper boundary's certainty indicator 2026-06-11 12:34:45 +03:00
sepgsql Adjust sepgsql expected output for 681d9e462 et al. 2023-05-08 11:24:47 -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 contrib/start-scripts/osx/. 2017-11-17 12:53:20 -05:00
tablefunc Update copyright for 2021 2021-01-02 13:06:25 -05:00
tcn Update copyright for 2021 2021-01-02 13:06:25 -05:00
test_decoding Fix re-distributing previously distributed invalidation messages during logical decoding. 2025-06-16 17:35:50 -07:00
tsm_system_rows Update copyright for 2021 2021-01-02 13:06:25 -05:00
tsm_system_time Update copyright for 2021 2021-01-02 13:06:25 -05:00
unaccent Replace pg_mblen() with bounds-checked versions. 2026-02-09 12:39:01 +13:00
uuid-ossp Reject bogus output from uuid_create(3). 2022-09-09 12:41:36 -04:00
vacuumlo Add a copyright notice to perl files lacking one. 2021-05-07 10:56:14 -04:00
xml2 xml2: Fix crash with namespace nodes in xpath_nodeset() 2026-06-11 14:29:29 +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 Introduce --with-ssl={openssl} as a configure option 2021-02-01 19:19:44 +09: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.