16.5. Update Operators

These operators are used in queries that update the graph.

Constraint Operation

Creates a constraint on a (label,property) pair. The following query will create a unique constraint on the name property of nodes with the Country label.

Query 

CREATE CONSTRAINT ON (c:Country) ASSERT c.name IS UNIQUE

Query Plan 

+-------------------------+
| Operator                |
+-------------------------+
| +CreateUniqueConstraint |
+-------------------------+

Total database accesses: ?

Empty Result

Eagerly loads everything coming in to the EmptyResult operator and discards it.

Query 

CREATE (:Person)

Query Plan 

+-----------------+----------------+------+---------+-----------+
| Operator        | Estimated Rows | Rows | DB Hits | Variables |
+-----------------+----------------+------+---------+-----------+
| +ProduceResults |              1 |    0 |       0 |           |
| |               +----------------+------+---------+-----------+
| +EmptyResult    |                |    0 |       0 |           |
| |               +----------------+------+---------+-----------+
| +CreateNode     |              1 |    1 |       2 | anon[8]   |
+-----------------+----------------+------+---------+-----------+

Total database accesses: 2

Update Graph

Applies updates to the graph.

Query 

CYPHER planner=rule
CREATE (:Person { name: "Alistair" })

Query Plan 

+--------------+------+---------+-----------+------------+
| Operator     | Rows | DB Hits | Variables | Other      |
+--------------+------+---------+-----------+------------+
| +EmptyResult |    0 |       0 |           |            |
| |            +------+---------+-----------+------------+
| +UpdateGraph |    1 |       4 | anon[7]   | CreateNode |
+--------------+------+---------+-----------+------------+

Total database accesses: 4

Merge Into

When both the start and end node have already been found, merge-into is used to find all connecting relationships or creating a new relationship between the two nodes.

Query 

CYPHER planner=rule
MATCH (p:Person { name: "me" }),(f:Person { name: "Andres" })
MERGE (p)-[:FRIENDS_WITH]->(f)

Query Plan 

+--------------+------+---------+------------------+--------------------------------+
| Operator     | Rows | DB Hits | Variables        | Other                          |
+--------------+------+---------+------------------+--------------------------------+
| +EmptyResult |    0 |       0 |                  |                                |
| |            +------+---------+------------------+--------------------------------+
| +Merge(Into) |    1 |       5 | anon[68] -- f, p | (p)-[:FRIENDS_WITH]->(f)       |
| |            +------+---------+------------------+--------------------------------+
| +SchemaIndex |    1 |       2 | f -- p           | {  AUTOSTRING1}; :Person(name) |
| |            +------+---------+------------------+--------------------------------+
| +SchemaIndex |    1 |       2 | p                | {  AUTOSTRING0}; :Person(name) |
+--------------+------+---------+------------------+--------------------------------+

Total database accesses: 9