TitanDB not using indexes for query

本秂侑毒 提交于 2020-01-03 01:51:22

问题


I have created indexes on two properties:

mgmt.buildIndex("userId", Vertex.class).addKey(mgmt.makePropertyKey("userId").dataType(Integer.class).make()).buildCompositeIndex();

mgmt.buildIndex("firstNameIndex", Vertex.class).addKey(mgmt.makePropertyKey("firstName").dataType(String.class).make()).buildCompositeIndex();

On Gremlin shell i can see the indexes have been created:

g.getIndexedKeys(Vertex.class)
==>userId
==>firstName

Now when i so query on vertices like simplest one:

gremlin> g.V()
18:33:42 WARN  com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx  - Query requires iterating over all vertices [()]. For better performance, use indexes
==>v[512]
==>v[256]

Or some complex one:

gremlin> g.V.has('firstName' ,CONTAINS,'Raj')
18:36:00 WARN  com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx  - Query requires iterating over all vertices [(firstName CONTAINS Raj)]. For better performance, use indexes
==>v[512]

Why its not using indexes for query.??

And is there any difference between creation of indexes and key indexes.? Any Explanation will be helpful.

Thanks


回答1:


Based on http://s3.thinkaurelius.com/docs/titan/1.0.0/indexes.html#index-mixed

Use a composite index for exact match index retrievals. Composite indexes do not require configuring or operating an external index system and are often significantly faster than mixed indexes.

As an exception, use a mixed index for exact matches when the number of distinct values for query constraint is relatively small or if one value is expected to be associated with many elements in the graph (i.e. in case of low selectivity). Use a mixed indexes for numeric range, full-text or geo-spatial indexing. Also, using a mixed index can speed up the order().by() queries.

In your case that it seems you are doing a full text search you need to use a mixed index, since composite ones are only used for exact matches.

You can find more info about full text search indices in: http://s3.thinkaurelius.com/docs/titan/1.0.0/index-parameters.html#_full_text_search

I don't see anywhere any difference between indices and key indices. Vertex-centric indices are different than property/key indices. Have a look at the link I provided. Hope this helps!



来源:https://stackoverflow.com/questions/33303123/titandb-not-using-indexes-for-query

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