diff --git a/NEWS.md b/NEWS.md index 591db40a52..2777518722 100644 --- a/NEWS.md +++ b/NEWS.md @@ -35,6 +35,7 @@ To see all issues & pull requests closed by this release see the * [#2966](https://github.com/pgRouting/pgrouting/issues/2966): pgr_withPoints does not pick optimal route when fraction = 1 * [#3034](https://github.com/pgRouting/pgrouting/issues/3034): metrics driver should not be using new +* [#3010](https://github.com/pgRouting/pgrouting/issues/3010): Performance issue with pgr_separateTouching() **Code enhancements** diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index 9104cc6b11..64df174ceb 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -65,6 +65,7 @@ To see all issues & pull requests closed by this release see the * :issue:`2966`: pgr_withPoints does not pick optimal route when fraction = 1 * :issue:`3034`: metrics driver should not be using new +* :issue:`3010`: Performance issue with pgr_separateTouching() .. rubric:: Code enhancements diff --git a/docqueries/utilities/separateTouching.result b/docqueries/utilities/separateTouching.result index 84da482e7e..0c2c7f5dbe 100644 --- a/docqueries/utilities/separateTouching.result +++ b/docqueries/utilities/separateTouching.result @@ -22,15 +22,19 @@ FROM pgr_separateTouching('SELECT id, geom FROM edges', dryrun => true); NOTICE: WITH edges_table AS ( - SELECT id, geom FROM edges + SELECT id, geom, + ST_StartPoint(geom) AS startpoint, + ST_EndPoint(geom) AS endpoint + FROM (SELECT id, geom FROM edges) _edges ), get_touching AS ( - SELECT e1.id id1, e2.id id2, ST_Snap(e1.geom, e2.geom, 0.01) AS geom, e1.geom AS g1, e2.geom AS g2 + SELECT e1.id id1, e2.id id2, ST_Snap(e1.geom, e2.geom, 0.01) AS geom, e1.geom AS g1, e2.geom AS g2, + e1.startpoint AS sp1, e1.endpoint AS ep1 FROM edges_table e1, edges_table e2 WHERE e1.id != e2.id AND ST_DWithin(e1.geom, e2.geom, 0.01) AND NOT( - ST_StartPoint(e1.geom) = ST_StartPoint(e2.geom) OR ST_StartPoint(e1.geom) = ST_EndPoint(e2.geom) - OR ST_EndPoint(e1.geom) = ST_StartPoint(e2.geom) OR ST_EndPoint(e1.geom) = ST_EndPoint(e2.geom)) + e1.startpoint = e2.startpoint OR e1.startpoint = e2.endpoint + OR e1.endpoint = e2.startpoint OR e1.endpoint = e2.endpoint) ), touchings AS ( @@ -38,8 +42,8 @@ NOTICE: FROM get_touching WHERE NOT (geom = g1) OR (ST_touches(g1, g2) AND NOT - (ST_Intersection(geom, g2) = ST_StartPoint(g1) - OR ST_Intersection(geom, g2) = ST_EndPoint(g1))) + (ST_Intersection(geom, g2) = sp1 + OR ST_Intersection(geom, g2) = ep1)) ), blades AS ( diff --git a/locale/en/LC_MESSAGES/pgrouting_doc_strings.po b/locale/en/LC_MESSAGES/pgrouting_doc_strings.po index 8edb97b173..0e94406305 100644 --- a/locale/en/LC_MESSAGES/pgrouting_doc_strings.po +++ b/locale/en/LC_MESSAGES/pgrouting_doc_strings.po @@ -15064,6 +15064,11 @@ msgid "" "driver should not be using new" msgstr "" +msgid "" +"`#3010 `__: Performance " +"issue with pgr_separateTouching()" +msgstr "" + msgid "" "`#3044 `__: Check and " "fix assert.hpp for cppcoreguidelines-explicit-virtual-functions" diff --git a/locale/pot/pgrouting_doc_strings.pot b/locale/pot/pgrouting_doc_strings.pot index e4721ccc0b..e62286f0b2 100644 --- a/locale/pot/pgrouting_doc_strings.pot +++ b/locale/pot/pgrouting_doc_strings.pot @@ -12718,6 +12718,9 @@ msgstr "" msgid "`#3034 `__: metrics driver should not be using new" msgstr "" +msgid "`#3010 `__: Performance issue with pgr_separateTouching()" +msgstr "" + msgid "`#3044 `__: Check and fix assert.hpp for cppcoreguidelines-explicit-virtual-functions" msgstr "" diff --git a/sql/utilities/separateTouching.sql b/sql/utilities/separateTouching.sql index 32c0ed6e35..7f1c0c7298 100644 --- a/sql/utilities/separateTouching.sql +++ b/sql/utilities/separateTouching.sql @@ -59,15 +59,19 @@ BEGIN the_query := format($$ WITH edges_table AS ( - %s + SELECT id, geom, + ST_StartPoint(geom) AS startpoint, + ST_EndPoint(geom) AS endpoint + FROM (%s) _edges ), get_touching AS ( - SELECT e1.id id1, e2.id id2, ST_Snap(e1.geom, e2.geom, %2$s) AS geom, e1.geom AS g1, e2.geom AS g2 + SELECT e1.id id1, e2.id id2, ST_Snap(e1.geom, e2.geom, %2$s) AS geom, e1.geom AS g1, e2.geom AS g2, + e1.startpoint AS sp1, e1.endpoint AS ep1 FROM edges_table e1, edges_table e2 WHERE e1.id != e2.id AND ST_DWithin(e1.geom, e2.geom, %2$s) AND NOT( - ST_StartPoint(e1.geom) = ST_StartPoint(e2.geom) OR ST_StartPoint(e1.geom) = ST_EndPoint(e2.geom) - OR ST_EndPoint(e1.geom) = ST_StartPoint(e2.geom) OR ST_EndPoint(e1.geom) = ST_EndPoint(e2.geom)) + e1.startpoint = e2.startpoint OR e1.startpoint = e2.endpoint + OR e1.endpoint = e2.startpoint OR e1.endpoint = e2.endpoint) ), touchings AS ( @@ -75,8 +79,8 @@ BEGIN FROM get_touching WHERE NOT (geom = g1) OR (ST_touches(g1, g2) AND NOT - (ST_Intersection(geom, g2) = ST_StartPoint(g1) - OR ST_Intersection(geom, g2) = ST_EndPoint(g1))) + (ST_Intersection(geom, g2) = sp1 + OR ST_Intersection(geom, g2) = ep1)) ), blades AS (