pgRouting性能的问题似乎是新的pgr_astar和pgr_dijkstra使用整个图形(如果有一个图形,则可以保证解决方案)。获得更好性能的简单解决方案是将使用的图形限制为较小的区域。它有自己的问题,例如有时它可能会创建无法解决的图形
(SELECT ST_Expand(ST_Extent(geom_way),0.1) as box FROM hh_2po_4pgr as l1 WHERE l1.source =7 OR l1.target = 12)
在源和目标集合上创建BBOX,并将其扩展0.1度,然后在pgr_查询中使用相同的查询来限制图形大小
Dijkstra从1.2s到〜65ms
SELECT seq, id1 AS node, id2 AS edge, g.geom_way as the_geom
FROM pgr_dijkstra(
'SELECT id, source, target, cost FROM hh_2po_4pgr as r,
(SELECT ST_Expand(ST_Extent(geom_way),0.1) as box FROM hh_2po_4pgr as l1 WHERE l1.source =7 OR l1.target = 12) as box
WHERE r.geom_way && box.box',
7, 12, false, false
) as r INNER JOIN hh_2po_4pgr as g ON r.id2 = g.id ;
A *从2s到〜50ms
SELECT seq, id1 AS node, id2 AS edge, cost
FROM pgr_astar(
'SELECT id, source, target, cost, x1,y1,x2,y2 FROM hh_2po_4pgr as r,
(SELECT ST_Expand(ST_Extent(geom_way),0.1) as box FROM hh_2po_4pgr as l1 WHERE l1.source =7 OR l1.target = 12) as box
WHERE r.geom_way && box.box',
7, 12, false, false
);
osm2po用于将数据(芬兰最新)导入postgis表。将要点索引添加到geom_way列,并为数据库运行全真空分析。共享内存1G。工作存储器512M