I am using Neo4j 5.1 Enterprise edition.
I performed the following code:
profile MATCH(d:Dataset {name:'dataset2'})<-[:`has_d`]-(s:Score)-[:`has_a`]->(a:Algorithm {name:'algorithm1'})
MATCH (t:Tag) WHERE t.name IN ['tag1', 'tag2', 'tag3', 'tag4', 'tag5']`
MATCH (i:Image)-[:has_score]->(s)-[:`has_tag`]->(t)
RETURN i LIMIT 100
Due to the profile result is too big, i only post here the important part:
I was expecting it to filter Tag by name before doing Expand.
Why Neo4j did Expand before Filter?
How can i fix it? Is the order of execution irrelevant?
Is Filter@Neo4j a simple filter or it uses our index?
I'm very sorry for asking so many questions, maybe some of them are stupid and obvious, but I don't understand why.
Any help would be greatly appreciated
It needs to follow the relationships by type and direction first from the source nodes.
So it does the expand by type and direction and only then sees the end node and then can filter those nodes if they have the matching label(s).
If your relationships are already uniquely identifying the target node label, then you can leave off the labels from those (but not from the start node otherwise it won't use the index).