Reputation: 127
Indexes for Products:
Indexes for Orders:
Product has 50K nodes
Orders has 500K nodes
When I create relation on the above scenarios on the existing nodes. It takes 15 mins in community version 3.1.
Query:
MATCH(prod:Products)
WHERE prod.ID = 999
WITH prod
MATCH (ord:Orders)
WHERE ord.ID = prod.ID and ord.SaleID=prod.SaleID and ord.CountryID = prod.CountryID and ord.ProductID = prod.ProductID
CREATE (prod)-[prod_ord]->(ord)
current conig:
RAM - 64g heap max = min = 32 Page swap = default/auto
DB hit -> 500 million hits
Q1. Its not considering the Indexes, How do I force it to considering indexing via the following indexes?
Using Index ON prod:Product(SaleID)
Using Index ON prod:Product(ProductID)
Using Index ON prod:Product(CountryID)
Using Index ON prod:Product(ID)
Q2. Why does it take so much time? Any configuration needs to be done? Or data model is wrong?
Upvotes: 2
Views: 79
Reputation: 15086
Your query uses Products
label, but your index is on Product
.
Also extract the product id as parameter and use it in the second match. It should then use the Orders(ID)
index:
MATCH (prod:Products)
WHERE prod.ID = {prodId}
WITH prod
MATCH (ord:Orders)
WHERE ord.ID = {prodId} and ord.SaleID=prod.SaleID and ord.CountryID = prod.CountryID and ord.ProductID = prod.ProductID
CREATE (prod)-[prod_ord]->(ord)
You can set the parameter in the browser by
:param prodId : 999
The other indexes are probably not very useful, because usually doing a lookup on one property and then filter the results is faster than using multiple lookups and doing some kind of join. If some of the properties is more unique use that instead.
Upvotes: 1