In the spirit of giving back to the community, I am sharing a problem and 
solution that I just discovered in working with OrientDB.

For my application, I need to be able to *very* quickly determine how many 
(zero or more, often, but not always zero or one) edges with a given label 
and direction exist between two vertices.

The pure Java solution is OrientVertex.getEdges(otherVertex, direction, 
labels ...) but it returns an OMultiCollectionIterable of *all* the edges 
adjacent to the first vertex that match the label and direction criteria. 
Then it post-filters them for adjacency to the second vertex. This can be 
very slow if the first vertex has many edges that match the label and 
direction criteria.

As an alternative, if you only need the count (like I do) and need it to be 
as fast as possible, consider a SQL query like the following:

SELECT IN('myLabel')[@rid=:vertex2].SIZE() FROM :vertex1

Replace the IN function with BOTH or OUT as needed. The fragment above uses 
parameterized SQL, with the :vertex1 and :vertex2 parameters specifying the 
vertices of interest.

OrientDB team: Should I add to this to the "query cookbook" in the 
documentation?

-- John

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to