I have the following Cypher query:
MATCH (v:Value)-[:CONTAINS]->(hv:HistoryValue)
WHERE v.id = 13335
WITH hv
ORDER BY hv.createDate DESC
OPTIONAL MATCH (hv)-[:CREATED_BY]->(u:User) WHERE true
WITH COLLECT({userId: u.id, historyValueId: hv.id, historyValue: hv.originalValue, historyValueDescription: hv.description, historyValueCreateDate: hv.createDate}) AS data, count(hv) as count, ceil(toFloat(count(hv)) / 100) as step
RETURN REDUCE(s = [], i IN RANGE(0, count - 1, CASE step WHEN 0 THEN 1 ELSE step END) | s + data[i]) AS result
On the cold Neo4j database during the first access, this query works very slow but the second and the subsequent calls work well.
This is PROFILE output:
Is there any way to improve this query performance(add appropriate indexes and so on)?
