Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I tried to find a route using shortest_path function of pgrouting, and it took to the server (postgres) a lot time to process my query (more then 5 minutes!) even I have only 10 rows in my table.

After playing with my table I found out that the IDs of source & target must be short (up to 6-7 digits) in order to get the query results fast. But these IDs I get them from the map so I don't want to change them.

For Example, this is the table:

id   source     target   cost
--   -------    -------  -----
1    123456     2        1
2    3          2        2
3    3          4        3
4    4          5        4
5    5          6        3.3

This query takes ~30ms:

SELECT * FROM shortest_path('SELECT * FROM temp_table_2',123456, 3, false, false);

But the same query when I change the source 123456 to 1234567 I get the result after ~400ms! (and of course, If I try to increase the source to 12345678 it will take more than few seconds...)

How can I use pgrouting to get the shortest path (and not just wait...) from my table?

Thanks!

share|improve this question

1 Answer 1

up vote 1 down vote accepted

The shortest path functions of pgRouting require that source and target ID have the type INTEGER. (see http://www.pgrouting.org/docs/1.x/dijkstra.html)

Also it's recommended to renumber your source and target ID, that they start from 1. You can keep your original ID as a reference stored in a different attribute, but for the algorithm it's bad to have high numbers and "big wholes".

Furthermore check that you have indices on source and target column and that you run vacuum.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.