I have a database of ways and nodes. A way is defined by two or more nodes. The list of node_id’s that a way contains are stored in the way_nodes table.
I have a table of node joins, points where two or more ways join. A join is defined as two or more ways having the same node. I’m looking to find the ways that have joins. So trying something like this:
SELECT DISTINCT
way_id
FROM way_nodes wn
JOIN path_vectors pv ON pv.node_id = wn.node_id
The table path_vectors contains a list of all nodes which are joins between ways, it is precalculated.
I found it was too slow, maybe 5 ways per second, with my large ~10,000 way and ~40,000 node database. This is related to my previous question.
The goal with this information is to simplify road networks into a simple graph, which can be used with a pathfinder to plot an optimal route. I’m using Open Street Map data, hence the similar terminology.
As I understand it, you are trying to build a list of all way_id values from the way_nodes table, where there is a corresponding node_id on the path_vectors table.
If all node_id values are stored on the path_vectors table, this can be simplified to:
If not all node_id values are stored on the path_vectors table, this may be the most efficient way to query the values:
I suggest checking that there is an index on the node_id field on the path_vectors table.