当我们有两个具有两个不同索引的列时,索引如何在 JanusGraph 数据库中工作
How does index work in JanusGraph database, when we have two columns with two different indexes
我使用的是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()
步骤来验证行为
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
是被选中的那个。
我使用的是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()
步骤来验证行为
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
是被选中的那个。