Opened 9 years ago

Closed 9 years ago

#3484 closed defect (wontfix)

IS DISTINCT FROM not seeing additional points

Reported by: pvalsecc Owned by: pramsey
Priority: medium Milestone: PostGIS 2.2.3
Component: postgis Version: 2.2.x
Keywords: Cc: patrick.valsecchi@…

Description

This result is wrong:

SELECT
ST_GeomFromText('MULTIPOLYGON(((2494153.5178082585 1118531.569023041, 2494549.8246264406 1118753.159932132, 2494600.960990077 1118817.0803866775, 2494153.5178082585 1118531.569023041)))',2056) 
is distinct from
ST_GeomFromText('MULTIPOLYGON(((2494153.5178082585 1118531.569023041, 2494527.2564446223 1118796.7735684956, 2494549.8246264406 1118753.159932132, 2494600.960990077 1118817.0803866775, 2494153.5178082585 1118531.569023041)))',2056);
?column? 
----------
 f

As you can see the second geometry as one more point.

What's strange is that this error doesn't happen in 4326:

# SELECT
ST_GeomFromText('MULTIPOLYGON(((-71.1031880899493 42.3152774590236, -71.1031627617667 42.3152960829043, -71.1038734225584 42.3151140942995, -71.1031880899493 42.3152774590236)))',4326) 
is distinct from
ST_GeomFromText('MULTIPOLYGON(((-71.1031880899493 42.3152774590236, -71 42, -71.1031627617667 42.3152960829043, -71.1038734225584 42.3151140942995, -71.1031880899493 42.3152774590236)))',4326);
 ?column? 
----------
 t

Change History (8)

comment:1 by strk, 9 years ago

I guess "IS DISTINCT FROM" uses the btree index, which is based on bounding box (2d, float) comparison. Do you confirm it makes sense when casting those geometries to BOX2D ?

comment:2 by pvalsecc, 9 years ago

In my 2056 example, one geometry was not valid. But the problem appears as well with valid geometries:

# select ST_GeomFromText('MULTIPOLYGON(((2494153.5178082585 1118531.569023041, 2494549.8246264406 1118753.159932132, 2494600.960990077 1118817.0803866775, 2494153.5178082585 1118531.569023041)))',2056)
is distinct from
       ST_GeomFromText('MULTIPOLYGON(((2494153.5178082585 1118531.569023041, 2494500 1118600, 2494549.8246264406 1118753.159932132, 2494600.960990077 1118817.0803866775, 2494153.5178082585 1118531.569023041)))',2056);
 ?column? 
----------
 f

in reply to:  1 comment:3 by pvalsecc, 9 years ago

Replying to strk:

I guess "IS DISTINCT FROM" uses the btree index, which is based on bounding box (2d, float) comparison. Do you confirm it makes sense when casting those geometries to BOX2D ?

I don't understand. My example is not using an index. And that would be wrong to only compare bounding boxes! Postgres documentation for "IS DISTINCT FROM" says:

For non-null inputs, IS DISTINCT FROM is the same as the <> operator.

For the context, I was using that in a "on update" trigger to check if a row is really modified before updating the modified column. My trigger was missing modifications.

[1] http://www.postgresql.org/docs/9.1/static/functions-comparison.html

comment:4 by pvalsecc, 9 years ago

Cc: patrick.valsecchi@… added

comment:5 by strk, 9 years ago

Right, same as ≠ which is probably implemented using the operators in the btree opclass, like < and > and order by.

comment:6 by pramsey, 9 years ago

DISTINCT ON, GROUP BY, DISTINCT FROM keywords all delegate to operators from the btree opclass, which since time immemorial in PostGIS geometry have been backed by single precision bounding boxes. I'm afraid this is not fixable nor are the many other reports we've had over the years on this issue. Workaroud: use NOT ST_Equals(a, b)

comment:7 by pramsey, 9 years ago

Milestone: PostGIS 2.2.2PostGIS 2.2.3

comment:8 by pramsey, 9 years ago

Resolution: wontfix
Status: newclosed
Note: See TracTickets for help on using tickets.