Why does a subsequent "has" step, make a Gremlin query significantly slower?

Viewed 52

I am trying to understand understand how gremlin queries work, especially when it comes to "AND" like queries.

When I execute the following query, it produces results in approximately 17 seconds.

g.V().has(id, gte(51200)).has(id, lte(51200000)).count().profile()

However, if I append another has statement to this such as the following, it doesn't even finish evaluating in 5 minutes.

g.V().has(id, gte(51200)).has(id, lte(51200000)).has('entity_type', 'Human').count().profile()

My expectation was that the added "has" step would only be executed on traversals that pass through the first two has steps. Therefore, I didn't expect this last has statement to add much time to the overall query, since it would simply be checking the value of a property.

My back end is a JanusGraph, configured with ElasticSearch and Google BigTable. It's got about 5 million vertices loaded.

Any guidance on this would be highly appreciated.

1 Answers

It is going to depend on how the graph engine optimizes the query and how much support an index can give. When using JanusGraph, assuming you have created the relevant indices, a .profile() should show you how much the index is helping and where the time is being spent.

Related