From abc107c85260e4abbe8e7f7c41ef6797efac0a53 Mon Sep 17 00:00:00 2001 From: Pontus Melke Date: Tue, 11 Nov 2025 13:14:11 +0100 Subject: [PATCH 1/2] Add documentation for MergeInto --- .../operators/operators-detail.adoc | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/modules/ROOT/pages/planning-and-tuning/operators/operators-detail.adoc b/modules/ROOT/pages/planning-and-tuning/operators/operators-detail.adoc index df40642e9..8e4a0ac86 100644 --- a/modules/ROOT/pages/planning-and-tuning/operators/operators-detail.adoc +++ b/modules/ROOT/pages/planning-and-tuning/operators/operators-detail.adoc @@ -6005,6 +6005,58 @@ Total database accesses: 4, total allocated memory: 184 ====== +[query-plan-merge-into]] +=== Merge Into + +The `MergeInto` operator is similar to the xref:planning-and-tuning/operators/operators-detail.adoc#query-plan-merge[`Merge`] operator, but is used when the start and end node of the pattern is matched outside the MERGE pattern. + +If necessary the operator will lock the pattern nodes before creating the relationship, to make sure we don't create multiple relationships between the nodes. + + +.MergeInto +====== + + +.Query +[source, cypher] +---- +PROFILE +MATCH (s:Person {name: 'me'}) +MERGE (s)-[:FRIENDS_WITH]->(s) +---- + +.Query Plan +[role="queryplan", subs="attributes+"] +---- +Planner COST + +Runtime PIPELINED + +Runtime version {neo4j-version} + +Batch size 128 + ++-----------------+----+-------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+----------------------+ +| Operator | Id | Details | Estimated Rows | Rows | DB Hits | Memory (Bytes) | Page Cache Hits/Misses | Time (ms) | Pipeline | Indexes Used | ++-----------------+----+-------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+----------------------+ +| +ProduceResults | 0 | | 1 | 0 | 0 | 0 | | | | | +| | +----+-------------------------------------------------------+----------------+------+---------+----------------+ | | +----------------------+ +| +EmptyResult | 1 | | 1 | 0 | 0 | | | | | | +| | +----+-------------------------------------------------------+----------------+------+---------+----------------+ | | +----------------------+ +| +Apply | 2 | | 1 | 1 | 0 | | | | | | +| |\ +----+-------------------------------------------------------+----------------+------+---------+----------------+ | | +----------------------+ +| | +MergeInto | 3 | MERGE (s)-[anon_0:FRIENDS_WITH]->(s) | 1 | 1 | 1 | | | | | | +| | | +----+-------------------------------------------------------+----------------+------+---------+----------------+ | | +----------------------+ +| | +Argument | 4 | s | 1 | 1 | 0 | 2288 | 1/0 | 0.673 | Fused in Pipeline 1 | | +| | +----+-------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+----------------------+ +| +NodeIndexSeek | 5 | RANGE INDEX s:Person(name) WHERE name = $autostring_0 | 1 | 1 | 2 | 376 | 1/0 | 0.256 | In Pipeline 0 | range_person_name: 1 | ++-----------------+----+-------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+----------------------+ + +Total database accesses: 15, total allocated memory: 2232 +---- + +====== + [[query-plan-locking-merge]] === Locking Merge From 4cd6066354e4ebc32f2b47eff69472fcb07e079a Mon Sep 17 00:00:00 2001 From: Stefano Ottolenghi Date: Tue, 11 Nov 2025 16:38:42 +0100 Subject: [PATCH 2/2] Update operators-detail.adoc --- .../planning-and-tuning/operators/operators-detail.adoc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/ROOT/pages/planning-and-tuning/operators/operators-detail.adoc b/modules/ROOT/pages/planning-and-tuning/operators/operators-detail.adoc index 8e4a0ac86..785088ca9 100644 --- a/modules/ROOT/pages/planning-and-tuning/operators/operators-detail.adoc +++ b/modules/ROOT/pages/planning-and-tuning/operators/operators-detail.adoc @@ -6008,15 +6008,14 @@ Total database accesses: 4, total allocated memory: 184 [query-plan-merge-into]] === Merge Into -The `MergeInto` operator is similar to the xref:planning-and-tuning/operators/operators-detail.adoc#query-plan-merge[`Merge`] operator, but is used when the start and end node of the pattern is matched outside the MERGE pattern. +The `MergeInto` operator is similar to the xref:planning-and-tuning/operators/operators-detail.adoc#query-plan-merge[`Merge`] operator, but is used when the start and end node of the pattern is matched outside the `MERGE` pattern. -If necessary the operator will lock the pattern nodes before creating the relationship, to make sure we don't create multiple relationships between the nodes. +If necessary, the operator locks the pattern nodes before creating the relationship, to avoid creating multiple relationships between the nodes. .MergeInto ====== - .Query [source, cypher] ----