Neo4j: Incorrect Cypher query result when relationship type is specified

Created on 22 Feb 2019  路  3Comments  路  Source: neo4j/neo4j

  • Neo4j version: 3.5.2
  • Operating system: Windows 10
  • API: Cypher

Steps to reproduce

  1. Start Neo4j with the example Cineasts database (https://neo4j.com/developer/example-data/#_data_sets).
  2. Open localhost:7474 and execute these queries:
    2a. match (a)-[:DIRECTED]-(b)--(c) where a.id="6593" and c.id=a.id return c.id
    2b. match (a)-[:DIRECTED]-(b)-[:DIRECTED]-(c) where a.id="6593" and c.id=a.id return c.id

Expected behavior

Both queries should return "6593" because the relationship type is DIRECTED and it shouldn't matter if we specify it or not.

Actual behavior

Query 2a returns "6593" while the query 2b returns an empty result set.

image

cypher team-cypher

Most helpful comment

@averza Here's a section in the docs where we discuss the uniqueness of a relationship per path:

https://neo4j.com/docs/cypher-manual/current/introduction/uniqueness/

All 3 comments

Hi, thanks for reporting. We will look into it.

/Team Cypher

@averza This is not a bug but intended behaviour. When running your first query, you get the result shown in the attached image. The variables a and c will both map to the same node namely John Huston and you will get 2 results since you have 2 different b nodes. The relationship between a and b will be the DIRECTED and the one between b and c will be ACTED_IN.

In your second query you search for 2 DIRECTED relationship but since each b node just have one DIRECTED relationship to the node with id 6593 and Cypher never traverse the same relationship twice you won't get any matches.

Best regards Neo4j Cypher team

cypher_rel_issue

@averza Here's a section in the docs where we discuss the uniqueness of a relationship per path:

https://neo4j.com/docs/cypher-manual/current/introduction/uniqueness/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lassewesth picture lassewesth  路  5Comments

savv picture savv  路  3Comments

apjanke picture apjanke  路  6Comments

webtic picture webtic  路  4Comments

szarnyasg picture szarnyasg  路  3Comments