I am querying a postgreSQL DB from my ruby on rails application this way:
var = Map.connection.execute("
SELECT *
FROM shortest_path('SELECT * FROM japan WHERE japan.geom_way && ST_MakeEnvelope(139.68012, 35.63993, 139.71918, 35.66024)', 242945, 582735, false, false)
JOIN japan ON edge_id = id;")
The execution time shown in the rails server console is 327.8 ms.
I execute an identical query from the psql promtp:
SELECT *
FROM shortest_path('SELECT * FROM japan WHERE japan.geom_way && ST_MakeEnvelope(139.68012, 35.63993, 139.71918, 35.66024)', 242945, 582735, false, false)
JOIN japan ON edge_id = id;
The execution time is 53.108 ms.
I thought that some caching could be the reason of the different execution times, but if I try to execute 2 times in a row the same query in the rails application, the execution time for 1 query doesn't change. For instance:
var = Map.connection.execute("SELECT * FROM shortest_path('SELECT * FROM japan WHERE japan.geom_way && ST_MakeEnvelope(139.68012, 35.63993, 139.71918, 35.66024)', 242945, 582735, false, false) JOIN japan ON edge_id = id;")
var = Map.connection.execute("SELECT * FROM shortest_path('SELECT * FROM japan WHERE japan.geom_way && ST_MakeEnvelope(139.68012, 35.63993, 139.71918, 35.66024)', 242945, 582735, false, false) JOIN japan ON edge_id = id;")
gives an execution time of 330.7 ms and 327.8 ms.
Since the 2 queries are identical, shouldn't I expect the same execution time in RoR and in the prompt?
Thanks in advance for any idea.