neo4jcypherspring-data-neo4j-4neo4j-ogm

Neo4j SDN4 entity inheritance and indexes


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

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.

This is PROFILE output:

enter image description here

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;

....

}

This is :schema output:

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)

Please note that createDate index is set on :BaseEntity and not on :Decision

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


Solution

  • 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).

    Hope this helps.

    Regards, Tom