Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postgis: select with unbounded extent fails #4079

Open
lightmare opened this issue Aug 18, 2019 · 0 comments · May be fixed by #4089
Open

postgis: select with unbounded extent fails #4079

lightmare opened this issue Aug 18, 2019 · 0 comments · May be fixed by #4089
Assignees
Milestone

Comments

@lightmare
Copy link
Contributor

Apparently we don't have a test for this in core, but python-mapnik has a failing test exhibiting it (select from empty table, for which mapnik cannot guess the extent).

Here's what's going on:

SELECT ST_MakeEnvelope(1.797693134862316e+308, 1.797693134862316e+308,
    -1.797693134862316e+308, -1.797693134862316e+308, 0);

ERROR: "179769313486231600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" is out of range for type double precision

SELECT 1.797693134862316e+308::double precision;

Postgres parses 1.797693134862316e+308 as a numeric (arbitrary precision), and when it tries to pass that to a function accepting double precision, the number falls on the wrong side of [-DBL_MAX, DBL_MAX].

This started being an issue after #3942. That "increase" in precision was ill-informed, back then I didn't realize PostGIS does bbox intersections in single precision (which totally makes sense, storing double precision bboxes in index would be a waste).

The obvious and simple fix would be not putting the intersection test in SQL if query extent is unbounded.

However, I'll need to emit bbox even if unbounded for an upcoming feature, so what I suggest is some magic in constructing the SQL:

  • clamp bbox coordinates to single precision range [-FLT_MAX, FLT_MAX]
  • convert to single precision
  • nudge the values that fell inside the original bbox (making the converted smaller) with nextafter.
  • output either with default precision (6), or as exact hex-float (which Postgres supports by virtue of using strtof); either way force cast to ::real
@lightmare lightmare added this to the v4.0.0 milestone Aug 18, 2019
@lightmare lightmare self-assigned this Aug 18, 2019
@lightmare lightmare added the bug label Aug 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant