I am using JanusGraph 0.2.0 version. I have following two indexes in my graph.
mgmt = graph.openManagement()
keyName = mgmt.getPropertyKey('propertyKeyA')
labelName = mgmt.getVertexLabel('labelA')
mgmt.buildIndex('labelA_keyAIndex', Vertex.class).addKey(keyName).indexOnly(labelName).buildCompositeIndex()
mgmt.commit()
mgmt.awaitGraphIndexStatus(graph, 'labelA_keyAIndex').call()
mgmt = graph.openManagement()
mgmt.updateIndex(mgmt.getGraphIndex("labelA_keyAIndex"), SchemaAction.REINDEX).get()
mgmt.commit()
mgmt.awaitGraphIndexStatus(graph, 'labelA_keyAIndex').status(SchemaStatus.ENABLED).call()
mgmt = graph.openManagement()
keyName = mgmt.getPropertyKey("propertyKeyB")
mgmt.buildIndex("keyBIndex",Vertex.class).addKey(keyName).buildCompositeIndex()
mgmt.commit()
mgmt.awaitGraphIndexStatus(graph, "keyBIndex").call();
mgmt = graph.openManagement()
mgmt.updateIndex(mgmt.getGraphIndex("keyBIndex"), SchemaAction.REINDEX).get()
mgmt.commit()
mgmt.awaitGraphIndexStatus(graph, 'keyBIndex').status(SchemaStatus.ENABLED).call()
g.V().hasLabel("labelA").has("propertyKeyB","value").has("propertyKeyA","value").valueMap()
1) will the above query use both index or only labelA_KeyAIndex?
I am using propertyKeyB with many other label in the graph, so I have created a seperate index for propertyKeyB keyBIndex without specifying indexOnly(label)
.
Thanks in advance
You can verify the behavior by using the profile()
step on your traversal
gremlin> g.V().hasLabel("labelA").has("propertyKeyB","value").has("propertyKeyA","value").valueMap().profile()
==>Traversal Metrics
Step Count Traversers Time (ms) % Dur
=============================================================================================================
JanusGraphStep([],[~label.eq(labelA), propertyK... 0.422 94.51
\_condition=(~label = labelA AND propertyKeyB = value AND propertyKeyA = value)
\_isFitted=true
\_query=multiKSQ[1]@2147483647
\_index=keyBIndex
\_orders=[]
\_isOrdered=true
optimization 0.255
PropertyMapStep(value) 0.024 5.49
>TOTAL - - 0.447 -
You can see in the profile output that keyBIndex
is the one that is chosen.