【发布时间】:2023-09-30 06:35:02
【问题描述】:
我们在下面的代码块中使用 Titan cassandra 定义了 5 个索引
def mgmt = g.managementSystem;
try {
if (!mgmt.containsGraphIndex("byId")) {
def key = mgmt.makePropertyKey('__id').dataType(String.class).make()
mgmt.buildIndex("byId",Vertex.class).addKey(key).buildCompositeIndex()
}
if (!mgmt.containsGraphIndex("byType")) {
def key = mgmt.makePropertyKey('__type').dataType(String.class).make()
mgmt.buildIndex("byType",Vertex.class).addKey(key).buildCompositeIndex()
}
if (!mgmt.containsGraphIndex("lastName")) {
def key = mgmt.makePropertyKey('lastName').dataType(String.class).make()
mgmt.buildIndex('lastName',Vertex.class).addKey(key).buildMixedIndex(INDEX_NAME)
}
if (!mgmt.containsGraphIndex("firstName")) {
def key = mgmt.makePropertyKey('firstName').dataType(String.class).make()
mgmt.buildIndex('firstName',Vertex.class).addKey(key).buildMixedIndex(INDEX_NAME)
}
if (!mgmt.containsGraphIndex("vin")) {
def key = mgmt.makePropertyKey('vin').dataType(String.class).make()
mgmt.buildIndex('vin',Vertex.class).addKey(key).buildMixedIndex(INDEX_NAME)
}
mgmt.commit()
} catch (Exception e) {
System.err.println("An error occurred initializing indices")
e.printStackTrace()
}
然后我们执行下面的查询
g.V.has('__id','49fb8bae5f994cf5825b849a5dd9b49a')
这会产生一个警告,通知我们:
“查询需要遍历所有顶点 [{}]。为了获得更好的性能,请使用索引”
我很困惑,因为根据文档,这些索引设置正确,但由于某种原因,泰坦没有使用它们。
索引是在图表中的任何数据之前创建的,因此不需要重新索引。非常感谢任何帮助。
更新- 我设法将其分解为一个非常简单的测试。在我们的代码中,我们开发了一个自定义 gremlin 步骤以用于所述查询
Gremlin.defineStep('hasId', [Vertex,Pipe], { String id ->
_().has('__id', id)
})
然后从我们的代码中调用
g.V.hasId(id)
看来,当我们使用自定义 gremlin 步骤时,查询不使用索引,但在使用 vanilla gremlin 调用时使用索引。
在这篇文章中似乎注意到了类似的怪事 https://groups.google.com/forum/#!topic/aureliusgraphs/6DqMG13_4EQ
【问题讨论】:
标签: indexing cassandra gremlin titan