У меня есть запрос ниже:
SELECT seq, node, edge, cost as cost, agg_cost, geom, sT_AsGeoJson(geom), replace(
(REPLACE(sT_AsGeoJson(geom),
( select ST_AsGeoJson(geom1) from sample(20.983455,52.231909,20.973400,52.169647) a where seq1 in ( select min(seq1) from sample(20.983455,52.231909,20.973400,52.169647 ))),
(SELECT (St_asgeoJson(ST_LineSubstring((select (geom1) from sample(20.983455,52.231909,20.973400,52.169647) a where seq1 in (select min(seq1) from sample(20.983455,52.231909,20.973400,52.169647 ))),(select ST_LineLocatePoint((select st_astext(geom1) from sample(20.983455,52.231909,20.973400,52.169647) a where seq1 in (select min(seq1) from sample(20.983455,52.231909,20.973400,52.169647 ))), (ST_MakePoint(20.9850904,52.2318352)))),1)))
))),
( select ST_AsGeoJson(geom1) from sample(20.983455,52.231909,20.973400,52.169647) a where seq1 in ( select max(seq1) from sample(20.983455,52.231909,20.973400,52.169647 ))),
(SELECT st_asgeojson((ST_LineSubstring((select (geom1) from sample(20.983455,52.231909,20.973400,52.169647) a where seq1 in (select max(seq1) from sample(20.983455,52.231909,20.973400,52.169647 ))),0,(select ST_LineLocatePoint
((select st_astext(geom1) from sample(20.983455,52.231909,20.973400,52.169647) a where seq1 in (select max(seq1) from sample(20.983455,52.231909,20.973400,52.169647 ))), (ST_MakePoint(20.9741841,52.1691584)))))))
))
FROM pgr_dijkstra
('SELECT id, source, target, st_length(geom, true) as cost FROM roads',
(SELECT source FROM roads ORDER BY ST_Distance( ST_StartPoint(geom), ST_SetSRID(ST_MakePoint(20.983455, 52.231909), 4326), true ) ASC LIMIT 1),
(SELECT target FROM roads ORDER BY ST_Distance( ST_StartPoint(geom), ST_SetSRID(ST_MakePoint(20.973400, 52.169647), 4326), true ) ASC LIMIT 1)) as pt
JOIN roads rd ON pt.edge = rd.id;
Время выполнения запроса составляет 30 секунд.
Есть ли способ сократить время выполнения.