11.8. Using Periodic Commit

11.8.1. Periodic commit without update limit
11.8.2. Periodic commit with update limit
11.8.3. import using periodic commit

Note: See Chapter 12, Importing Data from CSV on how to import data from CSV files.

Updating very large amounts of data (e.g. when importing) with a single Cypher query may fail due to memory constraints. For these situations only, Cypher provides the global USING PERIODIC COMMIT query hint for updating queries.

Periodic Commit tracks the number of updates performed by a query (creating a node, setting a property etc.). Whenever the number of updates reaches a limit, the current transaction is committed and replaced with a newly opened transaction.

Using periodic commit will prevent running out of memory when updating large amounts of data. However it will also break transactional isolation thus it should only be used where needed.

11.8.1. Periodic commit without update limit

PERIODIC COMMIT with no specified number of entity updates, using 1000 as the default value.

Query. 

USING PERIODIC COMMIT
FOREACH (id IN range(0, 10000)| CREATE (n:User { id: id }))

Result

Nodes created: 10001
Properties set: 10001
Labels added: 10001

(empty result)


11.8.2. Periodic commit with update limit

PERIODIC COMMIT with a specified number of entity updates after which the transaction should be committed.

Query. 

USING PERIODIC COMMIT 500
FOREACH (id IN range(0, 10000)| CREATE (n:User { id: id }))

Result

Nodes created: 10001
Properties set: 10001
Labels added: 10001

(empty result)


11.8.3. import using periodic commit

Using PERIODIC COMMIT along with LOAD CSV

Query. 

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM 'file:/tmp/cypher6107290404124791025.csv' AS line
CREATE (n:User { name: line.name })

Result

Nodes created: 4
Properties set: 4
Labels added: 4

(empty result)