Cypher的ORDER BY是否使用索引?

时间:2014-05-23 17:38:25

标签: neo4j cypher

我有一个索引:Label(Uid)和:Label(Name)

但是,当我在(在shell中)配置以下两个查询时,我得到两个相同的代码路径。问题是我有700,000件商品:Label,订购商品时开始变得非常缓慢。

通过索引的属性查询排序:

MATCH (item:Label) RETURN item.Name ORDER BY item.Name SKIP 1000 LIMIT 50

通过没有索引的属性进行查询排序:

MATCH (item:Label) RETURN item.Name ORDER BY item.Created SKIP 1000 LIMIT 50

探查器让我(几乎)两者都是一样的,只改变了参数:

==> ColumnFilter(symKeys=["item", "item.Name", "  UNNAMEDS885193287"], returnItemNames=["item.Name"], _rows=30, _db_hits=0)
==> Slice(skip="Literal(1000)", _rows=30, _db_hits=0)
==>   Top(orderBy=["SortItem(Cached(  UNNAMEDS885193287 of type Any),true)"], limit="Add(Literal(1000),Literal(50))", _rows=1030, _db_hits=0)
==>     Extract(symKeys=["item"], exprKeys=["item.Name", "  UNNAMEDS885193287"], _rows=768596, _db_hits=1537192)
==>       NodeByLabel(identifier="item", _db_hits=0, _rows=768596, label="Label", identifiers=["item"], producer="NodeByLabel")

2 个答案:

答案 0 :(得分:8)

截至目前,neo4j没有利用现有索引来加速ORDER BY子句。

你应该让neo4j的人知道你希望得到这个支持: - )。

[UPDATE]

截至本次更新(2018年1月10日),此功能有open feature request。根据最近的评论,它应该是一个“高优先级功能”。

答案 1 :(得分:0)

从Neo4j 3.4开始,支持使用索引排序依据。但是您必须向查询引擎解释该属性的数据类型。添加一个虚拟where子句就足够了:

MATCH (item:Label)
WHERE item.Name > ""
RETURN item.Name 
ORDER BY item.Name 
SKIP 1000 
LIMIT 50

有关详细信息: https://neo4j.com/docs/cypher-manual/current/query-tuning/cypher-index-values-order/#_index_backed_order_by