cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Neo4j index not work in WHERE condition with exists

Server version 4.3.1



1. Local create index

CREATE INDEX Supply_id_index IF NOT EXISTS FOR (l:SupplyPlan) ON (l.id);


2. execute explain

explain MATCH (shipment:`Shipment` {tenantId: '0804', type: 'Shipment'}) 
   WHERE EXISTS {
        MATCH (shipment:`Shipment`)
        -[:`Shipment_SupplyPlan_supplyPlan` {fieldName: 'supplyPlan'}]->(supplyPlan:`SupplyPlan`) 
        WHERE supplyPlan.id = '0804-01'
 }
RETURN shipment;

We found

NodeIndexSeek@neo4

so it should hit the index we created



3. insert data of Shipment & Supply including node and edge

CREATE (shipment:Shipment {type: 'Shipment', tenantId: "0804", id:"0804-shipment-1"});
CREATE (supplyPlan:SupplyPlan {type: 'SupplyPlan', tenantId: "0804", id:"0804-01"});
MATCH (shipment:Shipment),(supplyPlan:SupplyPlan) 
WHERE shipment.id = "0804-shipment-1" AND supplyPlan.id = "0804-01" 
CREATE (shipment)-[r:`Shipment_SupplyPlan_supplyPlan` {fieldName: 'supplyPlan'}]->(supplyPlan) 
RETURN type(r), r.fieldName;


4. re-execute the explain of query again
We found it shows the

NodeByLabelScan@neo4j

It did not hit the index



5. not use exists in where condition and try a simple query
I think using exists in where condition may be a little different, so i try a simple query with match relation pattern:

explain MATCH (shipment:`Shipment` {tenantId: '0804', type: 'Shipment'})-[:`Shipment_SupplyPlan_supplyPlan` {fieldName: 'supplyPlan'}]->(supplyPlan:`SupplyPlan`) 
WHERE supplyPlan.id = '0804-01'
RETURN shipment; 

We found it showed the

NodeIndexSeek@neo4

again.



Conclusion & Question:
After inserting data, why the query with exists in where condition, can not hit the index?
Thanks so much~

2 REPLIES 2

Bennu
Graph Fellow

Hi @1033516561 !

Do you have a script to create a dump db of your use case?

It may help me in order to quickly test this.

H

EDIT:

I tried your queries in the same order, I always get the NodeIndexSeek execution.

H

Hi, @Bennu
Which server version did you try in the above test?
I tried again in totally new 4.3.3 neo4j, with the default config and followed the steps above. It always can not hit the index in the second EXPLAIN(the first explain can hit, but after inserting the data, EXPLAIN can not hit the index)