]> granicus.if.org Git - postgis/commitdiff
Reduce array operations in topology.asTopoJSON
authorSandro Santilli <strk@keybit.net>
Mon, 11 Jan 2016 16:21:30 +0000 (16:21 +0000)
committerSandro Santilli <strk@keybit.net>
Mon, 11 Jan 2016 16:21:30 +0000 (16:21 +0000)
Speeds it up by almost 50% in some cases.

git-svn-id: http://svn.osgeo.org/postgis/trunk@14591 b70326c6-7e19-0410-871a-916f4a2858ee

topology/sql/export/TopoJSON.sql.in

index 4d331634eace41284847ed228757d50261568513..dfb45e6d0daaabab84075f5df5794193c00afe1c 100644 (file)
@@ -45,6 +45,7 @@ DECLARE
   old_search_path TEXT;
   all_faces int[];
   faces int[];
+  bounding_edges int[];
   visited_face int;
   shell_faces int[];
   visited_edges int[];
@@ -131,6 +132,13 @@ BEGIN
     looking_for_holes := false;
     shell_faces := ARRAY[]::int[];
 
+    SELECT array_agg(edge_id)
+    FROM edge_data e
+    WHERE
+         ( e.left_face = ANY ( faces ) OR
+           e.right_face = ANY ( faces ) )
+    INTO bounding_edges;
+
     LOOP -- {
 
       arcs := NULL;
@@ -148,14 +156,11 @@ _edges AS (
          e.left_face = ANY ( faces ) as lf,
          e.right_face = ANY ( faces ) as rf
   FROM edge e
-  WHERE ( e.left_face = ANY ( faces ) OR
-          e.right_face = ANY ( faces ) )
+  WHERE edge_id = ANY (bounding_edges)
+          AND NOT e.edge_id = ANY ( visited_edges )
 ),
 _leftmost_non_dangling_edge AS (
-  SELECT * FROM _edges e
-    WHERE ( e.lf or e.rf ) AND ( e.lf != e.rf )
-          AND NOT e.edge_id = ANY ( visited_edges )
-      -- TODO: and not in visited ?
+  SELECT e.* FROM _edges e WHERE e.lf != e.rf
   ORDER BY geom LIMIT 1
 ),
 _edgepath AS (