简体   繁体   中英

Why this Arangodb query max depth is not correct

I have a normal node-link graph

For the purpose of getting all links, I want to get the node which is related on x max depth. But the query below returned incorrect result (64 out of 81). But the max depth between them is just like 7. Where did I go wrong?

FOR v IN 0..14 ANY "Entity/41591987" EntityRelation 
OPTIONS {uniqueVertices: "global"} return v

Edit 1: Adding the option of bfs: true seemed to solve the problem, but I do not understand why.


Edit 2: My full query is

   //get all the vertices related to this one id
    FOR v IN 0..9 ANY "EntityProd/58868489" EntityRelationProd 
    OPTIONS  {uniqueVertices: "global",bfs:true}
    //from each of above results, get the incoming and outgoing edges
    FOR vv, c IN ANY v EntityRelationProd RETURN c

The point is that I already got the correct results to get all vertices. Why would the "uniqueVertices: global" affect my second part? Or do I have to re-specify the OPTIONS?

I think the issue is OPTIONS {uniqueVertices: "global"} . This enforces that every vertex is visited at most once. So if there are two paths to a vertex of difference length only one of them will be traversed, the other is excluded. Without bfs: true the result of uniqueVertices: 'global' is not deterministic.

Let me illustrate it with the following example. We have 6 vertices in Alphabetical connection:

(A) -> (B) -> (C) -> (D) -> (E) -> (F)

And than we have another vertex X adding a shortcut:

(A) -> (X) -> (D)

Now let's execute the Traversal above with depth 1..3 starting at (A) . At A we have two options, either pick B or X first. Let's pick X Then we return X, D, E for this sub-graph. Than we go back to A and pick the other option. There we have B, C . We do not return D as it was already visited. So in this case we have: X, D, E, B, C as a result.

If we pick the other option at A the result would be different. First we find B, C, D , which is still in line with the other choice. But then trouble begins if we continue to search in X . There we pick X and look at D . Unfortunately D was already returned, so we stop here. Hence the result is: B, C, D, X and no E .

If you use bfs: true all paths are analyzed in ascending depth. So there cannot be any shorter way to any vertex that would run into the trouble we get in the example above. Here the result is deterministic and well-defined.

However you were talking about all links between your entities. Note here if you say: uniqueVertices: 'global' there will at most be ONE edge pointing to any of your entities returned (also picked based on the traversal ordering). If you want to have all edges between your entities you probably want to go without the uniqueVertex option.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM