postgresql/src/backend
Tom Lane ce773f230d 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:41 -04:00
..
access Fix float4/float8 hash functions to produce uniform results for NaNs. 2021-09-02 17:24:41 -04:00
bootstrap Fix bogus assertion in BootstrapModeMain(). 2021-08-09 08:28:53 -07:00
catalog Fix lookup error in extended stats ownership check 2021-08-31 18:33:38 +02:00
commands Identify simple column references in extended statistics 2021-09-01 17:41:56 +02:00
executor Improve error messages about misuse of SELECT INTO. 2021-08-21 10:22:14 -04:00
foreign Update copyright for 2021 2021-01-02 13:06:25 -05:00
jit Clarify some comments making use of leetspeak term "up2date" 2021-07-28 10:31:24 +09:00
lib Fix typo in comment 2021-04-20 14:35:16 +02:00
libpq Set type identifier on BIO 2021-08-17 14:30:01 +02:00
main process startup: Centralize pgwin32_signal_initialize() calls. 2021-08-05 12:36:06 -07:00
nodes Check the size in COPY_POINTER_FIELD 2021-08-08 18:46:34 +02:00
optimizer Fix missed lock acquisition while inlining new-style SQL functions. 2021-08-31 12:02:36 -04:00
parser Avoid using ambiguous word "positive" in error message. 2021-08-25 11:46:25 +09:00
partitioning Allow ordered partition scans in more cases 2021-08-03 12:25:52 +12:00
po Translation updates 2021-06-21 12:33:50 +02:00
port Make EXEC_BACKEND more convenient on macOS. 2021-08-13 11:09:00 +12:00
postmaster Enhance pg_stat_reset_single_table_counters function. 2021-09-02 14:01:06 +09:00
regex Doc: add a little about LACON execution to src/backend/regex/README. 2021-08-29 12:48:49 -04:00
replication Optimize fileset usage in apply worker. 2021-09-02 08:13:46 +05:30
rewrite Use l*_node() family of functions where appropriate 2021-07-19 08:20:24 +02:00
snowball Update snowball 2021-02-19 08:10:15 +01:00
statistics Error message refactoring 2021-06-27 09:41:16 +02:00
storage Optimize fileset usage in apply worker. 2021-09-02 08:13:46 +05:30
tcop process startup: Always call Init[Auxiliary]Process() before BaseInit(). 2021-08-05 15:36:59 -07:00
tsearch Improve various places that double the size of a buffer 2021-07-01 15:29:06 +12:00
utils Optimize fileset usage in apply worker. 2021-09-02 08:13:46 +05:30
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
Makefile Use sort_template.h for qsort_tuple() and qsort_ssup(). 2021-03-03 17:02:32 +13:00
nls.mk Translation updates 2021-05-10 14:36:21 +02:00