cancel
Showing results for 
Search instead for 
Did you mean: 

Why inconsistency of OR testing of Labels?

clem
Graph Steward

To test whether a Relationship has one or another label has two possible solutions:

MATCH(n)-[r:ACTED|DIRECTED]-(m)
RETURN count(r)

and

MATCH(n)-[r]-(m)
WHERE r:ACTED_IN OR r:DIRECTED
RETURN count(r)

But to test whether a Node has one or the other label has only one solution:

MATCH(n)
WHERE n:Movie OR n:Person
RETURN count(n)

This doesn't work. Why not?

MATCH(n:Movie|Person)
RETURN count(n)

It returns an error:

Invalid input '|': expected ")", "{" or "$" (line 1, column 14 (offset: 13))
"MATCH(n:Movie|Person)"

(Neo4J 4.2.1)

1 REPLY 1

dana_canzano
Neo4j
Neo4j

i suspect it doesnt work as a result of a planning perspective.
Lets say you had

match (n:Movie|Person)
where n.title='The Matrix' or n.name='Tom Hanks'
return count(n);

now you have an index on :Movie(title) but not :Person(name) or what if you actually have an index on both :Movie(title) and or :Person(name) and also :Movie(name). Not sure how the planner would know how to plan that query.

i guess this is also similar to why the RDBMS world does not have 'select count(*) from Movies|Person'

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online