janusgraph icon indicating copy to clipboard operation
janusgraph copied to clipboard

Query edge by the range not use indexes.

Open denghaiai opened this issue 8 years ago • 8 comments

I tried to query data range like 'g.E().has('weight',P.gt(1000))' .I have already built the compositeIndex and mixedIndex , it can run but gremlin print ' WARN: org.janusgraph.graphdb.transaction.StandardJanusGraphTx - Query requires iterating over all vertices [(weight > 1000)]. For better performance , use indexes', and the query is very slow , How can i make the query faster?

denghaiai avatar Dec 11 '17 09:12 denghaiai

Can you profile your query with profile() ?

davidclement90 avatar Dec 11 '17 17:12 davidclement90

@denghaiai you need to provide a lot more information in order to get any help. Start with how you created the index, did you use the label only parameter? In which case you need to specify the label during querying. Is the index status active i.e REGISTERED, ENABLED, etc. Finally, use the profile() command as @davidclement90 explained to see what exactly is or isnt happening. Also, the JanusGraph user's group has many questions, answers, examples and discussions about indexes. You'd be better served closing this issue and asking there (search first you'd likely get your exact use case already answered.)

The-Don-Himself avatar Dec 11 '17 23:12 The-Don-Himself

That means you didn't build index successfully or you hadn't used the right index. I guess g.E().has('weight',P.gt(1000)) will iterate all vertices first, you're supposed to choose a start vertex ahead.

Query requires iterating over all vertices [(weight > 1000)].

CJSoldier avatar Dec 12 '17 02:12 CJSoldier

@CJSoldier Yes,When I used g.V(1212,2323).bothE().has('weight',P.gt(1000)) , the index can work. But When I query Edge by the range ,for example ' g.E().has('weight',P.gt(1000))' . The index can't work.the profile show the full scan is true.

denghaiai avatar Dec 12 '17 02:12 denghaiai

Your research by Vertex do not use your index either but you do not have the log because you do not use g.V() but g.V(id1,id2).

Can you check the status of your index ? What is the class of weight define by your schema ?

davidclement90 avatar Dec 12 '17 03:12 davidclement90

@davidclement90 Thanks for your response.The weight index status is enable . The weight dataType is java.lang.Long ,The property and index 's code as follow: weight=mgmt.makePropertyKey('weight'.dataType(Long.class)).make() mgmt.buildIndex( "weightCIndex", Edge.class ,addKey(weight).buildCompositeIndex() mgmt.buildIndex( "weightMIndex", Edge.class ,addKey(weight).buildMixedIndex('search') When i tried g.E().has('weight',P.eq(1000)) , the index is ok , but used g.E().has('weight',P.gt(1000)) or g.E().has('weight',P.lt(1000)) the index do not work.

denghaiai avatar Dec 12 '17 07:12 denghaiai

Ok Can you test without the composite index ?

davidclement90 avatar Dec 14 '17 04:12 davidclement90

Can not reproduce. Correct indexes are used. Make sure your indexes are enabled. If you had data existing prior to creating the indexes, you'll need to REINDEX - http://docs.janusgraph.org/latest/index-admin.html#reindex . Please reopen if you can provide steps to reproduce your issue.

Create schema

graph = JanusGraphFactory.open('conf/janusgraph-cassandra-es.properties')
mgmt = graph.openManagement()
weight=mgmt.makePropertyKey('weight').dataType(Long.class).make()
mgmt.buildIndex( "weightCIndex", Edge.class).addKey(weight).buildCompositeIndex()
mgmt.buildIndex( "weightMIndex", Edge.class).addKey(weight).buildMixedIndex('search')
mgmt.commit()
mgmt.awaitGraphIndexStatus(graph, "weightCIndex").status(SchemaStatus.REGISTERED, SchemaStatus.ENABLED).call()
mgmt.awaitGraphIndexStatus(graph, "weightMIndex").status(SchemaStatus.REGISTERED, SchemaStatus.ENABLED).call()

Add data

g = graph.traversal()
g.addV().as('a').addV().addE('oo').from('a').property('weight', 5)
g.tx().commit()

Query exact

gremlin> g.E().has('weight', 5)
==>e[sn-37c-36d-3bk][4152-oo->4304]
gremlin> g.E().has('weight', 5).profile()
==>Traversal Metrics
Step                                                               Count  Traversers       Time (ms)    % Dur
=============================================================================================================
JanusGraphStep([],[weight.eq(5)])                                      1           1           1.381   100.00
    \_condition=(weight = 5)
    \_isFitted=true
    \_query=multiKSQ[1]@2147483647
    \_index=weightCIndex
    \_orders=[]
    \_isOrdered=true
  optimization                                                                                 0.187
                                            >TOTAL                     -           -           1.381        -

Query range

gremlin> g.E().has('weight', gte(5))
==>e[sn-37c-36d-3bk][4152-oo->4304]
gremlin> g.E().has('weight', gte(5)).profile()
==>Traversal Metrics
Step                                                               Count  Traversers       Time (ms)    % Dur
=============================================================================================================
JanusGraphStep([],[weight.gte(5)])                                     1           1           0.585   100.00
    \_condition=(weight >= 5)
    \_isFitted=true
    \_query=[(weight >= 5)]:weightMIndex
    \_index=weightMIndex
    \_orders=[]
    \_isOrdered=true
    \_index_impl=search
  optimization                                                                                 0.173
                                            >TOTAL                     -           -           0.585        -

robertdale avatar Dec 14 '17 13:12 robertdale