【问题标题】:JanusGraph - Warning about all vertices scan after index was createdJanusGraph - 创建索引后有关所有顶点扫描的警告
【发布时间】:2018-12-25 12:08:50
【问题描述】:

我正在使用 Janusgraph 0.2.0 并定义了以下顶点(在 Python 中):

class Airport(TypedVertex):
    type = goblin.VertexProperty(goblin.String, card=Cardinality.single)
    airport_code = goblin.VertexProperty(goblin.String, 
        card=Cardinality.single)
    airport_city = goblin.VertexProperty(goblin.String, 
        card=Cardinality.single)
    airport_name = goblin.VertexProperty(goblin.String, 
        card=Cardinality.single)
    airport_region = goblin.VertexProperty(goblin.String, 
        card=Cardinality.single)
    airport_runways = goblin.VertexProperty(goblin.Integer, 
        card=Cardinality.single)
    airport_longest_runway = goblin.VertexProperty(goblin.Integer, 
        card=Cardinality.single)
    airport_elev = goblin.VertexProperty(goblin.Integer, 
        card=Cardinality.single)
    airport_country = goblin.VertexProperty(goblin.String, 
        card=Cardinality.single)
    airport_lat = goblin.VertexProperty(goblin.Float, 
        card=Cardinality.single)
    airport_long = goblin.VertexProperty(goblin.Float, 
        card=Cardinality.single)

然后,我使用以下命令在机场代码字段上为该节点定义了一个索引(一些命令被排除在外以保持简短)。

mgmt.makePropertyKey('type').dataType(String.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('airport_city').dataType(String.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('airport_code').dataType(String.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('airport_country').dataType(String.class).cardinality(Cardinality.SINGLE).make()
airport_code = mgmt.getPropertyKey('airport_code')
airport_city = mgmt.getPropertyKey('airport_city')
airport_country = mgmt.getPropertyKey('airport_country')
mgmt.buildIndex('by_airport_code_unique', Vertex.class).addKey(airport_code).unique().buildCompositeIndex()
mgmt.buildIndex('by_airport_city', Vertex.class).addKey(airport_city).buildCompositeIndex()
mgmt.buildIndex('by_airport_country', Vertex.class).addKey(airport_country).buildCompositeIndex()
mgmt.awaitGraphIndexStatus(graph, 'by_airport_code_unique').call()
mgmt.awaitGraphIndexStatus(graph, 'by_airport_city').call()
mgmt.awaitGraphIndexStatus(graph, 'by_airport_country').call()

创建后,我使用脚本来描述 :schema 并且我看到所有索引都已注册:

| Graph Index .          | Type .    | Element          | Unique | Backing  | PropertyKey  | Status    |
|-----------------------:|:-----|:--------|:-------|:--------|:-----------|:--------|
| by_airport_code_unique | Composite | JanusGraphVertex |   true | internalindex | airport_code | REGISTERED |
| by_airport_city | Composite | JanusGraphVertex | false | internalindex | airport_city | REGISTERED |
| by_airport_country | Composite | JanusGraphVertex |  false | internalindex | airport_country | REGISTERED |

当我尝试使用相同的 airport_code 插入第二个顶点时,正如预期的那样,我得到了一个违反约束的异常。但是,如果我进入 gremlin 控制台并运行遍历以通过他们的 airport_code 检索顶点:

g.V().has('airport_code').values()

我收到警告:WARN org.janusgraph.graphdb.transaction.StandardJanusGraphTx - 查询需要遍历所有顶点 [()]。为了获得更好的性能,请使用索引

几周前我遇到了类似的问题,问题是我试图根据标签定义索引,当时有人告诉我,janusgraph 不支持标签上的索引。但是,我认为情况并非如此。 关于为什么我的索引不起作用或未被使用的任何建议或想法? 提前感谢您的帮助。 --MD

【问题讨论】:

    标签: gremlin tinkerpop3 janusgraph


    【解决方案1】:

    您看到警告是因为您的查询没有使用索引。 composite index 用于相等匹配。

    复合索引非常快速和高效,但仅限于对特定的、先前定义的属性键组合进行相等性查找。混合索引可用于查找索引键的任意组合,并支持多个条件谓词以及取决于后备索引存储的相等性。

    为了利用复合索引,您需要提供要匹配的属性和值。例如:

    g.V().has('airport_code', 'JFK').toList()
    

    我不确定为什么创建后索引不是ENABLED,可能是您遗漏的步骤中的某些内容。如果您在与属性键相同的管理事务中创建索引,它应该是ENABLED 而不是REGISTERED。查看index lifecycle wiki。

    【讨论】:

    • 嗨,Jason,我尝试了您建议的查询,虽然我得到了顶点,但我仍然收到警告。 gremlin> g.V().has('airport_code', 'ATL').toList() 15:36:12 WARN org.janusgraph.graphdb.transaction.StandardJanusGraphTx - 查询需要遍历所有顶点 [(airport_code = ATL)]。为了获得更好的性能,请使用索引。
    • 在创建索引之前加载数据了吗?
    • 不,我通过运行 janusgraph.sh /clean 清空了整个数据库,运行脚本来创建索引并加载顶点。
    • 不确定为什么索引在创建后未启用,可能是您遗漏的步骤中的某些内容。如果您在与属性键相同的管理事务中创建索引,则它应该是 ENABLED 而不是 REGISTERED。查看index lifecycle wiki。
    • 非常感谢。我修复了脚本以在同一个事务中提交所有内容,现在它可以工作了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-28
    • 2012-10-17
    • 1970-01-01
    • 1970-01-01
    • 2019-06-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多