DataStax Help Center

or() operator in graph query doesn't use indexes

Summary

Using or() operator in a graph query will scan the full vertex table, ignoring any index on the vertex properties.

Symptoms

A typical single-level or() scenario occurs when querying one vertex for two different values of the same vertex property:

g.V().has('person','firstName','Tissa').or().has('person','firstName','Lotfi')

The profile() of this query will show that even if a materialized view (MV) index was created for the property firstName, the index will not be used. This will obviously increase the query execution time.

Cause

or() operator was designed to work with vertexes of different types and different properties. Because of this feature, it will ignore any index because no logic exists to decide which index to use. An internal jira (DSP-11534 “Fix folding of OR and AND conditions.”) is aiming at resolving this issue and avoiding the table scan when using or().

Workaround

Other ways to achieve the same results of a single-level (non nested) or(), may include a search()index or the use of within() operator. within() will use the MV indexes when they are available.

An example of within() operator is:

g.V().has('person', 'firstName', within('Tissa', 'Lotfi'))

Solution

A complete solution will be released with DSP-11534.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

Powered by Zendesk