Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-23-2020 10:35 AM
In my db I have some nodes Message
which could have a relationship Replay
, in a form like below:
(:Message)<-[:REPLAY]-(:Message)<-[:REPLAY]-(:Message)...
I want to return a Message which is the start of conversation and all his REPLAY relationships, so I write this query:
MATCH (n)
WHERE
ID(n) = ' + id + '
OPTIONAL MATCH x=(n)<-[:REPLAY*]-(r)
RETURN n AS StartOfConversation, r AS Replay ORDER by r.timestamp ASC
But when the path is too long, the query keeps running.
If i limit the path length with -[:REPLAY*100]-
I get the results
I also get this warning:
Binding relationships to a list in a variable length pattern is deprecated. (Binding a variable length relationship pattern to a variable ('r') is deprecated and will be unsupported in a future version. The recommended way is to bind the whole path to a variable, then extract the relationships: MATCH p = (...)-[...]-(...) WITH *, relationships(p) AS r)
How can I improve this query to work on every path ?
05-23-2020 02:35 PM
Some quick optimizations I can suggest right away:
But I must say, you have a rather data modeling problem here, thread messages should not be organized as linked lists. You already have them ordered by date, and they should all point to their single original :Thread parent. Message dependencies should exist only if someone replies to some other message, in a hierarchical layout.
It's easy to change their relationships, if you're allowed to. And your processing time will be improved by 1-2 orders of magnitude.
All the sessions of the conference are now available online