Can this breadth-first search be made faster?

后端 未结 4 2084
野的像风
野的像风 2021-02-09 23:28

I have a data set which is a large unweighted cyclic graph The cycles occur in loops of about 5-6 paths. It consists of about 8000 nodes and each node has from 1-6 (usually abou

4条回答
  •  北海茫月
    2021-02-09 23:58

    Well, given the upvotes on the comment, I'll make it an answer now.

    The SQL in the tight loop is definitely slowing you down. I don't care how fast the call is. Think about it -- you're asking for a query to be parsed, a lookup to be run -- as fast as that is, it's still in a tight loop. What does your data set look like? Can you just SELECT the entire data set into memory, or at least work with it outside of MySQL?

    If you work with that data in memory, you will see a significant performance gain.

提交回复
热议问题