在经过一些小修改后,我尝试了here给出的示例 - 主要是我添加了一个没有匹配的where子句 - 用于实验目的。
在我的系统上(1.9.M04 - java 6u43 - ubuntu 12.04 - AMD phenom II -X6 1090T)简单查询
数据库中只有1个节点(也是嵌入式的)需要262毫秒。显然出现了问题。可能是什么问题?
谢谢
public void test()
{
GraphDatabaseService db = g = new GraphDatabaseFactory().newEmbeddedDatabase("./neo4j1test" );
long id;
Transaction tx = db.beginTx();
try
{
Node refNode = db.createNode();
id = refNode.getId();
refNode.setProperty( "name", "reference node" );
tx.success();
}
finally
{
tx.finish();
}
ExecutionEngine engine = new ExecutionEngine( db );
ExecutionResult result = engine.execute( "start n=node("+id+") where ( n.name = \"reference node\") return n.name" );
long time = System.currentTimeMillis();
result = engine.execute( "start n=node("+id+") where ( n.name = \"reference node\") return n.name" );
time = (System.currentTimeMillis() - time);
System.out.println("Time taken : " + time + " ms.");
}
答案 0 :(得分:0)
您可能希望索引您的name属性(请参阅indexing)。之后,您可以这样查询:
START n=node:your_index_name("name:the_indexed_name") RETURN n;
通过索引查找节点比通过WHERE子句进行过滤要快得多。
答案 1 :(得分:0)
我与Cypher查询技术有类似的问题。处理Cypher声明性查询的开销导致性能不佳。我同意你的看法,开销是不允许的。
我们应该使用Core Java API来充分利用neo4j。
请参阅此文章:Get the full neo4j power by using the Core Java API
而且:Performance of Graph Query Languages: Comparison of Cypher, Gremlin and Native Access in Neo4j