Re: Forcing Janusgraph to use indices when performing traversal with Union step


Boxuan Li
 

Hi Brad,

I can see that your traversal is using the index index_ten1_apm_0 from the following snippet:

  backend-query                                                        3                      21.484
    \\_query=index_ten1_apm_0:[(ten1.apm.idx.type_id = i_javaServiceInstance)](4000):index_ten1_apm_0
    \\_limit=4000

Then, JanusGraph uses in-memory filtering to check whether the results returned by the index_ten1_apm_0 satisfy your predicates has('indexed-prop2', 'value2’) or has('indexed-prop3', ‘value3’).

Do you have an index that contains both the field “indexed-prop1” and “indexed-prop2”, and an index that contains both the field “indexed-prop1” and “indexed-prop3”? If so, try replacing “union” step with “or” step. If not, then you could try creating those indexes, otherwise there is no optimization that JanusGraph can do.

Btw it looks like you are using a JanusGraph version < 0.6, which is out of maintenance. The same query should run moderately faster in the latest version due to a couple of optimizations.

Best,
Boxuan

On Feb 6, 2022, at 3:14 PM, brad@... wrote:

TRAVERSAL:
[GraphStep(vertex,[]), HasStep([~label.eq(ten1.apm.version), ten1.apm.idx.type_id.eq(i_javaServiceInstance)]), UnionStep([[HasStep([ten1.apm.idx.display_name.eq(JavaServiceInstance3)]), EndStep], [HasStep([ten1.apm.idx.str4.eq(998)]), EndStep]]), RangeGlobalStep(0,2147483647), HasStep([ten1.apm.idx.discovery_ts.lte(1643313164000), ten1.apm.idx.last_seen_ts.gt(0)]), OrderGlobalStep([[value(ten1.apm.idx.last_seen_ts), desc]]), RangeGlobalStep(0,1000), GroupStep(value(uid),[FoldStep, OrderLocalStep([[value(ten1.apm.idx.last_seen_ts), desc]]), UnfoldStep, RangeGlobalStep(0,1)]), LambdaFlatMapStep(lambda), RangeGlobalStep(0,2500), PropertyMapStep([uid, ten1.apm.idx.display_name, ten1.apm.idx.last_seen_ts, ten1.apm.idx.discovery_ts, typ],value)]
Traversal Metrics
Step                                                               Count  Traversers       Time (ms)    % Dur
=============================================================================================================
JanusGraphStep([],[~label.eq(ten1.apm.version),...                     3           3          14.381    54.44
    \\_condition=(~label = ten1.apm.version AND ten1.apm.idx.type_id = i_javaServiceInstance)
    \\_orders=[]
    \\_isFitted=true
    \\_isOrdered=true
    \\_query=[(ten1.apm.idx.type_id = i_javaServiceInstance)](4000):index_ten1_apm_0
    \\_index=index_ten1_apm_0
    \\_index_impl=search
  optimization                                                                                 0.011
  optimization                                                                                 0.381
  backend-query                                                        3                      21.484
    \\_query=index_ten1_apm_0:[(ten1.apm.idx.type_id = i_javaServiceInstance)](4000):index_ten1_apm_0
    \\_limit=4000
UnionStep([[HasStep([ten1.apm.idx.display_name....                     2           2          10.005    37.87
  HasStep([ten1.apm.idx.display_name.eq(JavaSer...                     1           1           0.113
  EndStep                                                              1           1           0.076
  HasStep([ten1.apm.idx.str4.eq(998)])                                 1           1           0.208
  EndStep                                                              1           1           0.169
RangeGlobalStep(0,2147483647)                                          2           2           0.177     0.67
HasStep([ten1.apm.idx.discovery_ts.lte(16433131...                     2           2           0.616     2.33
OrderGlobalStep([[value(ten1.apm.idx.last_seen_...                     2           2           0.281     1.06
RangeGlobalStep(0,1000)                                                2           2           0.115     0.44
GroupStep(value(uid),[FoldStep, OrderLocalStep(...                     1           1           0.323     1.22
LambdaFlatMapStep(lambda)                                              2           2           0.082     0.31
RangeGlobalStep(0,2500)                                                2           2           0.062     0.23
PropertyMapStep([uid, ten1.apm.idx.display_name...                     2           2           0.373     1.41
                                            >TOTAL                     -           -          26.417        -
 

Join janusgraph-users@lists.lfaidata.foundation to automatically receive all group messages.