postgresql/src/include/utils
Tom Lane 1acf757255 Fix GiST index build for NaN values in geometric types.
GiST index build could go into an infinite loop when presented with boxes
(or points, circles or polygons) containing NaN component values.  This
happened essentially because the code assumed that x == x is true for any
"double" value x; but it's not true for NaNs.  The looping behavior was not
the only problem though: we also attempted to sort the items using simple
double comparisons.  Since NaNs violate the trichotomy law, qsort could
(in principle at least) get arbitrarily confused and mess up the sorting of
ordinary values as well as NaNs.  And we based splitting choices on box size
calculations that could produce NaNs, again resulting in undesirable
behavior.

To fix, replace all comparisons of doubles in this logic with
float8_cmp_internal, which is NaN-aware and is careful to sort NaNs
consistently, higher than any non-NaN.  Also rearrange the box size
calculation to not produce NaNs; instead it should produce an infinity
for a box with NaN on one side and not-NaN on the other.

I don't by any means claim that this solves all problems with NaNs in
geometric values, but it should at least make GiST index insertion work
reliably with such data.  It's likely that the index search side of things
still needs some work, and probably regular geometric operations too.
But with this patch we're laying down a convention for how such cases
ought to behave.

Per bug #14238 from Guang-Dih Lei.  Back-patch to 9.2; the code used before
commit 7f3bd86843 is quite different and doesn't lock up on my simple
test case, nor on the submitter's dataset.

Report: <20160708151747.1426.60150@wrigleys.postgresql.org>
Discussion: <28685.1468246504@sss.pgh.pa.us>
2016-07-14 18:45:59 -04:00
..
.gitignore Avoid maintaining three separate copies of the error codes list. 2011-02-03 22:32:49 -05:00
acl.h pgindent run for 9.6 2016-06-09 18:02:36 -04:00
aclchk_internal.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
array.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
arrayaccess.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
ascii.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
attoptcache.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
builtins.h Fix GiST index build for NaN values in geometric types. 2016-07-14 18:45:59 -04:00
bytea.h Extend sortsupport for text to more opclasses. 2016-02-03 14:29:53 -05:00
cash.h Add casts from int4 and int8 to numeric. 2011-04-05 09:35:43 -04:00
catcache.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
combocid.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
date.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
datetime.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
datum.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
dynahash.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
dynamic_loader.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
elog.h pgindent run for 9.6 2016-06-09 18:02:36 -04:00
evtcache.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
expandeddatum.h Inline the easy cases in MakeExpandedObjectReadOnly(). 2016-06-03 18:34:05 -04:00
fmgrtab.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
formatting.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
geo_decls.h pgindent run for 9.6 2016-06-09 18:02:36 -04:00
guc.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
guc_tables.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
help_config.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
hsearch.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
index_selfuncs.h Restructure index access method API to hide most of it at the C level. 2016-01-17 19:36:59 -05:00
inet.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
int8.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
inval.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
json.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
jsonapi.h pgindent run for 9.6 2016-06-09 18:02:36 -04:00
jsonb.h pgindent run for 9.6 2016-06-09 18:02:36 -04:00
logtape.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
lsyscache.h Improve index AMs' opclass validation procedures. 2016-01-21 19:47:15 -05:00
memdebug.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
memutils.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
nabstime.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
numeric.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
palloc.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_crc.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_locale.h Cope if platform declares mbstowcs_l(), but not locale_t, in <xlocale.h>. 2016-03-15 13:19:57 -04:00
pg_lsn.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_rusage.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
plancache.h pgindent run for 9.6 2016-06-09 18:02:36 -04:00
portal.h Widen query numbers-of-tuples-processed counters to uint64. 2016-03-12 16:05:29 -05:00
ps_status.h Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
rangetypes.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
rel.h Restore foreign-key-aware estimation of join relation sizes. 2016-06-18 15:22:34 -04:00
relcache.h Restore foreign-key-aware estimation of join relation sizes. 2016-06-18 15:22:34 -04:00
relfilenodemap.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
relmapper.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
reltrigger.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
resowner.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
resowner_private.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
rls.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
ruleutils.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
sampling.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
selfuncs.h Support CREATE ACCESS METHOD 2016-03-23 23:01:35 -03:00
snapmgr.h Fix interaction between CREATE INDEX and "snapshot too old". 2016-06-10 09:25:31 -05:00
snapshot.h Add the "snapshot too old" feature 2016-04-08 14:36:30 -05:00
sortsupport.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
spccache.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
syscache.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
timeout.h Be more predictable about reporting "lock timeout" vs "statement timeout". 2016-05-27 10:40:20 -04:00
timestamp.h Add parallel query support functions for assorted aggregates. 2016-04-05 14:32:53 -04:00
tqual.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
tuplesort.h Reuse abbreviated keys in ordered [set] aggregates. 2016-02-17 15:40:00 +05:30
tuplestore.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
typcache.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
tzparser.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
uuid.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
varbit.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
xml.h Update copyright for 2016 2016-01-02 13:33:40 -05:00