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~