本文介绍了Cypher FOREACH MERGE未达到指标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)

这非常慢,分析显示:

    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)上定义的索引

As you can see, it's apparently not using the index I've defined on :Tag(value)

有什么办法解决此问题吗?我的想法不多了,我开始认为这可能与 https://相关联github.com/neo4j/neo4j/issues/861

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

仅供参考,MERGE对我来说真的很方便,并且此查询与我提取数据所需的用法完全匹配(或者是否可行:).

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.

推荐答案

嗯,如果您使用UNWIND而不是FOREACH,它是否使用索引?

Hmmm, does it use an index if you use UNWIND instead of 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

这篇关于Cypher FOREACH MERGE未达到指标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 05:22