From ba75d718b0c20d676ddb1d83a26e9e417d7f90c0 Mon Sep 17 00:00:00 2001 From: Mohit242-bit Date: Wed, 25 Feb 2026 11:27:32 +0000 Subject: [PATCH 1/3] Fix #3010: Optimize pgr_separateTouching performance --- docqueries/utilities/separateTouching.result | 16 ++++++++++------ sql/utilities/separateTouching.sql | 16 ++++++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) 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/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 ( From f3fe1e84ce7e6949091881e4bd90547b0a6a9001 Mon Sep 17 00:00:00 2001 From: Mohit242-bit Date: Mon, 2 Mar 2026 03:15:52 +0000 Subject: [PATCH 2/3] Add release notes and news entry for #3010 bug fix --- NEWS.md | 1 + doc/src/release_notes.rst | 1 + 2 files changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index bc2855eb35..0ec205f3b7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -34,6 +34,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 795aa5c0be..cd0dc85093 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -64,6 +64,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 From cade7fd9dbcfd6025fa76b22834e1659b2e4790d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 2 Mar 2026 03:49:30 +0000 Subject: [PATCH 3/3] Update locale: commit f3fe1e84c --- locale/en/LC_MESSAGES/pgrouting_doc_strings.po | 7 ++++++- locale/pot/pgrouting_doc_strings.pot | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/locale/en/LC_MESSAGES/pgrouting_doc_strings.po b/locale/en/LC_MESSAGES/pgrouting_doc_strings.po index e3d55a1fc8..1b21ce93a6 100644 --- a/locale/en/LC_MESSAGES/pgrouting_doc_strings.po +++ b/locale/en/LC_MESSAGES/pgrouting_doc_strings.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: pgRouting v4.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-02-21 01:08+0000\n" +"POT-Creation-Date: 2026-03-02 03:49+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -15059,6 +15059,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 bf3e750913..90dfe7bcf5 100644 --- a/locale/pot/pgrouting_doc_strings.pot +++ b/locale/pot/pgrouting_doc_strings.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: pgRouting v4.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-02-21 01:08+0000\n" +"POT-Creation-Date: 2026-03-02 03:49+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -12715,6 +12715,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 ""