在Titan中使用order()。by()时,索引不起作用

时间:2015-12-15 09:08:51

标签: titan tinkerpop3

The Titan documentation说:

  

混合索引支持本地和高效的排序。但是,order()。by()方法中使用的属性键必须先前已添加到用于本机结果排序支持的混合索引中。这在order()。by()键与查询键不同的情况下很重要。如果属性键不是索引的一部分,那么排序需要将所有结果加载到内存中。

所以,我在prop1属性上创建了一个混合索引。 {?1}}上的混合索引在指定值时效果很好。

prop1

但是,当我在gremlin> g.V().has('prop1', gt(1)) /* this gremlin uses the mixed index */ ==>v[6017120] ==>v[4907104] ==>v[8667232] ==>v[3854400] ... 上使用order().by()时,我无法利用混合索引。

prop1

同样gremlin> g.V().order().by('prop1', incr) /* doesn't use the mixed index */ 17:46:00 WARN com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx - Query requires iterating over all vertices [()]. For better performance, use indexes Could not execute query since pre-sorting requires fetching more than 1000000 elements. Consider rewriting the query to exploit sort orders 需要很长时间。

count()
如果我知道我的错误,我会很高兴的。这是我的泰坦信息:

  • Titan版本:1.0.0-hadoop1
  • 存储后端:Cassandra 2.1.1
  • 索引后端:ElasticSearch 1.7

谢谢。

1 个答案:

答案 0 :(得分:4)

您必须提供一个值以过滤要使用的索引。这里:

g.V().order().by('prop1', incr)

您没有提供任何过滤器,因此Titan必须迭代所有V(),然后应用排序。

下面:

g.V().has('prop1').count()

您提供了一个索引键,但没有指定要过滤的值,因此它仍在迭代所有V()。你可以这样做:

g.V().has("prop1", textRegex(".*")).count()

在这种情况下,你会把Titan搞砸一下,但如果该查询返回大量结果来迭代,查询仍然可能很慢。

相关问题