Neo4j SDN4 实体继承和索引
Neo4j SDN4 entity inheritance and indexes
我有以下 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
我认为您混淆了 索引 和 排序顺序 。这个查询没有任何理由使用索引,因为你没有给它任何值来搜索索引。可能是索引实现按顺序排列了日期,但没有规定必须如此(显然查询没有使用索引对决策节点进行排序)。
希望对您有所帮助。
此致,
汤姆
我有以下 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
我认为您混淆了 索引 和 排序顺序 。这个查询没有任何理由使用索引,因为你没有给它任何值来搜索索引。可能是索引实现按顺序排列了日期,但没有规定必须如此(显然查询没有使用索引对决策节点进行排序)。
希望对您有所帮助。
此致, 汤姆