问题
So this is a neo4j graph database design question. Is having a where filter on a date property relatively performant or should I start to create nodes and relationships to help filter that.
For instance, using the neo4j movie graph example.
MATCH (nineties:Movie) WHERE nineties.released > 1990
AND nineties.released < 2000 RETURN nineties.title
If there were millions of movies, would this query be doing what would be akin to a table scan of all movies and then filtering - would creating an index on Movie.released be the way to avoid that?
Or is it better to have a node for each decade, say sixties, seventies, eighties, etc... and relating each movie to that node be more efficient query-wise?
What if it was a more dynamic time query, like movies released in the last 7 days - would just creating the index on released and adding the where clause be good enough or are there pitfalls to that approach?
回答1:
Looking up on node properties with < and > is not that "performant", I mean that it is quicker to traverse relationships.
In fact, managing times in Neo4j is a common use case where you need to have a mind shift.
Generally we use time trees and events or in your use cases movies would then have a relationship RELEASED_IN connected to the 1990 year node of the Timetree.

You may want to look at the GraphAware TimeTree Neo4j plugin that will handle this under the hood :
https://github.com/graphaware/neo4j-timetree
来源:https://stackoverflow.com/questions/30057353/performance-of-time-filters-in-neo4j-where