Skip to content

Commit 2e15dbb

Browse files
authored
Merge branch 'dev' into dev_add_coll_functions
2 parents 13695ea + 523e35a commit 2e15dbb

File tree

4 files changed

+95
-20
lines changed

4 files changed

+95
-20
lines changed

modules/ROOT/pages/functions/predicate.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ RETURN all(i in emptyList WHERE true) as allTrue, all(i in emptyList WHERE false
110110
|===
111111
| *Syntax* 3+| `allReduce(accumulator = initial, stepVariable IN list \| reductionFunction, predicate)`
112112
| *Description* 3+| Returns true if, during the stepwise evaluation of a value across the elements in a given `LIST<ANY>`, the accumulated result satisfies a specified predicate at every step.
113-
Where that list is a xref:patterns/variable-length-patterns.adoc#group-variables[group variable] defined in a xref:patterns/variable-length-patterns.adoc#quantified-path-patterns[quantified path pattern], it allows for the early pruning of paths that do not satisfy the predicate.
113+
If that list is a xref:patterns/variable-length-patterns.adoc#group-variables[group variable] defined in a xref:patterns/variable-length-patterns.adoc#quantified-path-patterns[quantified path pattern], its predicate is inlined where applicable.
114+
This inlining allows for early pruning of the search space by discarding paths as soon as the predicate is not satisfied.
115+
Note that `allReduce()` predicates are not inlined when used in a xref:patterns/shortest-paths.adoc[shortest path pattern], and therefore do not benefit from this pruning.
114116
.7+| *Arguments* | *Name* | *Type* | *Description*
115117
| `accumulator` | `ANY` | A variable that holds the result of the `reductionFunction` as the `list` is iterated.
116118
It is initialized with the value of `initial`.

modules/ROOT/pages/patterns/variable-length-patterns.adoc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,10 @@ For example, all relationships in the path must be of type `EMPLOYED_BY`.
380380
* Nodes or relationships must have properties satisfying some condition.
381381
For example, all relationships must have the property `distance > 10`.
382382

383+
* For every iteration of the quantified path pattern, an aggregated value over the constructed path so far must satisfy a predicate.
384+
For example, the sum of the property `distance` of the relationships in the path must be less than 50 for every step in the construction of the path.
385+
See xref::functions/predicate.adoc#functions-allreduce[allReduce] for more information about this predicate.
386+
383387
To demonstrate the utility of predicates in quantified path patterns, this section considers an example of finding the shortest path by physical distance and compares that to the results yielded by using the xref:patterns/shortest-paths.adoc[`SHORTEST`] keyword.
384388
The graph in this example continues with `Station` nodes, but adds both a geospatial `location` property to the `Stations`, as well as `LINK` relationships with a `distance` property representing the distance between pairs of `Stations`:
385389

@@ -558,6 +562,26 @@ This query avoids having to find all possible paths and then imposing a `LIMIT 1
558562
It also shows that there is only one path to solving the query (a number that remains constant even if the data from the rest of the UK railway network was included).
559563
Using inline predicates or making quantified path patterns more specific where possible can thus greatly improve query performance.
560564

565+
An alternative is to use an upper bound for the total distance, for example `6.05`.
566+
Once a path exceeds this upper bound, you can prune it and continue searching other paths.
567+
The xref::functions/predicate.adoc#functions-allreduce[allReduce] predicate function expresses this as follows:
568+
569+
.Query
570+
[source,cypher]
571+
----
572+
MATCH (bfr:Station {name: "London Blackfriars"}),
573+
(ndl:Station {name: "North Dulwich"})
574+
MATCH p = (bfr) ((a)-[l:LINK]-(b:Station))+ (ndl)
575+
WHERE allReduce(
576+
pathLength = 0,
577+
link IN l | pathLength + link.distance,
578+
pathLength < 6.05
579+
)
580+
RETURN reduce(acc = 0, r in relationships(p) | round(acc + r.distance, 2))
581+
AS distance
582+
ORDER BY distance LIMIT 1
583+
----
584+
561585
[[further-reading]]
562586
== Further reading
563587

modules/ROOT/pages/planning-and-tuning/operators/operators-detail.adoc

Lines changed: 66 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3379,23 +3379,21 @@ Runtime version {neo4j-version}
33793379
33803380
Batch size 128
33813381
3382-
+--------------------+----+-------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+----------------------+
3383-
| Operator | Id | Details | Estimated Rows | Rows | DB Hits | Memory (Bytes) | Page Cache Hits/Misses | Time (ms) | Pipeline | Indexes Used |
3384-
+--------------------+----+-------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+----------------------+
3385-
| +ProduceResults | 0 | | 1 | 0 | 0 | 0 | | | | |
3386-
| | +----+-------------------------------------------------------+----------------+------+---------+----------------+ | | +----------------------+
3387-
| +EmptyResult | 1 | | 1 | 0 | 0 | | | | | |
3388-
| | +----+-------------------------------------------------------+----------------+------+---------+----------------+ | | +----------------------+
3389-
| +Apply | 2 | | 1 | 0 | 0 | | | | | |
3390-
| |\ +----+-------------------------------------------------------+----------------+------+---------+----------------+ | | +----------------------+
3391-
| | +ArgumentTracker | 6 | | 1 | 0 | 0 | 736 | | | | |
3392-
| | | +----+-------------------------------------------------------+----------------+------+---------+----------------+ | | +----------------------+
3393-
| | +MergeInto | 3 | MERGE (s)-[anon_0:FRIENDS_WITH]->(s) | 1 | 1 | 1 | | | | | |
3394-
| | | +----+-------------------------------------------------------+----------------+------+---------+----------------+ | | +----------------------+
3395-
| | +Argument | 4 | s | 1 | 1 | 0 | 2288 | 1/0 | 1.626 | Fused in Pipeline 1 | |
3396-
| | +----+-------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+----------------------+
3397-
| +NodeIndexSeek | 5 | RANGE INDEX s:Person(name) WHERE name = $autostring_0 | 1 | 1 | 2 | 376 | 1/0 | 0.300 | In Pipeline 0 | range_person_name: 1 |
3398-
+--------------------+----+-------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+----------------------+
3382+
+-----------------+----+-------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+----------------------+
3383+
| Operator | Id | Details | Estimated Rows | Rows | DB Hits | Memory (Bytes) | Page Cache Hits/Misses | Time (ms) | Pipeline | Indexes Used |
3384+
+-----------------+----+-------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+----------------------+
3385+
| +ProduceResults | 0 | | 1 | 0 | 0 | 0 | | | | |
3386+
| | +----+-------------------------------------------------------+----------------+------+---------+----------------+ | | +----------------------+
3387+
| +EmptyResult | 1 | | 1 | 0 | 0 | | | | | |
3388+
| | +----+-------------------------------------------------------+----------------+------+---------+----------------+ | | +----------------------+
3389+
| +Apply | 2 | | 1 | 1 | 0 | | | | | |
3390+
| |\ +----+-------------------------------------------------------+----------------+------+---------+----------------+ | | +----------------------+
3391+
| | +MergeInto | 3 | MERGE (s)-[anon_0:FRIENDS_WITH]->(s) | 1 | 1 | 1 | | | | | |
3392+
| | | +----+-------------------------------------------------------+----------------+------+---------+----------------+ | | +----------------------+
3393+
| | +Argument | 4 | s | 1 | 1 | 0 | 2288 | 1/0 | 0.673 | Fused in Pipeline 1 | |
3394+
| | +----+-------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+----------------------+
3395+
| +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 |
3396+
+-----------------+----+-------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+----------------------+
33993397
34003398
Total database accesses: 15, total allocated memory: 2232
34013399
----
@@ -6007,6 +6005,57 @@ Total database accesses: 4, total allocated memory: 184
60076005
60086006
======
60096007

6008+
[query-plan-merge-into]]
6009+
=== Merge Into
6010+
6011+
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.
6012+
6013+
If necessary, the operator locks the pattern nodes before creating the relationship, to avoid creating multiple relationships between the nodes.
6014+
6015+
6016+
.MergeInto
6017+
======
6018+
6019+
.Query
6020+
[source, cypher]
6021+
----
6022+
PROFILE
6023+
MATCH (s:Person {name: 'me'})
6024+
MERGE (s)-[:FRIENDS_WITH]->(s)
6025+
----
6026+
6027+
.Query Plan
6028+
[role="queryplan", subs="attributes+"]
6029+
----
6030+
Planner COST
6031+
6032+
Runtime PIPELINED
6033+
6034+
Runtime version {neo4j-version}
6035+
6036+
Batch size 128
6037+
6038+
+-----------------+----+-------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+----------------------+
6039+
| Operator | Id | Details | Estimated Rows | Rows | DB Hits | Memory (Bytes) | Page Cache Hits/Misses | Time (ms) | Pipeline | Indexes Used |
6040+
+-----------------+----+-------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+----------------------+
6041+
| +ProduceResults | 0 | | 1 | 0 | 0 | 0 | | | | |
6042+
| | +----+-------------------------------------------------------+----------------+------+---------+----------------+ | | +----------------------+
6043+
| +EmptyResult | 1 | | 1 | 0 | 0 | | | | | |
6044+
| | +----+-------------------------------------------------------+----------------+------+---------+----------------+ | | +----------------------+
6045+
| +Apply | 2 | | 1 | 1 | 0 | | | | | |
6046+
| |\ +----+-------------------------------------------------------+----------------+------+---------+----------------+ | | +----------------------+
6047+
| | +MergeInto | 3 | MERGE (s)-[anon_0:FRIENDS_WITH]->(s) | 1 | 1 | 1 | | | | | |
6048+
| | | +----+-------------------------------------------------------+----------------+------+---------+----------------+ | | +----------------------+
6049+
| | +Argument | 4 | s | 1 | 1 | 0 | 2288 | 1/0 | 0.673 | Fused in Pipeline 1 | |
6050+
| | +----+-------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+----------------------+
6051+
| +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 |
6052+
+-----------------+----+-------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+----------------------+
6053+
6054+
Total database accesses: 15, total allocated memory: 2232
6055+
----
6056+
6057+
======
6058+
60106059

60116060
[[query-plan-locking-merge]]
60126061
=== Locking Merge

modules/ROOT/pages/syntax/naming.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ Some techniques to mitigate this are:
6262
Here are the recommended naming conventions:
6363

6464
|===
65-
| Node labels | Camel-case, beginning with an upper-case character | `:VehicleOwner` rather than `:vehicle_owner` etc.
66-
| Relationship types | Upper-case, using underscore to separate words | `:OWNS_VEHICLE` rather than `:ownsVehicle` etc.
65+
| Node labels | Pascal case, capitalized words using no spaces or separators | `:VehicleOwner` rather than `:vehicle_owner` etc.
66+
| Relationship types | Upper case, using underscore to separate words | `:OWNS_VEHICLE` rather than `:ownsVehicle` etc.
6767
|===
6868

6969
[[identifier-length-limit]]

0 commit comments

Comments
 (0)