我有以下Cypher查询:
PROFILE MATCH (childD:Decision)
WITH childD
ORDER BY childD.createDate
DESC SKIP 0 LIMIT 10
MATCH (childD:Decision)-[ru:CREATED_BY]->(u:User)
OPTIONAL MATCH (childD:Decision)-[rup:UPDATED_BY]->(up:User)
RETURN ru, u, rup, up, childD AS decision, [ (childD)-[rdt:BELONGS_TO]->(t:Tag) | t ] AS tags
现在我的Neo4j数据库(~23k决策节点)此查询工作约50毫秒,我不理解或使用childD.createDate
字段上的索引。
这是PROFILE
输出:
这是我的SDN 4实体:
@NodeEntity
public abstract class BaseEntity implements BaseEntityVisitable {
private static final String CREATED_BY = "CREATED_BY";
private static final String UPDATED_BY = "UPDATED_BY";
@GraphId
private Long graphId;
@Index(unique = false)
private Date createDate;
@Relationship(type = CREATED_BY, direction = Relationship.OUTGOING)
private User createUser;
@Index(unique = false)
private Date updateDate;
@Relationship(type = UPDATED_BY, direction = Relationship.OUTGOING)
private User updateUser;
....
}
@NodeEntity
public class Decision extends BaseEntity {
private static final String BELONGS_TO = "BELONGS_TO";
private static final String CONTAINS = "CONTAINS";
private static final String DEFINED_BY = "DEFINED_BY";
@Index(unique = true)
private Long id;
@Index(unique = false)
private String name;
....
}
这是:schema
输出:
Indexes
ON :BaseEntity(createDate) ONLINE
ON :BaseEntity(updateDate) ONLINE
ON :Decision(lowerName) ONLINE
ON :Decision(name) ONLINE
ON :Decision(totalChildDecisions) ONLINE
ON :Decision(totalViews) ONLINE
ON :Decision(id) ONLINE (for uniqueness constraint)
请注意createDate
索引设置在:BaseEntity
而不是:Decision
热门检查此索引是否适用于此部分查询:ORDER BY childD.createDate
答案 0 :(得分:1)
我认为您将索引与排序顺序混淆。没有任何理由认为此查询将使用索引,因为您没有给它任何值来搜索索引。可能是索引实现按顺序排列日期,但是没有规则说明必须这样(显然查询不使用索引来对Decision节点进行排序)。
希望这有帮助。
此致 汤姆