Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-17-2021 11:09 PM
Hello guys:
I'm a new with Neo4j. When taking a invesgation on neo4j cypher, i'm stumped by the TWO questions about INDEX:
Question1:
In summary, the index seems not working in EXISTS clause
Question2:
For example, i have two index: Invoice.id, InvoiceLine.id
Then
profile match (a:Invoice), (b:InvoiceLine)
where a.id = "xxx" and b.id = "xx"
return a,b;
It shows it hits two indexes
however, if use a.id = "xxx" or b.id = "xx"
, it can not hit any one.
So in one word, can we hit indexes on different nodes in OR clause?
Apologize for my poor English as a Chinese. ^-^
08-19-2021 12:45 PM
Hi!
Can you try:
match (a:Invoice)
where a.id = "xxx"
WITH a
MATCH (b:InvoiceLine)
WHERE b.id = "xx"
return a,b;
?
H
08-19-2021 06:33 PM
Yeah, actually i need a relation between the two node
profile match (a:Invoice)-[]->(b:InvoiceLine)
where a.id = "xxx" OR b.id = "xx"
return a,b;
Then it can not hit any index.
It is great to get help from you, but do you have any idea on Question 1?
08-20-2021 12:57 AM
Hi @1033516561 !
I just noticed the AND OR game.
Can you try soomething like:
match (a:Invoice)-[]->(b:InvoiceLine)
where a.id = "xxx"
return a,b
UNION
match (a:Invoice)-[]->(b:InvoiceLine)
where b.id = "xx"
return a,b
I'll check on a local DB as well. Can you share the entire Profile of the queries next time?
I'll check the other question next.
H
08-20-2021 01:12 AM
So happy for your response @Bennu
If I run
profile match (a:Invoice)-[]->(b:InvoiceLine)
where a.id = "xxx" OR b.id = "xx"
return a,b;
The profile shows like
And if i run
profile match (a:Invoice)-[]->(b:InvoiceLine)
where a.id = "xxx" AND b.id = "xx"
return a,b;
It shows
08-20-2021 04:24 AM
Hi @1033516561 !
I've been testing some variations to the query without the type of results you are expecting. Talking from my experience, Cypher will try to enforce a linear planing in order to avoid Joints and cartesian products. OR conditions will always be tricky because they will logically try to split the pipeline but Cypher will mostly try to guarantee the conditions during a filter step.
You can always split the pipeline with UNION,knowing that doing so you will get better performance on individuals branches. My suggestion, stick to the UNION. By the time you get into more complex queries you will have experience enough to decide what's better.
Cypher is a perfect double edge sword.
H
All the sessions of the conference are now available online