Skip to content

Commit 4fae3d3

Browse files
authored
Merge pull requestfrom Mohit242-bit/fix/separateTouching-performance
Fix #3010: Optimize pgr_separateTouching performance
2 parents 2c6d59a + 1c8d3e6 commit 4fae3d3

6 files changed

Lines changed: 30 additions & 12 deletions

File tree

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ To see all issues & pull requests closed by this release see the
3737

3838
* [#2966](https://github.com/pgRouting/pgrouting/issues/2966): pgr_withPoints does not pick optimal route when fraction = 1
3939
* [#3034](https://github.com/pgRouting/pgrouting/issues/3034): metrics driver should not be using new
40+
* [#3010](https://github.com/pgRouting/pgrouting/issues/3010): Performance issue with pgr_separateTouching()
4041

4142
**Code enhancements**
4243

doc/src/release_notes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ To see all issues & pull requests closed by this release see the
6767

6868
* :issue:`2966`: pgr_withPoints does not pick optimal route when fraction = 1
6969
* :issue:`3034`: metrics driver should not be using new
70+
* :issue:`3010`: Performance issue with pgr_separateTouching()
7071

7172
.. rubric:: Code enhancements
7273

docqueries/utilities/separateTouching.result

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,28 @@ FROM pgr_separateTouching('SELECT id, geom FROM edges', dryrun => true);
2222
NOTICE:
2323
WITH
2424
edges_table AS (
25-
SELECT id, geom FROM edges
25+
SELECT id, geom,
26+
ST_StartPoint(geom) AS startpoint,
27+
ST_EndPoint(geom) AS endpoint
28+
FROM (SELECT id, geom FROM edges) _edges
2629
),
2730

2831
get_touching AS (
29-
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
32+
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,
33+
e1.startpoint AS sp1, e1.endpoint AS ep1
3034
FROM edges_table e1, edges_table e2
3135
WHERE e1.id != e2.id AND ST_DWithin(e1.geom, e2.geom, 0.01) AND NOT(
32-
ST_StartPoint(e1.geom) = ST_StartPoint(e2.geom) OR ST_StartPoint(e1.geom) = ST_EndPoint(e2.geom)
33-
OR ST_EndPoint(e1.geom) = ST_StartPoint(e2.geom) OR ST_EndPoint(e1.geom) = ST_EndPoint(e2.geom))
36+
e1.startpoint = e2.startpoint OR e1.startpoint = e2.endpoint
37+
OR e1.endpoint = e2.startpoint OR e1.endpoint = e2.endpoint)
3438
),
3539

3640
touchings AS (
3741
SELECT id1, g1, g2, st_intersection(geom, g2) AS point
3842
FROM get_touching
3943
WHERE NOT (geom = g1) OR
4044
(ST_touches(g1, g2) AND NOT
41-
(ST_Intersection(geom, g2) = ST_StartPoint(g1)
42-
OR ST_Intersection(geom, g2) = ST_EndPoint(g1)))
45+
(ST_Intersection(geom, g2) = sp1
46+
OR ST_Intersection(geom, g2) = ep1))
4347
),
4448

4549
blades AS (

locale/en/LC_MESSAGES/pgrouting_doc_strings.po

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15069,6 +15069,11 @@ msgid ""
1506915069
"driver should not be using new"
1507015070
msgstr ""
1507115071

15072+
msgid ""
15073+
"`#3010 <https://github.com/pgRouting/pgrouting/issues/3010>`__: Performance "
15074+
"issue with pgr_separateTouching()"
15075+
msgstr ""
15076+
1507215077
msgid ""
1507315078
"`#3044 <https://github.com/pgRouting/pgrouting/issues/3044>`__: Check and "
1507415079
"fix assert.hpp for cppcoreguidelines-explicit-virtual-functions"

locale/pot/pgrouting_doc_strings.pot

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12721,6 +12721,9 @@ msgstr ""
1272112721
msgid "`#3034 <https://github.com/pgRouting/pgrouting/issues/3034>`__: metrics driver should not be using new"
1272212722
msgstr ""
1272312723

12724+
msgid "`#3010 <https://github.com/pgRouting/pgrouting/issues/3010>`__: Performance issue with pgr_separateTouching()"
12725+
msgstr ""
12726+
1272412727
msgid "`#3044 <https://github.com/pgRouting/pgrouting/issues/3044>`__: Check and fix assert.hpp for cppcoreguidelines-explicit-virtual-functions"
1272512728
msgstr ""
1272612729

sql/utilities/separateTouching.sql

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,28 @@ BEGIN
5959
the_query := format($$
6060
WITH
6161
edges_table AS (
62-
%s
62+
SELECT id, geom,
63+
ST_StartPoint(geom) AS startpoint,
64+
ST_EndPoint(geom) AS endpoint
65+
FROM (%s) _edges
6366
),
6467

6568
get_touching AS (
66-
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
69+
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,
70+
e1.startpoint AS sp1, e1.endpoint AS ep1
6771
FROM edges_table e1, edges_table e2
6872
WHERE e1.id != e2.id AND ST_DWithin(e1.geom, e2.geom, %2$s) AND NOT(
69-
ST_StartPoint(e1.geom) = ST_StartPoint(e2.geom) OR ST_StartPoint(e1.geom) = ST_EndPoint(e2.geom)
70-
OR ST_EndPoint(e1.geom) = ST_StartPoint(e2.geom) OR ST_EndPoint(e1.geom) = ST_EndPoint(e2.geom))
73+
e1.startpoint = e2.startpoint OR e1.startpoint = e2.endpoint
74+
OR e1.endpoint = e2.startpoint OR e1.endpoint = e2.endpoint)
7175
),
7276

7377
touchings AS (
7478
SELECT id1, g1, g2, st_intersection(geom, g2) AS point
7579
FROM get_touching
7680
WHERE NOT (geom = g1) OR
7781
(ST_touches(g1, g2) AND NOT
78-
(ST_Intersection(geom, g2) = ST_StartPoint(g1)
79-
OR ST_Intersection(geom, g2) = ST_EndPoint(g1)))
82+
(ST_Intersection(geom, g2) = sp1
83+
OR ST_Intersection(geom, g2) = ep1))
8084
),
8185

8286
blades AS (

0 commit comments

Comments
 (0)