# How to accelerate writing

**URL:** <https://community.neo4j.com/t/how-to-accelerate-writing/14424>\
**Category:** Neo4j Graph Platform\
**Created:** [February 6, 2020, 6:24am UTC](https://community.neo4j.com/t/how-to-accelerate-writing/14424 "2020-02-06T06:24:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![shao-shuai](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/shao-shuai/32/8948_2.png) [@shao-shuai](https://community.neo4j.com/u/shao-shuai)\
**Post date:** [February 6, 2020, 6:24am UTC](https://community.neo4j.com/t/how-to-accelerate-writing/14424/1 "2020-02-06T06:24:25Z")

</div>

I have 200,000,000 relationships to write into my database. The data is a nested list like b = [[1, 2],[3, 4], [5, 6]]. Right I am using Neo4j Bolt Driver for Python to write data. But the writing is very slow, it would take 5 days to finish all the writing.

I am using the following query:

```auto
query='''WITH $names AS nested
UNWIND nested AS x
MERGE (w:Patent {name: x[0]})
MERGE (n:Patent {name: x[1]})
MERGE (w)-[r:NIHAO]-(n)
'''

```

Is there anyone who can help me with the writing? Many thanks!

---

<div class="post-metadata">

**Author:** ![Thomas\_Silkjaer](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/thomas_silkjaer/32/2476_2.png) [@Thomas\_Silkjaer](https://community.neo4j.com/u/Thomas_Silkjaer)\
**Post date:** [February 6, 2020, 7:27am UTC](https://community.neo4j.com/t/how-to-accelerate-writing/14424/2 "2020-02-06T07:27:42Z")

</div>

Is it a new database, or an existing database?

If it's a new, it's more efficient to use the neo4j-admin import tool.

If it's an existing, it can be beneficial to do the imports in parallel using apoc.periodic.iterate – but only if you can do it in a way where you are sure to avoid deadlock situations.

Also, if you are sure that the Patent's exist, it will be more beneficial to match them, rather than merge them.

---

<div class="post-metadata">

**Author:** ![conker84](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/conker84/32/275_2.png) [@conker84](https://community.neo4j.com/u/conker84)\
**Post date:** [February 6, 2020, 5:13pm UTC](https://community.neo4j.com/t/how-to-accelerate-writing/14424/3 "2020-02-06T17:13:46Z")

</div>

Did you create a constraint on `Patent.name`?

`CREATE CONSTRAINT ON (p:Patent) ASSERT p.name IS UNIQUE`

---

<div class="post-metadata">

**Author:** ![conker84](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/conker84/32/275_2.png) [@conker84](https://community.neo4j.com/u/conker84)\
**Post date:** [February 6, 2020, 5:16pm UTC](https://community.neo4j.com/t/how-to-accelerate-writing/14424/4 "2020-02-06T17:16:42Z")

</div>

Moreover don't try to send the 2\*10^8 relationships to the UNWIND all in once, try split them in batches of 10/20k

---

<div class="post-metadata">

**Author:** ![shao-shuai](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/shao-shuai/32/8948_2.png) [@shao-shuai](https://community.neo4j.com/u/shao-shuai)\
**Post date:** [February 6, 2020, 6:19pm UTC](https://community.neo4j.com/t/how-to-accelerate-writing/14424/5 "2020-02-06T18:19:33Z")

</div>

Thanks Thomas, it's a new database. I tried neo4j-admin import, it is reaally fast. The thing is, if I use csv, I have like 1600 csvs to import, I'll try to find a way to make some Concatenation.

Also thanks for the MATCH suggestion, definitely I'll give it a try.

---

<div class="post-metadata">

**Author:** ![shao-shuai](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/shao-shuai/32/8948_2.png) [@shao-shuai](https://community.neo4j.com/u/shao-shuai)\
**Post date:** [February 6, 2020, 6:20pm UTC](https://community.neo4j.com/t/how-to-accelerate-writing/14424/6 "2020-02-06T18:20:50Z")

</div>

Thanks Conker for let me know UNIQUE, I'll have a try.

---

<div class="post-metadata">

**Author:** ![shao-shuai](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/shao-shuai/32/8948_2.png) [@shao-shuai](https://community.neo4j.com/u/shao-shuai)\
**Post date:** [February 6, 2020, 7:55pm UTC](https://community.neo4j.com/t/how-to-accelerate-writing/14424/7 "2020-02-06T19:55:51Z")

</div>

Thank you Conker again, it's super fast!
