0

I have the following query that uses plain relationship operations for node filtering:

MATCH (dg:DecisionGroup)-[:CONTAINS]->(childD:Decision) 
WHERE dg.id = 1 
MATCH (childD)-[relationshipValueRel2:HAS_VALUE_ON]->(filterCharacteristic2:Characteristic) 
WHERE filterCharacteristic2.id = 2 
WITH relationshipValueRel2, childD, dg  
WHERE   (ANY (id IN [".NET"] WHERE id IN relationshipValueRel2.value ))  
RETURN childD.name

which returns only one node(as it was expected):

"Candidate1"

PROFILE output:

enter image description here

I'd like to optimize the query performance and this is why I use the following trigger in order to add the relationship into the manual index:

CALL apoc.trigger.add('HAS_VALUE_ON_ASSIGNED_RELATIONSHIP_PROPERTIES_TRIGGER', "UNWIND keys({assignedRelationshipProperties}) AS key 
UNWIND {assignedRelationshipProperties}[key] AS map 
WITH map 
WHERE type(map.relationship) = 'HAS_VALUE_ON' 
CALL apoc.index.addRelationship(map.relationship, keys(map.relationship))  RETURN true", 
{phase:'before'})

and the following query in order to get the same data as the first one but only from the manual index:

MATCH (dg:DecisionGroup)-[:CONTAINS]->(childD:Decision) 
WHERE dg.id = 1 
MATCH (childD)-[relationshipValueRel2:HAS_VALUE_ON]->(filterCharacteristic2:Characteristic) 
WHERE filterCharacteristic2.id = 2 
WITH relationshipValueRel2, filterCharacteristic2, childD, dg   
CALL apoc.index.in(filterCharacteristic2,'HAS_VALUE_ON','(value:(".NET"))') 
YIELD node WITH node AS childD 
RETURN childD.name

but the issue is, that this query returns two instances of the same node:

"Candidate1"
"Candidate1"

PROFILE output:

enter image description here

What am I doing wrong and why this query returns 2 instances instead of the single one ?

alexanoid
  • 24,051
  • 54
  • 210
  • 410
  • For the second match, do you know the direction ahead of time? I think that the unspecified direction is causing it to be walked twice, which triggers the trigger twice, which affects the index (just a theory). Otherwise, can you profile both queries and make sure they are the same up till the apoc call? – Tezra May 23 '18 at 17:45
  • @Tezra thanks for your comment. Yes, I know the direction and I have already updated my queries in the question taking this into account. Also, I have provided the profile information for both of the queries. What may be wrong there? Thanks. – alexanoid May 23 '18 at 18:53
  • OH! I think I see it now. Can you change the return statement to `RETURN *`? The WITH part is different in the two queries `filterCharacteristic2` is only carried over in the second version. I think that extra column is giving you extra rows. `RETURN *` should show exactly what you have at the return phase. – Tezra May 23 '18 at 19:12
  • Unfortunately, I can't change the return statement because my real query is much more complex than this one. This is only a simplified case ( – alexanoid May 23 '18 at 19:24
  • Also, I tried to add `filterCharacteristic2` into the `WITH` of the first query but it still correctly returns only one record. But with `return *` it correctly returns one record, unfortunately I can't use `return *` there – alexanoid May 23 '18 at 19:27
  • Well, aside from that, the plans ARE the same up till the end. The first query performs a filter on `WHERE ANY...`, which drops one of the rows. The other does the APOC call, and keeps all the rows. I suspect if you cut out those two parts, they would return the same results. So I'm guessing there is an error in your manual index. I don't understand that part enough to tell what could be wrong though. – Tezra May 23 '18 at 19:43
  • yeah. very likely.. but I still unable to find the source of this issue by myself – alexanoid May 24 '18 at 04:40

0 Answers0