Fix some corner cases that cube_in rejects

Started by Tom Laneover 9 years ago5 messageshackers
Jump to latest
#1Tom Lane
tgl@sss.pgh.pa.us

In bug #14300 it's pointed out that cube_in rejects zero-element
cubes, as well as infinity and NaN coordinate values. Since it's
easy to make such cube values via the cube-from-float-array
constructors, this is a dump/reload hazard. The attached proposed
patch attempts to fix it up.

To deal with the infinity/NaN issues, I made cube_in and cube_out rely
on float8in_internal and float8out_internal, as we recently did for the
core geometric types. That causes the response to "1e-700" to be an
out-of-range error rather than silent underflow, which seems to me to
be fine, especially since it removes the platform dependency that's
responsible for needing the separate cube_1.out and cube_3.out files.

I also took the opportunity to make cube_in's error strings and ERRCODE
results match project convention. This is maybe a bit more debatable,
but I think it's worth doing as long as we're touching the function's
behavior.

I found only one other place that seemed to be assuming that cubes
aren't zero-length, but it would be worth someone reviewing it again
to see if I missed anything. I'll put this on the commitfest queue.

regards, tom lane

Attachments:

fix-cube-for-empty-inf-and-nan-1.patchtext/x-diff; charset=us-ascii; name=fix-cube-for-empty-inf-and-nan-1.patchDownload+403-3792
#2Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#1)
Re: Fix some corner cases that cube_in rejects

On Mon, Aug 29, 2016 at 7:19 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

To deal with the infinity/NaN issues, I made cube_in and cube_out rely
on float8in_internal and float8out_internal, as we recently did for the
core geometric types. That causes the response to "1e-700" to be an
out-of-range error rather than silent underflow, which seems to me to
be fine, especially since it removes the platform dependency that's
responsible for needing the separate cube_1.out and cube_3.out files.

So what happens to a database that has invalid cubes in it already?
Offhand I suspect they mostly become valid since float8in will handle
NaN and the like.

Incidentally, I so wish this module were named "vector" instead of
cube. I don't think I was confused by it for ages and still find it
confuses me for a few moments before I remember what it does.

--
greg

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#2)
Re: Fix some corner cases that cube_in rejects

Greg Stark <stark@mit.edu> writes:

On Mon, Aug 29, 2016 at 7:19 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

To deal with the infinity/NaN issues, I made cube_in and cube_out rely
on float8in_internal and float8out_internal, as we recently did for the
core geometric types. That causes the response to "1e-700" to be an
out-of-range error rather than silent underflow, which seems to me to
be fine, especially since it removes the platform dependency that's
responsible for needing the separate cube_1.out and cube_3.out files.

So what happens to a database that has invalid cubes in it already?
Offhand I suspect they mostly become valid since float8in will handle
NaN and the like.

Nothing really. cube_out works fine. The point of substituting
float8out_internal is mostly to make sure we get platform-independent
spellings for inf and nan.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#4Amul Sul
sulamul@gmail.com
In reply to: Tom Lane (#3)
Re: Fix some corner cases that cube_in rejects

The following review has been posted through the commitfest application:
make installcheck-world: tested, passed
Implements feature: tested, passed
Spec compliant: tested, passed
Documentation: not tested

Note for committer : There are unnecessary files (cube_1.out, cube_2.out & cube_3.out) in contrib directory, that need to be removed at code checkin, other than this concern, I think this patch looks pretty reasonable. Thanks.

Regards,
Amul

The new status of this patch is: Ready for Committer

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Amul Sul (#4)
Re: Fix some corner cases that cube_in rejects

Amul Sul <sulamul@gmail.com> writes:

The following review has been posted through the commitfest application:
make installcheck-world: tested, passed
Implements feature: tested, passed
Spec compliant: tested, passed
Documentation: not tested

Note for committer : There are unnecessary files (cube_1.out, cube_2.out & cube_3.out) in contrib directory, that need to be removed at code checkin, other than this concern, I think this patch looks pretty reasonable. Thanks.

Thanks for the review --- pushed.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers