【发布时间】:2015-02-18 08:52:24
【问题描述】:
我们使用带有 Persistit 的 Titan 作为后端,用于具有大约 100.000 个顶点的图。我们的用例非常复杂,但可以用一个简单的例子来说明当前的问题。假设我们在图中存储 Books 和 Authors。每个 Book 顶点都有一个 ISBN 号,对于整个图来说是唯一的。
我需要回答以下问题: 给我图表中所有图书的 ISBN 编号。
目前,我们正在这样做:
// retrieve graph instance
TitanGraph graph = getGraph();
// Start a Gremlin query (I omit the generics for brevity here)
GremlinPipeline gremlin = new GremlinPipeline().start(graph);
// get all vertices in the graph which represent books (we have author vertices, too!)
gremlin.V("type", "BOOK");
// the ISBN numbers are unique, so we use a Set here
Set<String> isbnNumbers = new HashSet<String>();
// iterate over the gremlin result and retrieve the vertex property
while(gremlin.hasNext()){
Vertex v = gremlin.next();
isbnNumbers.add(v.getProperty("ISBN"));
}
return isbnNumbers;
我的问题是:有没有更聪明的方法可以更快地做到这一点?我是 Gremlin 的新手,所以很可能我在这里做了一些非常愚蠢的事情。该查询目前需要 2.5 秒,这还不错,但如果可能的话,我想加快速度。请认为后端是固定的。
【问题讨论】: