Cypher FOREACH MERGE没有达到指数

时间:2014-11-10 21:44:03

标签: neo4j cypher

我有一个以下参数化的Cypher查询:

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)

这很慢,分析显示:

    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

正如您所看到的,它显然没有使用我定义的索引:Tag(value)

任何想法如何解决这个问题?我已经没有想法了,我开始认为这可能与https://github.com/neo4j/neo4j/issues/861

相关联

仅供参考,MERGE对我来说非常方便,这个查询完全匹配(或者如果它有效:)我需要用于数据摄取。

1 个答案:

答案 0 :(得分:3)

嗯,如果你使用UNWIND而不是FOREACH,它会使用索引吗?

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
WITH c
UNWIND {tags} AS tagValue
MERGE (t:Tag {value:tagValue})
MERGE c-[:hasTag]->t