[postgis-tickets] r14591 - Reduce array operations in topology.asTopoJSON
Sandro Santilli
strk at keybit.net
Mon Jan 11 08:21:30 PST 2016
Author: strk
Date: 2016-01-11 08:21:30 -0800 (Mon, 11 Jan 2016)
New Revision: 14591
Modified:
trunk/topology/sql/export/TopoJSON.sql.in
Log:
Reduce array operations in topology.asTopoJSON
Speeds it up by almost 50% in some cases.
Modified: trunk/topology/sql/export/TopoJSON.sql.in
===================================================================
--- trunk/topology/sql/export/TopoJSON.sql.in 2016-01-11 14:30:08 UTC (rev 14590)
+++ trunk/topology/sql/export/TopoJSON.sql.in 2016-01-11 16:21:30 UTC (rev 14591)
@@ -45,6 +45,7 @@
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 @@
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 @@
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 (
More information about the postgis-tickets
mailing list