You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc
+42Lines changed: 42 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,6 +21,48 @@ Replacement syntax for deprecated and removed features are also indicated.
21
21
Cypher 25 was introduced in Neo4j 2025.06 and can only be used on Neo4j 2025.06+ databases.
22
22
Features removed in Cypher 25 are still available on Neo4j 2025.06+ databases either by prepending a query with `CYPHER 5` or by having Cypher 5 as the default language for the database.
New match mode, xref:patterns/match-modes.adoc#repeatable-elements[`REPEATABLE ELEMENTS`].
47
+
This is a non-restrictive match mode, in which relationships matched across all constituent path patterns in a graph patterns can be repeatedly traversed.
48
+
49
+
50
+
a|
51
+
label:functionality[]
52
+
label:new[]
53
+
[source, cypher, role="noheader"]
54
+
----
55
+
MATCH DIFFERENT RELATIONSHIPS p = (:B)-->{,5}()
56
+
RETURN [n IN nodes(p) \| n.q] AS nodes
57
+
----
58
+
59
+
a|
60
+
New keyword, xref:patterns/match-modes.adoc#different-relationships[`DIFFERENT RELATIONSHIPS`], which enables explicitly specifying Cypher's default mode.
61
+
This is a restrictive match mode, which requires that all relationships matched across all constituent path patterns in a graph pattern must be unique.
62
+
Specifying `DIFFERENT RELATIONSHIPS` is functionally equivalent to not specifying a match mode.
Copy file name to clipboardExpand all lines: modules/ROOT/pages/patterns/index.adoc
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ This chapter includes the following sections:
26
26
* xref:patterns/variable-length-patterns.adoc[] - information about quantified path patterns, quantified relationships, and group variables.
27
27
* xref:patterns/shortest-paths.adoc[] - information about finding the `SHORTEST` path patterns.
28
28
* xref:patterns/non-linear-patterns.adoc[] - information about equijoins and graph patterns (combined path patterns).
29
-
* xref:patterns/match-modes.adoc[] - information about Cypher's different match modes, which which determine whether relationships can appear more than once in a graph pattern match.
29
+
* xref:patterns/match-modes.adoc[] - information about Cypher's different match modes, which determine whether relationships can appear more than once in a graph pattern match.
30
30
* xref:patterns/reference.adoc[] - a reference for looking up the syntax and semantics of graph pattern matching.
31
31
32
32
The model data in the examples used in this chapter are based on the UK national rail network, using https://www.raildeliverygroup.com/our-services/rail-data/fares-timetable-data.html[publicly available datasets].
Copy file name to clipboardExpand all lines: modules/ROOT/pages/patterns/match-modes.adoc
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,8 +2,8 @@
2
2
:table-caption!:
3
3
= Match modes
4
4
5
-
Match modes determine whether relationships can appear more than once in a graph pattern match.
6
-
Cypher offers two match modes:
5
+
Match modes determine whether relationships can appear more than once in a graph pattern match (nodes can appear multiple times regardless of the match mode).
6
+
Cypher contains two match modes:
7
7
8
8
* xref:patterns/match-modes.adoc#different-relationships[`DIFFERENT RELATIONSHIPS`]: a relationship can only be traversed once in a given match for a graph pattern.
9
9
The same restriction does not hold for nodes, which may be re-traversed any number of times in a matched path.
@@ -14,7 +14,7 @@ This match mode is required in order for paths to be able to traverse a relation
14
14
[[example-graph]]
15
15
== Example graph
16
16
17
-
To explain match modes, this page will use the scenario of the link:https://en.wikipedia.org/wiki/Seven_Bridges_of_K%C3%B6nigsberg[seven bridges of Königsberg], a problem studied by link:https://en.wikipedia.org/wiki/Leonhard_Euler[Leonhard Euler] in 1736 to determine if one could cross all seven bridges of Königsberg exactly once and return to the same starting location.
17
+
To explain match modes, this page will use the scenario of the link:https://en.wikipedia.org/wiki/Seven_Bridges_of_K%C3%B6nigsberg[Seven bridges of Königsberg], a problem studied by link:https://en.wikipedia.org/wiki/Leonhard_Euler[Leonhard Euler] in 1736 to determine if one could cross all seven bridges of Königsberg exactly once.
18
18
19
19
image::match-modes-graph.svg[Graph showing the seven bridges of Königsberg, width=600, role=popup]
20
20
@@ -134,7 +134,7 @@ In the `DIFFERENT RELATIONSHIPS` match mode, each step must use a unique bridge.
134
134
After the first step, one bridge is used, leaving 6 remaining bridges to be used in the subsequent steps.
135
135
Once all 6 remaining bridges are traversed, a 7th step would require re-traversing a bridge, which is not allowed.
136
136
137
-
This reflects the conclusion of Euler’s seven bridges of Königsberg problem: the impossibility of crossing each bridge exactly once and returning to the same starting point.
137
+
This reflects the conclusion of Euler’s seven bridges of Königsberg problem: the impossibility of crossing each bridge exactly once.
138
138
The below query demonstrates this impossibility.
139
139
More specifically, it tries to find a path where each bridge is crossed exactly once with a length of `7` relationships, starting and ending at the same `Location`, `Kneiphof`.
140
140
@@ -156,7 +156,7 @@ RETURN [n IN nodes(p) | n.name] AS visitedLocations,
156
156
(no results)
157
157
----
158
158
159
-
No results are returned because, when using the DIFFERENT RELATIONSHIPS match mode, it is impossible to traverse all 7 relationships once without any re-traversals, which is not allowed.
159
+
No results are returned because, when using the `DIFFERENT RELATIONSHIPS` match mode, it is impossible to traverse all 7 relationships once without any re-traversals, which is not allowed.
160
160
161
161
For more information about this match mode, see xref:patterns/reference.adoc#match-modes-rules-different-relationships[Syntax & semantics -> `DIFFERENT RELATIONSHIPS`].
162
162
@@ -165,11 +165,11 @@ For more information about this match mode, see xref:patterns/reference.adoc#mat
165
165
== REPEATABLE ELEMENTS
166
166
167
167
The `REPEATABLE ELEMENTS` match mode ensures that there are no restrictions on how many times a node or relationship can occur for a given `MATCH` result.
168
-
In so doing, the `REPEATABLE ELEMENTS` match mode does not solve the impossibility of crossing every bridge in Köningsberg exactly once and returning to the starting location.
168
+
In so doing, the `REPEATABLE ELEMENTS` match mode does not solve the impossibility of crossing every bridge in Königsberg exactly once.
169
169
However, the ability to re-traverse relationships does allow Cypher to return paths when testing Euler’s hypothesis.
170
170
171
171
[NOTE]
172
-
Queries utilizing this match mode must specify the `REPEATABLE ELEMENTS` keyword after the MATCH.
172
+
Queries utilizing this match mode must specify the `REPEATABLE ELEMENTS` keyword after `MATCH`.
173
173
174
174
The following example re-runs the above query, matching paths where each Königsberg bridge is crossed before returning the starting location
175
175
However, this time the query uses the match mode `REPEATABLE ELEMENTS`.
@@ -231,12 +231,12 @@ RETURN count(p) AS pathCount
231
231
1+d|Rows: 1
232
232
|===
233
233
234
-
If the path length is increased to exactly `10`, a total of `5580` paths are returned, `11` returns `54144`, `12` returns `229824`, and so on, without limit.
234
+
If the path length is increased to exactly `10`, a total of `5580` paths are returned, `11` hops returns `54144` paths, `12` hops returns `229824` paths, and so on, without limit.
235
235
236
236
To ensure that a `MATCH` will return a finite number of solutions in a finite amount of time, xref:patterns/reference.adoc#quantifiers-rules#quantifiers-rules[unbounded quantifiers] that do not impose an upper bound on a pattern, such as `*`, `+`, or `{1,}` are not allowed in combination with `REPEATABLE ELEMENTS`.
237
237
Also, users should take into account that the number of results returned for a high number of repetitions can significantly impact both memory usage and the speed of the query.
238
238
239
-
.Not allowed: Find paths of an unbounded length using REPEATABLE ELEMENTS
239
+
.Not allowed: find paths of an unbounded length using `REPEATABLE ELEMENTS`
240
240
[source, cypher, role=test-fail]
241
241
----
242
242
MATCH REPEATABLE ELEMENTS p = (start:Location {name: 'Kneiphof'})-[:BRIDGE]-+(start)
Copy file name to clipboardExpand all lines: modules/ROOT/pages/patterns/reference.adoc
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1706,7 +1706,7 @@ This restriction is required to prevent a a potentially infinite number of retur
1706
1706
[[match-modes-rules-clauses-subqueries]]
1707
1707
==== Clauses and subqueries
1708
1708
1709
-
Match modes can only be used after `MATCH`.
1709
+
Match modes can only be specified after `MATCH`.
1710
1710
They cannot be applied to a xref:clauses/merge.adoc[`MERGE`] clause.
1711
1711
1712
1712
Match modes are allowed in the xref:subqueries/collect.adoc[`COLLECT`], xref:subqueries/count.adoc[`COUNT`], and xref:subqueries/existential.adoc[`EXISTS`] subqueries after a `MATCH` clause.
@@ -1830,7 +1830,7 @@ The `DIFFERENT RELATIONSHIPS` match mode allows only nodes to recur in a path.
1830
1830
.Match a pattern with a length of `5` relationships using the `DIFFERENT RELATIONSHIPS` match mode
1831
1831
[source, cypher]
1832
1832
----
1833
-
MATCH p = (:B)->{5}()
1833
+
MATCH p = (:B)-->{5}()
1834
1834
RETURN [n IN nodes(p) | n.q] AS nodes
1835
1835
----
1836
1836
@@ -1850,7 +1850,7 @@ The `REPEATABLE ELEMENTS` match mode allows both nodes and relationships to be r
1850
1850
.Match a pattern with a length of `5` relationships using the `REPEATABLE ELEMENTS` match mode
0 commit comments