【问题标题】:How does index work in JanusGraph database, when we have two columns with two different indexes当我们有两个具有两个不同索引的列时,索引如何在 JanusGraph 数据库中工作
【发布时间】:2018-05-28 10:26:41
【问题描述】:

我正在使用 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)

提前致谢

【问题讨论】:

  • 我希望你不要在图中使用世界列,它很快就会变得非常混乱。也就是说,将 .profile() 附加到遍历的末尾以查看使用了哪些索引。在 JanusGraph 中,图索引仅用于随后的初始查找,以顶点​​为中心的索引接管。

标签: indexing gremlin janusgraph gremlin-server


【解决方案1】:

您可以通过在遍历中使用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 是被选中的那个。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-19
    • 1970-01-01
    相关资源
    最近更新 更多