Domanda

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).

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top