Titan Warning: Query requires iterating over all vertices

▼魔方 西西 提交于 2020-01-24 19:12:03

问题


Below I am adding cdate index and then some data:

    baseGraph.makeKey("cdate").dataType(Long.class).indexed(Vertex.class).make();

    for(int i=0;i<20;i++){
        Vertex page = g.addVertex("P0"+i);            
        page.setProperty("cdate", new Date().getTime());
        page.setProperty("pName","pName-P0"+i);
        Edge e =g.addEdge(null, user, page, "created");
        e.setProperty("time", i);
        Thread.sleep(2000);
    }


    for(int i=20;i<25;i++){
        Vertex page = g.addVertex("P0"+i);
        page.setProperty("cdate", new Date().getTime());
        page.setProperty("pName","pName-P0"+i);
        Edge e =g.addEdge(null, user, page, "notcreated");
        e.setProperty("time", i);
        Thread.sleep(2000);
    }
g.commit();

Now when I run following query:

Iterable<Vertex> vertices = g.query().interval("cdate",0,time).
             orderBy("cdate", Order.DESC).limit(5).vertices(); 

It gives the output in correct order but It shows:

WARN  com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx  - 
Query requires iterating over all vertices [(cdate >= 0 AND cdate < 1392198350796)].
For better performance, use indexes

But I have already defined cdate as index (see top line).


回答1:


In your type definition for cdate you are using Titan's standard index (by not specifying any other index). Titan's standard index only supports equality comparisons (i.e. no range queries).

To get support for range queries, you need to use an indexing backend that must be registered with Titan and then explicitly reference it in the type definition.

Check out the documentation on this page Chapter 8. Indexing for better Performance:

Titan supports two different kinds of indexing to speed up query processing: graph indexes and vertex-centric indexes. Most graph queries start the traversal from a list of vertices or edges that are identified by their properties. Graph indexes make these global retrieval operations efficient on large graphs. Vertex-centric indexes speed up the actual traversal through the graph, in particular when traversing through vertices with many incident edges.

Bottom line: Titan supports multiple types of indexes and it automatically picks the most suitable index to answer a particular query. In your case, there is none that supports range queries, hence the warning and slow performance. The documentation above outlines how to register additional indexes that provide the support you need.



来源:https://stackoverflow.com/questions/21725758/titan-warning-query-requires-iterating-over-all-vertices

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!