Skip to content

Commit 91f5e95

Browse files
Add Performance caveats section to Merge/Match dynamic labels section (#1137)
1 parent 2154bda commit 91f5e95

File tree

3 files changed

+56
-9
lines changed

3 files changed

+56
-9
lines changed

modules/ROOT/pages/clauses/load-csv.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,11 @@ RETURN n AS bandNodes
342342
Added 4 nodes, Set 4 properties, Added 4 labels
343343
|===
344344

345+
[NOTE]
346+
`MERGE` queries using dynamic values may not be as performant as those using static values.
347+
This is because the xref:planning-and-tuning/execution-plans.adoc[Cypher planner] uses statically available information when planning queries to determine whether to use an xref:indexes/search-performance-indexes/overview.adoc[index] or not, and this is not possible when using dynamic values.
348+
For more information, see xref:clauses/merge.adoc#dynamic-merge-caveats[`MERGE` using dynamic node labels and relationship types -> Performance caveats].
349+
345350
=== Import compressed CSV files
346351

347352
`LOAD CSV` can read local CSV files compressed with ZIP or gzip.

modules/ROOT/pages/clauses/match.adoc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -532,10 +532,6 @@ The expression must evaluate to a `STRING NOT NULL | LIST<STRING NOT NULL> NOT N
532532
If you use a `LIST<STRING>` with more than one item in a relationship pattern with dynamic relationship types, no results will be returned.
533533
This is because a relationship can only have exactly one type.
534534

535-
[NOTE]
536-
Queries using dynamic values may not be as performant as those using static values.
537-
This is because the xref:planning-and-tuning/execution-plans.adoc[Cypher planner] uses statically available information when planning queries to determine whether to use an xref:indexes/search-performance-indexes/overview.adoc[index] or not, and this is not possible when using dynamic values.
538-
539535
.Match labels dynamically
540536
[source, cypher]
541537
----
@@ -630,3 +626,11 @@ RETURN relationshipType, count(r) AS relationshipCount
630626
2+d|Rows: 2
631627
|===
632628

629+
[[dynamic-match-caveats]]
630+
=== Performance caveats
631+
632+
`MATCH` queries using dynamic values may not be as performant as those using static values.
633+
This is because the xref:planning-and-tuning/execution-plans.adoc[Cypher planner] uses statically available information when planning queries to determine whether to use an xref:indexes/search-performance-indexes/overview.adoc[index] or not, and this is not possible when using dynamic values.
634+
635+
As a result, `MATCH` queries using dynamic values cannot leverage xref:planning-and-tuning/operators/operators-detail.adoc#leaf-operators[index scans or seeks] and must instead use the xref:planning-and-tuning/operators/operators-detail.adoc#query-plan-all-nodes-scan[`AllNodesScan`] operator, which reads all nodes from the node store and is therefore more costly.
636+

modules/ROOT/pages/clauses/merge.adoc

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -703,10 +703,6 @@ The expression must evaluate to a `STRING NOT NULL | LIST<STRING NOT NULL> NOT N
703703
Using a `LIST<STRING>` with more than one item when merging a relationship using dynamic relationship types will fail.
704704
This is because a relationship can only have exactly one type.
705705

706-
[NOTE]
707-
Queries using dynamic values may not be as performant as those using static values.
708-
This is because the xref:planning-and-tuning/execution-plans.adoc[Cypher planner] uses statically available information when planning queries to determine whether to use an xref:indexes/search-performance-indexes/overview.adoc[index] or not, and this is not possible when using dynamic values.
709-
710706
.Parameters
711707
[source, parameters]
712708
----
@@ -730,7 +726,7 @@ RETURN greta.name AS name, labels(greta) AS labels, type(rel) AS relType, collec
730726
// end::clauses_merge_dynamic_merge[]
731727

732728
.Result
733-
[role="queryresult",options="footer",cols="3*<m"]
729+
[role="queryresult",options="footer",cols="4*<m"]
734730
|===
735731
| name | labels | relType | movies
736732

@@ -742,3 +738,45 @@ RETURN greta.name AS name, labels(greta) AS labels, type(rel) AS relType, collec
742738
4+d|Rows: 1 +
743739
|===
744740

741+
[[dynamic-merge-caveats]]
742+
=== Performance caveats
743+
744+
`MERGE` queries that use dynamic values may not be as performant as those using static values.
745+
This is because the xref:planning-and-tuning/execution-plans.adoc[Cypher planner] uses statically available information when planning queries to determine whether to use an xref:indexes/search-performance-indexes/overview.adoc[index] or not, and this is not possible when using dynamic values.
746+
747+
As a result, `MERGE` queries with dynamic values cannot leverage xref:planning-and-tuning/operators/operators-detail.adoc#leaf-operators[index scans or seeks] and must instead use the xref:planning-and-tuning/operators/operators-detail.adoc#query-plan-all-nodes-scan[`AllNodesScan`] operator, which reads all nodes from the node store and is therefore more costly.
748+
749+
To circumvent possible performance issues, place the dynamic labels or relationship types within `ON CREATE` or `ON MATCH` subclauses.
750+
751+
.Parameters
752+
[source, parameters]
753+
----
754+
{
755+
"onMatchLabels": ["Filmmaker", "AwardRecipient"],
756+
"onCreateLabels": ["ScreenWriter", "AwardWinner"]
757+
}
758+
----
759+
760+
.Merge nodes using dynamic values in `ON CREATE` and `ON MATCH` subclauses
761+
[source, cypher]
762+
----
763+
MERGE (n:Person {name: "Greta Gerwig"})
764+
ON MATCH
765+
SET n:$($onMatchLabels)
766+
ON CREATE
767+
SET n:$($onCreateLabels)
768+
RETURN labels(n) AS gretaLabels
769+
----
770+
771+
Because a `Person` node with the `name` "Greta Gerwig" already exists, this query will only `SET` the dynamic labels added to the `ON MATCH` subclause.
772+
773+
.Result
774+
[role="queryresult",options="footer",cols="1*<m"]
775+
|===
776+
| gretaLabels
777+
778+
| ["Person", "Director", "Filmmaker", "AwardRecipient"]
779+
780+
1+d|Rows: 1
781+
|===
782+

0 commit comments

Comments
 (0)