Neo4j index issues

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?


Can you have some support? It will help me a lot. We are interested in Neo4j and wish it can bring some new energy into our project.

Apologize for my poor English as a Chinese. ^-^

Hi!

Can you try:

match (a:Invoice)
where a.id = "xxx" 
WITH a
MATCH (b:InvoiceLine)
WHERE b.id = "xx"
return a,b;

?

H

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? :grin:

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

So happy for your response :grinning: @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


So it seems that when having a relation pattern in MATCH, the OR clause will not hit any one index(If we have two separate label index). I think it is actually what i want to know about the inner logic of cypher parse and index process.
I have tried the UNION clause and it realy works. However i wonder it may be a little cumbersome if we have complex relationship / pattern or many clauses mixed with AND / OR.
Hope keeping in touch! :wink:

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. :wink:

H