我正在运行 Neo4j Desktop v1.4.1,数据库是 4.2.1 企业版。
我有一个展示位置、活动和展示位置与活动“包含”关系的简单图表。这是一个新的数据集,每个节点都是唯一的。一些展示位置“包含”数千个广告系列,因此我想通过广告系列 ID 的包含列表过滤返回的广告系列。
当我返回所有匹配的节点时,它可以工作:
neo4j@neo4j> MATCH (:Placement {id: 5})-[:CONTAINS]->(c:Campaign)
WHERE c.id IN [400,263,150470,25810,37578]
RETURN *;
+--------------------------+
| c |
+--------------------------+
| (:Campaign {id: 37578}) |
| (:Campaign {id: 263}) |
| (:Campaign {id: 25810}) |
| (:Campaign {id: 150470}) |
+--------------------------+
当我只请求活动:id 时,我得到重复:
neo4j@neo4j> MATCH (:Placement {id: 5})-[:CONTAINS]->(c:Campaign)
WHERE c.id IN [400,263,150470,25810,37578]
RETURN c.id;
+--------+
| c.id |
+--------+
| 150470 |
| 150470 |
| 150470 |
| 150470 |
+--------+
展示位置 5 和广告系列 15070 之间只有一个 CONTAINS 关系:
neo4j@neo4j> MATCH (:Placement {id: 5})-[rel:CONTAINS]->(:Campaign {id:150470})
RETURN count(rel);
+------------+
| count(rel) |
+------------+
| 1 |
+------------+
EXPLAIN 返回以下查询计划,cache[c.id]
似乎它可能是罪魁祸首?
+---------------------------+------------------------------------------------------------------------------------------------------+----------------+---------------------+
| Operator | Details | Estimated Rows | Other |
+---------------------------+------------------------------------------------------------------------------------------------------+----------------+---------------------+
| +ProduceResults@neo4j | `c.id` | 4 | Fused in Pipeline 1 |
| | +------------------------------------------------------------------------------------------------------+----------------+---------------------+
| +Projection@neo4j | cache[c.id] AS `c.id` | 4 | Fused in Pipeline 1 |
| | +------------------------------------------------------------------------------------------------------+----------------+---------------------+
| +Expand(Into)@neo4j | (anon_7)-[anon_27:CONTAINS]->(c) | 4 | Fused in Pipeline 1 |
| | +------------------------------------------------------------------------------------------------------+----------------+---------------------+
| +MultiNodeIndexSeek@neo4j | UNIQUE anon_7:Placement(id) WHERE id = $autoint_0, cache[c.id], UNIQUE c:Campaign(id) WHERE id IN $a | 25 | In Pipeline 0 |
| | utolist_1, cache[c.id] | | |
+---------------------------+------------------------------------------------------------------------------------------------------+----------------+---------------------+
编辑:如果我在查询前加上CYPHER runtime=SLOTTED
我得到预期的输出:
+--------+
| c.id |
+--------+
| 37578 |
| 263 |
| 25810 |
| 150470 |
+--------+
如果我省略 WHERE 子句,我会得到唯一的广告系列 ID(但太多)。我觉得我遗漏了一些明显的东西,但我已经阅读了 neo4j 文档但我没有得到它。谢谢!