I built a tree in orientdb with a high amount of nodes and edges in bottom up direction. I would like to receive all leaves of that tree (each leaf has the @class LEAF) which match a certain range condition (e.g. val > 150 and val < 300):
o / \ o o / / \ o o o 210 120 /\ 270 180
Result: 210, 180, 270
What I tried so far is to use the following query:
SELECT FROM(TRAVERSE IN() FROM <root>) WHERE value > 150 and value < 300
This is working well with a few elements but the performance drops with increasing amount of leafs. So my questions are:
- Is this the most efficient way to do this in OrientDB, especially if I have let’s say 300000 leaves under each node ?
- I know from the documentation, that using an index can help to improve the performance on range queries, but would the index be used in this case? My first assumption is no because orient is first traversing and then filtering the the traversed elements. An explain in orient studio gives me:
:+ FETCH FROM SUBQUERY + FETCH FROM RIDs [#123:123] + DEPTH-FIRST TRAVERSE [IN()] + FILTER ITEMS WHERE value > 150 AND value < 300
- bonus question: what I really want is to query the last leaf for each node. Before I executed the query for each single node which was way slower than executing one single query. But still the performance is not really good and I wonder if there is way to do this in orient db.
Thanks and Regards