I'm developing a Java application where I have to implement Shortest path algorithm (dijkstra's).

I've stored the details of nodes in database.

But my problem is that the number of nodes is very large (1000+) and taking all the nodes into consideration will increase the time and space consumption of the application.

Also taking such large number of nodes into consideration will be inefficient as many nodes will be irrelevant in finding the shortest path.

Hence, I'm looking for a solution this problem.

I don't want the code, I just want the idea/method to solve it.

So, please suggest me some method.