Jack Daniel
Jack Daniel

Reputation: 2611

Neo4j : Slow Selection Operation with Huge Data

I am trying to the nodes from the Graph randomly each time. the number of nodes is 24600968 in the database. The following query

MATCH (n:Employee)
WITH n AS emp,rand() AS ids ORDER BY ids LIMIT 10

MATCH (n:Company)
WITH emp, n AS com,rand() AS ids ORDER BY ids LIMIT 10
RETURN emp.guid,com.guid

is taking very long time. The time is

Returned 10 rows in 306863 ms.

How can I speed up this process.

Upvotes: 0

Views: 121

Answers (1)

Michael Hunger
Michael Hunger

Reputation: 41686

  1. run 2 separate statements

  2. try this

Lookup nodes by a random set of ids and check if they are an employee

MATCH (n) WITH count(*) as total
WITH [_ IN range(1,10000) | toInt(rand()*total)] as ids
MATCH (emp) WHERE id(emp) IN ids AND emp:Employee
RETURN emp LIMIT 10

Your query generates a list of 24M random values and sorts it (twice) while also pulling that many nodes from the graph into memory (not sure how much memory you have)

Upvotes: 2

Related Questions