Skip to content

Commit f850924

Browse files
Add Performance caveats section to Merge/Match dynamic labels section (#1137)
1 parent 4c20ac5 commit f850924

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
@@ -339,6 +339,11 @@ RETURN n AS bandNodes
339339
Added 4 nodes, Set 4 properties, Added 4 labels
340340
|===
341341

342+
[NOTE]
343+
`MERGE` queries using dynamic values may not be as performant as those using static values.
344+
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.
345+
For more information, see xref:clauses/merge.adoc#dynamic-merge-caveats[`MERGE` using dynamic node labels and relationship types -> Performance caveats].
346+
342347
=== Import compressed CSV files
343348

344349
`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
@@ -522,10 +522,6 @@ The expression must evaluate to a `STRING NOT NULL | LIST<STRING NOT NULL> NOT N
522522
If you use a `LIST<STRING>` with more than one item in a relationship pattern with dynamic relationship types, no results will be returned.
523523
This is because a relationship can only have exactly one type.
524524

525-
[NOTE]
526-
Queries using dynamic values may not be as performant as those using static values.
527-
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.
528-
529525
.Match labels dynamically
530526
[source, cypher]
531527
----
@@ -614,3 +610,11 @@ RETURN relationshipType, count(r) AS relationshipCount
614610
2+d|Rows: 2
615611
|===
616612

613+
[[dynamic-match-caveats]]
614+
=== Performance caveats
615+
616+
`MATCH` queries using dynamic values may not be as performant as those using static values.
617+
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.
618+
619+
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.
620+

modules/ROOT/pages/clauses/merge.adoc

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

705-
[NOTE]
706-
Queries using dynamic values may not be as performant as those using static values.
707-
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.
708-
709705
.Parameters
710706
[source, parameters]
711707
----
@@ -727,7 +723,7 @@ RETURN greta.name AS name, labels(greta) AS labels, type(rel) AS relType, collec
727723
----
728724

729725
.Result
730-
[role="queryresult",options="footer",cols="3*<m"]
726+
[role="queryresult",options="footer",cols="4*<m"]
731727
|===
732728
| name | labels | relType | movies
733729

@@ -739,3 +735,45 @@ RETURN greta.name AS name, labels(greta) AS labels, type(rel) AS relType, collec
739735
4+d|Rows: 1 +
740736
|===
741737

738+
[[dynamic-merge-caveats]]
739+
=== Performance caveats
740+
741+
`MERGE` queries that use dynamic values may not be as performant as those using static values.
742+
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.
743+
744+
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.
745+
746+
To circumvent possible performance issues, place the dynamic labels or relationship types within `ON CREATE` or `ON MATCH` subclauses.
747+
748+
.Parameters
749+
[source, parameters]
750+
----
751+
{
752+
"onMatchLabels": ["Filmmaker", "AwardRecipient"],
753+
"onCreateLabels": ["ScreenWriter", "AwardWinner"]
754+
}
755+
----
756+
757+
.Merge nodes using dynamic values in `ON CREATE` and `ON MATCH` subclauses
758+
[source, cypher]
759+
----
760+
MERGE (n:Person {name: "Greta Gerwig"})
761+
ON MATCH
762+
SET n:$($onMatchLabels)
763+
ON CREATE
764+
SET n:$($onCreateLabels)
765+
RETURN labels(n) AS gretaLabels
766+
----
767+
768+
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.
769+
770+
.Result
771+
[role="queryresult",options="footer",cols="1*<m"]
772+
|===
773+
| gretaLabels
774+
775+
| ["Person", "Director", "Filmmaker", "AwardRecipient"]
776+
777+
1+d|Rows: 1
778+
|===
779+

0 commit comments

Comments
 (0)