Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
230 views
in Technique[技术] by (71.8m points)

aql - retrieve vertices with no linked edge in arangodb

What is the best way to retrieve all vertices that do not have an edge in a related edge_collection

I've tried to use the following code but it's got incredibly slow since arangodb 2.8 (It was not really fast in previous versions but round about 10 times faster as now). It takes more than 30 seconds on collection sizes of around 1000 edges and around 3000 vertices.

FOR v IN vertex_collection  
    FILTER LENGTH( EDGES(edge_collection, v._id, "outbound"))==0
RETURN v._id

...

update

...

After playing around a bit I came to the following query

LET vIDs = (FOR v IN vertex_collection
            RETURN v._id)
LET vEdgesFrom = (FOR e IN edge_collection
                  FILTER e._from IN vIDs
                  RETURN e._from)
FOR v IN vertex_collection
    FILTER v._id IN MINUS(vIDs, vEdgesFrom)
RETURN v._id

This one is much faster (around 0.05s) but still looks like some kind of work around (just thinking of more than one edge collections we need to query against).

So I'm still looking for the best method to find vertices having no edge in specific edge collections.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

My sugestion was going to be similar - rather use joins than graph features.

FOR oneEdge IN edges
LET vertices=(FOR oneVertex IN vertices
        FILTER oneEdge._from == oneVertex._id OR
               oneEdge._to == oneVertex._id
        RETURN 1)
FILTER LENGTH(vertices) < 2
RETURN {v: vertices, e: oneEdge}

to find all edges where one of _from and _to would point into nil, and then subsequently delete it.

Note the RETURN 1 which will reduce the amount of data passed up from the inner query.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...