neoman1
neoman1

Reputation: 127

Neo4j Performance Issue while creating relationship on existing nodes?

Indexes for Products:

  1. ON: Products(SaleID)
  2. ON: Products(CountryID)
  3. ON: Products(ProductID)
  4. ON: Products(ID)
  5. Few more Properties...

Indexes for Orders:

  1. ON: Orders(SaleID)
  2. ON: Orders(CountryID)
  3. ON: Orders(ProductID)
  4. ON: Orders(ID)
  5. Few more Properties...

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

enter image description here

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

Answers (1)

František Hartman
František Hartman

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

Related Questions