This issue can't be edited

Because it belongs to an archived project. Jira admins can restore projects from the archive.

Inefficient query for retrieving embedded nodes in Neo4j

Description

When accessing the Neo4j datastore via hibernate.ogm.datastore.provider=neo4j_bolt, the runtime complexity of the query for BoltNeo4jEntityQueries.getFindEntityQuery() depends on how many nodes are reachable in the overall graph by following the outgoing relations of the searched node. This bad runtime complexity seems to be caused by the query pattern that is added to the findEntityQuery by BaseNeo4jEntityQueries.appendOptionalMatchOwnerEmbeddedNodes().

Given the following Entity class

the findEntityQuery in BoltNeo4jEntityQueries is as follows:

The runtime complexity of this query depends on how many nodes can be reached from the node with uuid: {0} by following the previousNode relationship because the pattern (owner) [r*]> emb:EMBEDDED) potentially expands all those previous nodes.

For example, if we are using the Node entity for basically saving a linked list of nodes, e.g. node1 <- previousNode - node2 <- previousNode - node3 ..., then Neo4J is using the following query plan during executing the findEntityQuery:

This query plan becomes more and more inefficient, the more nodes are matched by the subpattern (owner)[r*]>(emb). In case of a linked list of several thousand nodes, when trying to retrieve the last node of the linked list via its uuid, this may lead to query times of the findEntityQuery of several seconds.

Environment

hibernate.ogm.datastore.provider=neo4j_bolt

Attachments

3

Activity

Show:

Davide D'Alto December 13, 2017 at 3:24 PM

In the screenshots you can see the changes before and after the PR I sent to fix this issue.

Guillaume Smet November 22, 2017 at 1:19 PM

Hi ,

Thanks for reporting this issue. You're right, the query is not very optimized in your case.

One of the challenge we have is that you can have embedded of embedded, that's why we need a deep query.

And the other one is that we can only have one type for a relationship so we cannot add a generic EMBEDDED label to all the embedded relationships.

That being said, Davide has ideas on how we could improve the situation. We'll get back to you soon!

Fixed

Details

Assignee

Reporter

Participants

Davide D'Alto
Guillaume Smet
Klaas Dellschaft

Components

Fix versions

Affects versions

Priority

Created November 14, 2017 at 2:15 PM
Updated January 26, 2018 at 11:50 AM
Resolved December 15, 2017 at 2:59 PM