pgsql: Fix GiST index build for NaN values in geometric types.

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Fix GiST index build for NaN values in geometric types.
Дата
Msg-id E1bNpOc-0007XX-05@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
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 7f3bd86843e5aad8 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>

Branch
------
REL9_5_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/50354637694b0040e33f91f354c53227de9df9a6

Modified Files
--------------
src/backend/access/gist/gistproc.c | 151 +++++++++++++++++++++----------------
src/backend/utils/adt/float.c      |   7 +-
src/include/utils/builtins.h       |   2 +
3 files changed, 92 insertions(+), 68 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: pgsql: Fix GiST index build for NaN values in geometric types.
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Fix GiST index build for NaN values in geometric types.