Neo4j功能或搜索查询的错误?

时间:2015-09-15 06:24:16

标签: neo4j cypher

我最近将neo4j从2.1.7更新到2.2.5。我发现了那个查询

Match (c:C) where id(c) = 111 with c Match (p:I{id: c.id}) return count(p)

在2.1.7中运行良好,但在2.2.5(100倍长)中表现很差。我有所需的所有索引。 我将此查询修改为

Match (c:C) where id(c) = 111 with c.id as c_id Match (p:I{id: c_id}) return count(p)

在此之后它在2.2.5中正常工作 这两个查询有不同的配置文件。但我对分析并不十分满意。

已更新 更奇怪的是,如果我使用explain而不是profile - 它可以快速运行。

neo4j-sh (?)$ PROFILE Match (c:C) where id(c) = 10563822 with c Match (i:I{id: c.id}) return count(i);
==> +----------+
==> | count(i) |
==> +----------+
==> | 4551     |
==> +----------+
==> 1 row
==> 18257 ms
==> 
==> Compiler CYPHER 2.2
==> 
==> Planner COST
==> 
==> EagerAggregation
==>   |
==>   +Filter(0)
==>     |
==>     +CartesianProduct
==>       |
==>       +Filter(1)
==>       |  |
==>       |  +NodeByIdSeek
==>       |
==>       +NodeByLabelScan
==> 
==> +------------------+---------------+---------+---------+-------------+-------------------------+
==> |         Operator | EstimatedRows |    Rows |  DbHits | Identifiers |                   Other |
==> +------------------+---------------+---------+---------+-------------+-------------------------+
==> | EagerAggregation |            26 |       1 |       0 |    count(i) |                         |
==> |        Filter(0) |           652 |    4551 | 2522988 |        c, i |            i.id == c.id |
==> | CartesianProduct |          6521 | 1261494 |       0 |        c, i |                         |
==> |        Filter(1) |             0 |       1 |       1 |           c |                     c:C |
==> |     NodeByIdSeek |             1 |       1 |       1 |           c |                         |
==> |  NodeByLabelScan |       1261494 | 1261494 | 1261495 |           i |                      :I |
==> +------------------+---------------+---------+---------+-------------+-------------------------+
==> 
==> Total database accesses: 3784485

sh (?)$ PROFILE Match (c:C) where id(c) = 10563822 with c.id as c_id Match (i:I{id: c_id}) return count(i);
==> +----------+
==> | count(i) |
==> +----------+
==> | 4551     |
==> +----------+
==> 1 row
==> 64 ms
==> 
==> Compiler CYPHER 2.2
==> 
==> Planner COST
==> 
==> EagerAggregation
==>   |
==>   +Apply
==>     |
==>     +Projection
==>     |  |
==>     |  +Filter
==>     |    |
==>     |    +NodeByIdSeek
==>     |
==>     +NodeIndexSeek
==> 
==> +------------------+---------------+------+--------+-------------+---------------------+
==> |         Operator | EstimatedRows | Rows | DbHits | Identifiers |               Other |
==> +------------------+---------------+------+--------+-------------+---------------------+
==> | EagerAggregation |             1 |    1 |      0 |    count(i) |                     |
==> |            Apply |             1 | 4551 |      0 |  c, c_id, i |                     |
==> |       Projection |             0 |    1 |      1 |     c, c_id |                c.id |
==> |           Filter |             0 |    1 |      1 |           c |                 c:C |
==> |     NodeByIdSeek |             1 |    1 |      1 |           c |                     |
==> |    NodeIndexSeek |             1 | 4551 |   4552 |           i |              :I(id) |
==> +------------------+---------------+------+--------+-------------+---------------------+
==> 
==> Total database accesses: 4555

1 个答案:

答案 0 :(得分:0)

我没有足够的neo4j内部知识知道为什么你的查询在较新的版本中较慢(CartesianProduct步骤似乎是一个红色标志),但这里是一个逻辑上等效的查询,似乎它应该要快得多:

START c = node(111)
MATCH (p:I { id: c.id })
RETURN count(p)

以下是个人资料:

+------------------+------+--------+----------------------------------------------------------+-----------------------+
|         Operator | Rows | DbHits |                                              Identifiers |                 Other |
+------------------+------+--------+----------------------------------------------------------+-----------------------+
|     ColumnFilter |    1 |      0 |                                                 count(p) | keep columns count(p) |
| EagerAggregation |    1 |      0 |   INTERNAL_AGGREGATE51b25e53-027d-439b-9046-c1a2a6b0fe70 |                       |
|           Filter |    0 |      0 |                                                     c, p |          p.id == c.id |
|         NodeById |    0 |      0 |                                                     c, p |    Literal(List(111)) |
|      NodeByLabel |    0 |      1 |                                                        p |                    :I |
+------------------+------+--------+----------------------------------------------------------+-----------------------+

注意:这应该被视为一种临时解决方法,因为START已被弃用,我不知道这种用法将继续得到多长时间的支持。