[PostGIS] #5601: A ST_Intersect row is missed when using JOIN.

PostGIS trac at osgeo.org
Mon Oct 30 19:01:54 PDT 2023


#5601: A ST_Intersect row is missed when using JOIN.
----------------------+---------------------------
 Reporter:  Wenjing   |      Owner:  pramsey
     Type:  defect    |     Status:  new
 Priority:  critical  |  Milestone:  PostGIS 3.5.0
Component:  postgis   |    Version:  3.4.x
 Keywords:            |
----------------------+---------------------------
 Consider there are 3 geometries in table t.

 {{{

 DROP TABLE IF EXISTS t;
 CREATE TABLE t (id int, geom geometry);
 INSERT INTO t (id, geom) VALUES (1,ST_GeomFromText('MULTILINESTRING((-1
 0,1 0))'));
 INSERT INTO t (id, geom) VALUES (2,ST_GeomFromText('LINESTRING(-1 0,0
 0)'));
 INSERT INTO t (id, geom) VALUES
 (3,ST_GeomFromText('GEOMETRYCOLLECTION(MULTIPOINT((-1 0)),LINESTRING(0
 -1,1 0))'));

 }}}

 They intersect each other.

 {{{

 SELECT ST_Intersects(a1.geom, a2.geom), ST_Intersects(a2.geom, a1.geom)
 FROM t As a1, t As a2 WHERE a1.id = 1 and a2.id = 2;
 SELECT ST_Intersects(a1.geom, a2.geom), ST_Intersects(a2.geom, a1.geom)
 FROM t As a1, t As a2 WHERE a1.id = 1 and a2.id = 3;
 SELECT ST_Intersects(a1.geom, a2.geom), ST_Intersects(a2.geom, a1.geom)
 FROM t As a1, t As a2 WHERE a1.id = 2 and a2.id = 3;
 -- result{t, t; t, t; t, t}

 }}}

 But when I query how many geometries intersect, I get the result 5.
 However, the expected result is 6 because all of them intersect each
 other.

 {{{

 SELECT COUNT(*) FROM t As a1 JOIN t As a2 ON ST_Intersects(a1.geom,
 a2.geom)  WHERE a1.id <> a2.id;
 --expected{6}; actual{5}

 }}}
-- 
Ticket URL: <https://trac.osgeo.org/postgis/ticket/5601>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.


More information about the postgis-tickets mailing list