neo4j cypher使用嵌套括号查询速度很慢

时间:2014-04-02 11:20:34

标签: performance neo4j cypher spring-data-neo4j

当使用cypher查询neo4j时,我尝试过2次查询

慢查询

neo4j-sh (0)$ CYPHER 1.9 START entity=node:`PimDomainIndex_HFDgOXRJjq.nl_ed1`("*:*") WHERE (((((has(entity.str) and entity.str=~'(?i).*Q1E.*') and  (has(entity.`1_to_3`) and entity.`1_to_3`=1)) and  (has(entity.nr) and entity.nr=1)) and  (has(entity.`1_to_2`) and entity.`1_to_2`=~'(?i).*Q1E.*')) and  (has(entity.b) and entity.b="true")) and  (has(entity.nr) and entity.date<=1427666400000) RETURN count(DISTINCT entity);
==> +------------------------+
==> | count(DISTINCT entity) |
==> +------------------------+
==> | 0                      |
==> +------------------------+
==> 1 row
==> 
==> 328954 ms

配置文件:

==> ColumnFilter(symKeys=["  INTERNAL_AGGREGATE498258e2-ee6d-4959-8259-4fa1fad3eb11"], returnItemNames=["count(DISTINCT entity)"], _rows=1, _db_hits=0)
==> EagerAggregation(keys=[], aggregates=["(  INTERNAL_AGGREGATE498258e2-ee6d-4959-8259-4fa1fad3eb11,Distinct)"], _rows=1, _db_hits=0)
==>   Filter(pred="(((((((((((hasProp(str) AND LiteralRegularExpression) AND hasProp(1_to_3)) AND Property == Literal) AND hasProp(nr)) AND Property == Literal) AND hasProp(1_to_2)) AND LiteralRegularExpression) AND hasProp(b)) AND Property == Literal) AND hasProp(nr)) AND Property <= Literal)", _rows=0, _db_hits=6)
==>     Nodes(name="entity", _rows=3, _db_hits=3)
==>       ParameterPipe(_rows=1, _db_hits=0)

快速查询

neo4j-sh (0)$ CYPHER 1.9 START entity=node:`DomainIndex_HFDgOXRJjq.nl_ed1`("*:*")  WITH entity  WHERE (has(entity.str) and entity.str=~'(?i).*Q1E.*') and  (has(entity.`1_to_3`) and entity.`1_to_3`=1) and  (has(entity.nr) and entity.nr=1) and  (has(entity.`1_to_2`) and entity.`1_to_2`=~'(?i).*Q1E.*') and  (has(entity.b) and entity.b="true") and  (has(entity.nr) and entity.date<=1427666400000) WITH entity RETURN count(DISTINCT entity);
==> +------------------------+
==> | count(DISTINCT entity) |
==> +------------------------+
==> | 0                      |
==> +------------------------+
==> 1 row
==> 
==> 1786 ms

资料

==> ColumnFilter(symKeys=["  INTERNAL_AGGREGATE54528d13-254e-4914-b260-26b9f09fcc36"], returnItemNames=["count(DISTINCT entity)"], _rows=1, _db_hits=0)
==> EagerAggregation(keys=[], aggregates=["(  INTERNAL_AGGREGATE54528d13-254e-4914-b260-26b9f09fcc36,Distinct)"], _rows=1, _db_hits=0)
==>   Filter(pred="(((((((((((hasProp(str) AND LiteralRegularExpression) AND hasProp(1_to_3)) AND Property == Literal) AND hasProp(nr)) AND Property == Literal) AND hasProp(1_to_2)) AND LiteralRegularExpression) AND hasProp(b)) AND Property == Literal) AND hasProp(nr)) AND Property <= Literal)", _rows=0, _db_hits=6)
==>     Nodes(name="entity", _rows=3, _db_hits=3)
==>       ParameterPipe(_rows=1, _db_hits=0)

两个查询之间的唯一区别是使用“(”,“)”括号, 括号是未来业务逻辑所必需的,但性能是一个主要问题。

索引包含~3个节点,测试数据库只包含~15个节点。

==> | Node[13]{nr:2.0,date:1393459200000,str:"2"}         |
==> | Node[14]{b:false,nr:3.0,date:1393804800000,str:"3"} |
==> | Node[15]{b:true,nr:1.0,date:1392163200000,str:"1"}  |

使用括号时主要性能下降的原因是什么?如何解决?

0 个答案:

没有答案