Neo4j SDN4实体继承和索引 [英] Neo4j SDN4 entity inheritance and indexes

查看:198
本文介绍了Neo4j SDN4实体继承和索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下Cypher查询:

I have a following Cypher query:

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字段上的索引.

Right now on my Neo4j database (~23k Decision nodes) this query works ~50 ms and I don't understand or it uses index on childD.createDate field.

这是PROFILE输出:

这是我的SDN 4实体:

This is my SDN 4 entities:

@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索引设置在而不是:Decision

热检查该索引对于查询的这一部分是否有效:ORDER BY childD.createDate

Hot to check that this index works(or not) for this part of the query: ORDER BY childD.createDate

推荐答案

我认为您将索引排序顺序混淆了.没有任何理由使该查询使用索引,因为您没有为其提供任何用于搜索索引的值.可能是索引实现按日期顺序排列,但是没有规则说必须这样(显然,查询没有使用索引对Decision节点进行排序).

I think you're confusing an index with a sorting order. There is no reason whatsoever that this query would use an index as you're not giving it any value to search the index with. It could be that the index-implementation has the dates in order, but there's no rule that says this has to be so (and obviously the query is not using an index to sort the Decision nodes).

希望这会有所帮助.

关于, 汤姆

这篇关于Neo4j SDN4实体继承和索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆