I have the following query:
PROFILE MATCH(e:Entity {name:'Mona Lisa'})-[rel]->(e2:Entity)
WITH *, collect( e2.name) as e2Nodes
MATCH(e2)-[rele2ins:`https://www.wikidata.org/wiki/Property:P31`]->(e2ins:Entity) WHERE e2ins.wikidata_id in ['Q5']
WITH *, collect( e2ins.name) as e2InsNodes
return e2Nodes,e2InsNodes
It has 1k db hits and it's plan is as below:
When I add a WHERE condition to this query as follows:
PROFILE MATCH(e:Entity {name:'Mona Lisa'})-[rel]->(e2:Entity)
WITH *, collect( e2.name) as e2Nodes
MATCH(e2)-[rele2ins:`https://www.wikidata.org/wiki/Property:P31`]->(e2ins:Entity) WHERE e2ins.wikidata_id in ['Q5']
WITH *, collect( e2ins.name) as e2InsNodes
return e2Nodes,e2InsNodes
It's db hit count increases to 100k and the plan is as below:
Basically I'm returning entities(e2) have an incoming edge from 'Mona Lisa'. This is 1k db hits. Then I fetch entities with some specific relation(...P31) of these e2 entities. The total number of results is 227. However, there are 100k hits in between the steps when I filtered results by some attribute. Why is this the case?
Thanks.
NOTE: This applies to the following two queries below:
PROFILE MATCH(e:Entity {name:'Mona Lisa'})-[rel]->(e2:Entity)-[rele2ins:`https://www.wikidata.org/wiki/Property:P31`]->(e2ins:Entity)
return e2.name,e2ins.wikidata_id
PROFILE MATCH(e:Entity {name:'Mona Lisa'})-[rel]->(e2:Entity)-[rele2ins:`https://www.wikidata.org/wiki/Property:P31`]->(e2ins:Entity) WHERE e2ins.wikidata_id in ['Q5']
return e2.name,e2ins.wikidata_id