Sachin Myneni
Sachin Myneni

Reputation: 273

Creating relationships takes too long in neo4j

I have a CSV file with the following headers:

jobid,prev_jobid,next_jobid,change_number,change_datetime,change_description,username,email,job_submittime,job_starttime,job_endtime,job_status
"27555","27552","0","134180","2017-09-07 17:39:06","Testing a new methodology",john,[email protected],"2017-09-07 17:39:09","2017-09-07 18:11:10","success"
"27552","27549","27555","134178","2017-09-07 17:32:06","bug fix",emma,[email protected],"2017-09-07 17:29:09","2017-09-07 17:11:10","success"
..
..

I've loaded up the CSV and created 3 types of nodes:

LOAD CSV WITH HEADERS FROM "file:///wbdqueue.csv" AS bud
CREATE (j:job{id:bud.jobid,pid:bud.prev_jobid,nid:bud.next_jobid,
add_time:bud.job_submittime,start_time:bud.job_starttime,end_time:bud.job_endtime,status:bud.job_status})
CREATE (c:cl{clnum:bud.change_number,time:bud.change_datetime,desc:bud.change_description})
CREATE (u:user{user:bud.username,email:bud.email})

I am then attempting to create relationships like so:

LOAD CSV WITH HEADERS FROM "file:///wbdqueue.csv" AS node
MATCH (c:cl),(u:user) WHERE c.clnum=node.change_number AND u.user=node.username
CREATE (u)-[:SUBMITTED]->(c)

First of all there is a warning in the browser that this builds a cartesian product of all disconnected patterns and may take a lot of memory/time and suggests adding an optional MATCH. Secondly I've given it many hours (>3 days) but this does not create any relationships.

What am I doing wrong with my query?

What I am eventually trying to achieve is something like this (if you run the following in your Ne04j console you should get the sample graph that I am also attaching. I've reduced the properties for keeping this simple in this visual example.):

CREATE 
  (`0` :user ) ,
  (`1` :job ) ,
  (`2` :change_number ) ,
  (`3` :user ) ,
  (`4` :change_number ) ,
  (`5` :job ) ,
  (`0`)-[:`SUBMITTED`]->(`2`),
  (`2`)-[:`CAUSED`]->(`1`),
  (`3`)-[:`SUBMITTED`]->(`4`),
  (`2`)-[:`NEXT_CHECKIN`]->(`4`),
  (`4`)-[:`CAUSED`]->(`5`),
  (`1`)-[:`NEXT_JOB`]->(`5`),
  (`5`)-[:`PREVIOUS_JOB`]->(`1`)

cypher_example_from_arrowsTool_screenshot

Thank you

Upvotes: 2

Views: 669

Answers (1)

Bruno Peres
Bruno Peres

Reputation: 16355

The warning about cartesian product occurs because you are matching multiple disconnected patterns (MATCH (c:cl),(u:user)).

I believe you can use a MERGE instead of a MATCH & WHERE followed by CREATE. Also, add USING PERIODIC COMMIT to reduce the memory overhead of the transaction state:

USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM "file:///wbdqueue.csv" AS node
MERGE (:cl {clnum : node.change_number})-[:SUBMITTED]->(:user {user : node.username})

Upvotes: 3

Related Questions