postgresql/contrib
Tom Lane 7d3448961d 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:04:48 +03:00
auth_delay Update copyright for 2026 2026-01-01 13:24:10 -05:00
auto_explain Pre-beta mechanical code beautification, step 2: run pgperltidy. 2026-05-13 10:37:42 -04:00
basebackup_to_shell Update copyright for 2026 2026-01-01 13:24:10 -05:00
basic_archive Fix dereference in a couple of GUC check hooks 2026-03-24 16:45:39 +01:00
bloom Discount the metapage when estimating number of index pages visited. 2026-03-20 14:50:53 -04:00
bool_plperl Update copyright for 2026 2026-01-01 13:24:10 -05:00
btree_gin Use fallthrough attribute instead of comment 2026-02-19 08:51:12 +01:00
btree_gist btree_gist: fix NaN handling in float4/float8 opclasses. 2026-07-01 13:27:22 -04:00
citext Update copyright for 2026 2026-01-01 13:24:10 -05:00
cube Pre-beta mechanical code beautification, step 1: run pgindent. 2026-05-13 10:34:17 -04:00
dblink Run pgperltidy 2026-06-29 15:27:44 -04: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 file_fdw: Add regression test for file_fdw with ON_ERROR='set_null' 2026-03-16 12:13:11 +09:00
fuzzystrmatch Pre-beta mechanical code beautification, step 1: run pgindent. 2026-05-13 10:34:17 -04:00
hstore Reduce header inclusions via execnodes.h 2026-03-16 14:34:57 +01:00
hstore_plperl hstore_plperl: Add CHECK_FOR_INTERRUPTS() in reference-unwinding loop. 2026-06-18 12:23:13 -04:00
hstore_plpython plpython: Fix NULL pointer dereferences for broken sequence and mapping objects 2026-06-29 11:38:39 +09:00
intagg Update copyright for 2026 2026-01-01 13:24:10 -05:00
intarray Fix missed ReleaseVariableStats() in intarray's _int_matchsel(). 2026-05-25 18:15:49 -04:00
isn Pre-beta mechanical code beautification, step 1: run pgindent. 2026-05-13 10:34:17 -04: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:38:39 +09:00
lo Update copyright for 2026 2026-01-01 13:24:10 -05:00
ltree Fix int32 overflow in ltree_compare() 2026-06-16 09:29:47 +03:00
ltree_plpython Change StaticAssertVariableIsOfType to be a declaration 2026-02-03 08:46:02 +01:00
oid2name Fix mismatched deallocation functions 2026-07-01 13:50:08 +02:00
pageinspect Adjust some incorrect *GetDatum() macros 2026-04-30 13:10:19 +09:00
passwordcheck Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_buffercache pg_buffercache: restore rowtype verification in pg_buffercache_pages() 2026-06-10 12:32:59 +09: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 Fix a set of typos and grammar issues across the tree 2026-04-21 14:46:22 +09:00
pg_plan_advice pg_plan_advice: DO_NOT_SCAN is a simple tag, not a generic one. 2026-05-29 13:51:09 -04:00
pg_prewarm Fix out-of-bounds access in autoprewarm worker 2026-06-26 19:47:36 +02:00
pg_stash_advice Fix set of typos and grammar mistakes 2026-06-24 16:00:28 +09:00
pg_stat_statements pg_stat_statements: Set PlannedStmt to NULL after nested utility execution 2026-05-13 15:39:44 +09:00
pg_surgery pg_surgery: Fix off-by-one bug with heap offset 2026-06-06 08:16:36 +09:00
pg_trgm Avoid casting void * function arguments 2026-04-23 08:08:57 +02:00
pg_visibility Revert "Allow logical replication snapshots to be database-specific" 2026-05-23 21:33:19 -07:00
pg_walinspect Report detailed errors from XLogFindNextRecord() failures. 2026-03-24 22:33:09 +09:00
pgcrypto pgcrypto: avoid recursive ResourceOwnerForget(). 2026-06-22 12:59:16 -04:00
pgrowlocks Thread flags through begin-scan APIs 2026-03-30 12:27:24 -04:00
pgstattuple pgstattuple: Optimize pgstattuple_approx() with streaming read 2026-03-14 15:06:13 +09:00
postgres_fdw Make SPI_prepare argtypes argument const 2026-06-30 15:43:56 +02:00
seg Improve the names generated for indexes on expressions. 2026-07-01 11:33:52 -04:00
sepgsql Harmonize function parameter names for Postgres 19. 2026-04-22 12:47:19 -04:00
spi refint: Remove plan cache. 2026-06-05 12:08:05 -05:00
sslinfo Fix compilation with OpenSSL 4 2026-05-29 21:52:35 +02:00
start-scripts Remove gratuitous references to postmaster program 2023-01-26 10:48:32 +01:00
tablefunc Avoid including vacuum.h in tableam.h and heapam.h. 2026-03-31 12:43:52 -05:00
tcn Update copyright for 2026 2026-01-01 13:24:10 -05:00
test_decoding Disallow direct use of the pgrepack logical decoding plugin 2026-06-09 20:12:55 +02:00
tsm_system_rows Update copyright for 2026 2026-01-01 13:24:10 -05:00
tsm_system_time Reduce header inclusions via execnodes.h 2026-03-16 14:34:57 +01:00
unaccent Update Unicode data to Unicode 17.0.0 2026-03-20 08:42:50 +01: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 xml2: Fix crash with namespace nodes in xpath_nodeset() 2026-06-11 14:29:18 +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 Add pg_stash_advice contrib module. 2026-04-06 07:41:28 -04:00
meson.build Add pg_stash_advice contrib module. 2026-04-06 07:41:28 -04: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.