thinkaurelius / titan

Distributed Graph Database
http://titandb.io
Apache License 2.0
5.25k stars 1.01k forks source link

Traversal with "withPath()" does not use index #1361

Open bdighe opened 7 years ago

bdighe commented 7 years ago

I am observing, when withPath() is used, it does not make use of index. Anything I am missing here?

gremlin> titanMgmt.getGraphIndex("by_name").getFieldKeys();
==>name
    public static void main(String[] args) {
        BaseConfiguration conf = new BaseConfiguration();
        conf.setProperty("storage.backend", "cassandra");
        conf.setProperty("storage.hostname", "localhost");
        conf.setProperty("storage.port", 9160);
        conf.setProperty("cache.db-cache", false);
        conf.setProperty("storage.cassandra.keyspace", "my_ks");

        @SuppressWarnings("resource")
        TitanGraph graph = TitanFactory.open(conf);

        System.out.println("Without withPath() ..");
        System.out.println(graph.traversal().V().has("name", "xyz").count().next().longValue());
        System.out.println("with withPath() ..");
        System.out.println(graph.traversal().withPath().V().has("name", "xyz").count().next().longValue());

        graph.close();
    }

Output: Without withPath() .. 5 with withPath() .. 22:04:54,236 WARN StandardTitanTx:1262 - Query requires iterating over all vertices [()]. For better performance, use indexes 22:04:54,246 INFO ThriftKeyspaceImpl:745 - Detected partitioner org.apache.cassandra.dht.Murmur3Partitioner for keyspace my_ks 5

bdighe commented 7 years ago

t seems like a bug in titan-core/src/main/java/com/thinkaurelius/titan/graphdb/tinkerpop/optimize/HasStepFolder.java

When we use withPath(), the PathIdentityStep gets added to the Traverser before HasStep. But HasStepFolder.foldInHasContainer does not skip it, it does it for IdentityStep but not for PathIdentityStep. Since no HasContainer is added to translated TitanSteps, titan does not create index query.

I added highlighted code below and it resolves the issue.

It will be good if Titan experts can look at it and confirm if its a right fix.

bdighe commented 7 years ago

Should I create a pull request for this change? Would I need special permissions to push to this repository?

Thanks Bharat

sharpau commented 7 years ago

Your contribution might get more attention at https://github.com/JanusGraph/janusgraph