Does Cypher's ORDER BY uses the index?

2019-04-28 04:00发布

I have an index on :Label(Uid) and :Label(Name)

However, when I profile (in the shell) the following two queries I get the same codepath for both. The issue is that I have 700,000 items of :Label, and it's starting to be painfully slow to order the items.

Query ordering by a property with index:

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

Query ordering by a property without index:

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

The profiler gets me (almost) the same thing for both, only the parameters are changed:

==> 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")

标签: neo4j cypher
1条回答
老娘就宠你
2楼-- · 2019-04-28 04:41

As of now, neo4j does not take advantage of an existing index to speed up the ORDER BY clause.

You should probably let the neo4j folks know you would like this to be supported :-).

[UPDATE]

There is, as of this update (Jan. 10, 2018), an open feature request for this capability. According to a recent comment, it is supposed to be a "high prioritized feature".

查看更多
登录 后发表回答