当我们有两个具有两个不同索引的列时,索引如何在JanusGraph数据库中工作

时间:2018-05-28 10:26:42

标签: indexing gremlin janusgraph gremlin-server

我使用的是JanusGraph 0.2.0版本。我在图表中有两个索引。

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)上述查询是使用两个索引还是仅 labelA_KeyAIndex

我在图中使用了 propertyKeyB 和许多其他标签,因此我为propertyKeyB keyBIndex 创建了一个单独的索引,而没有指定indexOnly(label)

提前致谢

1 个答案:

答案 0 :(得分:2)

您可以通过遍历中的profile()步骤来验证行为

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        -

您可以在概要文件输出中看到keyBIndex是所选的那个。