I've got a following parametrized Cypher query:
MERGE (p:Person {pid: {personId}}) ON CREATE SET p.value=rand()
MERGE (c:Page {url: {pageUrl}}) ON CREATE SET c.value=rand()
MERGE p-[:REL]->c
FOREACH (tagValue IN {tags} |
MERGE (t:Tag {value:tagValue})
MERGE c-[:hasTag]->t)
This is very slow, the profiling shows:
EmptyResult
|
+UpdateGraph(0)
|
+Eager(0)
|
+UpdateGraph(1)
|
+Eager(1)
|
+UpdateGraph(2)
+----------------+------+--------+------------------------------+------------------------------------------------------------------------------+
| Operator | Rows | DbHits | Identifiers | Other |
+----------------+------+--------+------------------------------+------------------------------------------------------------------------------+
| EmptyResult | 0 | 0 | | |
| UpdateGraph(0) | 1 | 79222 | | Foreach |
| Eager(0) | 1 | 0 | | |
| UpdateGraph(1) | 1 | 5 | p, c, UNNAMED163 | MergePattern |
| Eager(1) | 1 | 0 | | |
| UpdateGraph(2) | 1 | 14 | p, p, c, c |
MergeNode; {personId}; :Person(pid); MergeNode; {pageUrl}; :Page(url) |
+----------------+------+--------+------------------------------+------------------------------------------------------------------------------+
Total database accesses: 79241
As you can see, it's apparently not using the index I've defined on :Tag(value)
Any ideas how to fix this? I'm running out of ideas and I'm starting to think this might be connected to https://github.com/neo4j/neo4j/issues/861
FYI, the MERGEs are really convenient for me and this query perfectly matches (or would if it worked:) the usage I need for data ingestion.
Hmmm, does it use an index if you use UNWIND instead of FOREACH?