我运行以下查询:
CREATE INDEX ON :Role(id)
+-------------------+
| No data returned. |
+-------------------+
Indexes added: 1
CREATE (:Role {id:'abc'})
+-------------------+
| No data returned. |
+-------------------+
Nodes created: 1
Properties set: 1
Labels added: 1
接下来,由于某种原因,当我尝试获取刚刚创建的Role
时,不使用索引。你能解释一下原因吗?
neo4j-sh (?)$ PROFILE MATCH (role:Role {id:'abc'})
> RETURN role.id;
+---------+
| role.id |
+---------+
| "abc" |
+---------+
1 row
7 ms
Compiler CYPHER 2.2
Planner COST
Projection
|
+Filter
|
+NodeByLabelScan
+-----------------+---------------+------+--------+---------------+----------------------------+
| Operator | EstimatedRows | Rows | DbHits | Identifiers | Other |
+-----------------+---------------+------+--------+---------------+----------------------------+
| Projection | 1 | 1 | 1 | role, role.id | role.id |
| Filter | 1 | 1 | 5 | role | role.id == { AUTOSTRING0} |
| NodeByLabelScan | 6 | 5 | 6 | role | :Role |
+-----------------+---------------+------+--------+---------------+----------------------------+
Total database accesses: 12
答案 0 :(得分:1)
您忘记使用索引。
试试这个:
MATCH (role:Role)
USING INDEX role:Role(id)
WHERE role.id='abc'
RETURN role.id
Projection
|
+Expand(All)
|
+NodeIndexSeek
Total database accesses: 4