Load CSV taking excessive amount of time

Hello, my LOAD CSV query is taking a very long time, despite having indexes on my columns and a unique constraint on PersonId.

It sometimes takes over 5 minutes for a CSV file with 27k records that is just under 3MB.

Here is my query:

LOAD CSV WITH HEADERS FROM ('myurl.csv') AS row 
MERGE (n:Person {name: row.PersonId }) 
SET n += {EmailAddress: row.EmailAddress, PhoneNumber: row.PhoneNumber}
RETURN true

I have also tried ON CREATE SET with no performance improvement.

Can anyone help me figure out what is causing it to take so long?

Thank you!

Hi @henry007 -

Be sure that your uniqueness constraint has been created for the correct node property. Given the Cypher statement you shared the uniqueness constraint should be on :Person(name) (not PersonId).

You can confirm the index / constraint is being used by adding PROFILE to the beginning of your Cypher query and examining the query plan for usage of the index.

ON CREATE SET will improve performance by not setting property values for nodes that already exist (when the MERGE statement matches instead of creating).

1 Like

Hello, creating the constraint on :Person(name) fixed my issue! Thank you so much!

1 Like