postgresql/src
Tom Lane 2bb20e34c1 Fix float4/float8 hash functions to produce uniform results for NaNs.
The IEEE 754 standard allows a wide variety of bit patterns for NaNs,
of which at least two ("NaN" and "-NaN") are pretty easy to produce
from SQL on most machines.  This is problematic because our btree
comparison functions deem all NaNs to be equal, but our float hash
functions know nothing about NaNs and will happily produce varying
hash codes for them.  That causes unexpected results from queries
that hash a column containing different NaN values.  It could also
produce unexpected lookup failures when using a hash index on a
float column, i.e. "WHERE x = 'NaN'" will not find all the rows
it should.

To fix, special-case NaN in the float hash functions, not too much
unlike the existing special case that forces zero and minus zero
to hash the same.  I arranged for the most vanilla sort of NaN
(that coming from the C99 NAN constant) to still have the same
hash code as before, to reduce the risk to existing hash indexes.

I dithered about whether to back-patch this into stable branches,
but ultimately decided to do so.  It's a clear improvement for
queries that hash internally.  If there is anybody who has -NaN
in a hash index, they'd be well advised to re-index after applying
this patch ... but the misbehavior if they don't will not be much
worse than the misbehavior they had before.

Per bug #17172 from Ma Liangzhu.

Discussion: https://postgr.es/m/17172-7505bea9e04e230f@postgresql.org
2021-09-02 17:24:42 -04:00
..
backend Fix float4/float8 hash functions to produce uniform results for NaNs. 2021-09-02 17:24:42 -04:00
bin In pg_dump, avoid doing per-table queries for RLS policies. 2021-08-31 15:04:05 -04:00
common Replace use of sys_siglist[] with strsignal(). 2020-07-15 22:05:12 -04:00
fe_utils Fix incautious handling of possibly-miscoded strings in client code. 2021-06-07 14:15:25 -04:00
include Avoid creating archive status ".ready" files too early 2021-08-23 15:50:35 -04:00
interfaces Set type identifier on BIO 2021-08-17 14:30:51 +02:00
makefiles Select CFLAGS_SL at configure time, not in platform-specific Makefiles. 2019-10-21 12:32:36 -04:00
pl Fix corner-case uninitialized-variable issues in plpgsql. 2021-07-20 13:01:48 -04:00
port Stamp 10.18. 2021-08-09 16:54:22 -04:00
template Further tweaking of PG_SYSROOT heuristics for macOS. 2021-01-20 12:07:46 -05:00
test Fix the random test failure in 001_rep_changes. 2021-09-01 09:46:03 +05:30
timezone Update time zone data files to tzdata release 2021a. 2021-01-24 16:29:48 -05:00
tools fix syntax error 2021-05-28 09:35:55 -04:00
tutorial tutorial: land height is "elevation", not "altitude" 2021-03-10 20:25:18 -05:00
.gitignore
DEVELOPERS
Makefile Build src/test/isolation during "make" and "make install". 2017-11-22 20:18:52 -08:00
Makefile.global.in Fix prove_installcheck to use correct paths when used with PGXS 2021-07-01 08:48:24 -04:00
Makefile.shlib makefile: use proper linker flags for C++ compiles 2020-03-31 22:26:11 -04:00
nls-global.mk