Skip to content

Conversation

@WilcoNeo
Copy link
Contributor

No description provided.

Comment on lines 565 to 566
An alternative is to use the information that we want to find paths with a total distance less than `6.05`.
From the `ALL SHORTEST` query, we know that there exists a path with a total distance of `6.04`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid mentioning SHORTEST here, it muddies the water. We don't want to suggest the association of SHORTEST with allReduce().
Like in the previous example we say "This works fine where the solution is known to lie within some range of hops.", here I would say that I pick a known upper bound of 6.05 or maybe even 7 or 10 for the total distance. I wouldn't specify how I know it to be a reasonable upper bound.

* Nodes or relationships must have properties satisfying some condition.
For example, all relationships must have the property `distance > 10`.

* For every iteration of the QPP, an aggregated value over the constructed path so far should satisfy a predicate.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* For every iteration of the QPP, an aggregated value over the constructed path so far should satisfy a predicate.
* For every iteration of the quantified path pattern, an aggregated value over the constructed path so far should satisfy a predicate.

| *Syntax* 3+| `allReduce(accumulator = initial, stepVariable IN list \| reductionFunction, predicate)`
| *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.
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.
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] (not within a xref:patterns/shortest-paths.adoc[shortest path pattern]), it allows for the early pruning of paths that do not satisfy the predicate.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make it a bit longer and as a follow-up sentence, not between prentheses.

Comment on lines 113 to 115
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.

*Note*: AllReduce should not be used for a group variable within a xref:patterns/shortest-paths.adoc[shortest path pattern].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for being so picky but this doesn't sound quite right, for a few reasons:

  • It should refer to the function as allReduce(), not AllReduce, see Considerations below,
  • We try our very best to inline allReduce() predicates, but it isn't always possible,
  • You can totally use it with SHORTEST but the important point is that it won't be inlined.

Something along the lines of:

When allReduce() is used with 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 will be inlined where applicable. This inlining allows for early pruning of the search space by discarding paths as soon as the predicate is not satisfied. 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.

| *Syntax* 3+| `allReduce(accumulator = initial, stepVariable IN list \| reductionFunction, predicate)`
| *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.
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.
When 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 will be inlined where applicable.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
When 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 will be inlined where applicable.
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.

* Nodes or relationships must have properties satisfying some condition.
For example, all relationships must have the property `distance > 10`.

* For every iteration of the quantified path pattern, an aggregated value over the constructed path so far should satisfy a predicate.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* For every iteration of the quantified path pattern, an aggregated value over the constructed path so far should satisfy a predicate.
* For every iteration of the quantified path pattern, an aggregated value over the constructed path so far must satisfy a predicate.

double-check if this reflects the intended meaning

Using inline predicates or making quantified path patterns more specific where possible can thus greatly improve query performance.

An alternative is to use an upper bound for the total distance, for example `6.05`.
Once a path exceeds this upper bound, we can prune it and continue searching other paths.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Once a path exceeds this upper bound, we can prune it and continue searching other paths.
Once a path exceeds this upper bound, you can prune it and continue searching other paths.

@WilcoNeo WilcoNeo force-pushed the dev-allReduceInPatternDocs branch from 6d9be28 to de4db08 Compare November 5, 2025 13:06
@WilcoNeo WilcoNeo requested a review from rsill-neo4j November 5, 2025 13:06
@neo4j-docops-agent
Copy link
Collaborator

neo4j-docops-agent commented Nov 5, 2025

Thanks for the documentation updates.

The preview documentation has now been torn down - reopening this PR will republish it.

@rsill-neo4j
Copy link
Contributor

is this tied to a specific release?

@WilcoNeo
Copy link
Contributor Author

WilcoNeo commented Nov 6, 2025

is this tied to a specific release?

No, it is just an extension of the docs such that people can know about allReduce() when reading about QPPs and to communicate the limitation w.r.t. SHORTEST.

@WilcoNeo WilcoNeo merged commit f90532c into neo4j:dev Nov 7, 2025
5 checks passed
@WilcoNeo WilcoNeo deleted the dev-allReduceInPatternDocs branch November 7, 2025 08:20
@rsill-neo4j rsill-neo4j added cherry-picked This PR was merged in another version and the changes has been cherry picked in this PR. cherry-pick-to-cypher-25 labels Nov 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick-to-cypher-25 cherry-picked This PR was merged in another version and the changes has been cherry picked in this PR. Cypher 25 dev team-cypher-planner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants