ArangoDB在遍历期间不使用索引 [英] ArangoDB Not Using Index During Traversal

查看:154
本文介绍了ArangoDB在遍历期间不使用索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的图形遍历查询:

I have a simple graph traversal query:

FOR e in 0..3 ANY 'Node/5025926' Edge
FILTER 

e.ModelType == "A.Model" && 
e.TargetType == "A.Target" && 
e.SourceType == "A.Source"

RETURN e

边缘"边缘集合具有为属性ModelType,TargetType,SourceType依次定义的哈希索引.

The 'Edge' edge collection has a hash index defined for attributes ModelType, TargetType, SourceType, in that order.

检查执行计划时,结果为:

When checking the execution plan, the results are:

Query string:
 FOR e in 0..3 ANY 'Node/5025926' Edge
 FILTER 
 e.ModelType == "A.Model" && 
 e.TargetType == "A.Target" && 
 e.SourceType == "A.Source"
 RETURN e

Execution plan:
 Id   NodeType          Est.   Comment
  1   SingletonNode        1   * ROOT
  2   TraversalNode        7     - FOR e  /* vertex */ IN 0..3  /* min..maxPathDepth */ ANY 'Node/5025926' /* startnode */  Edge
  3   CalculationNode      7     - LET #1 = (((e.`ModelType` == "A.Model") && (e.`TargetType` == "A.Target")) && (e.`SourceType` == "A.Source"))   /* simple expression */
  4   FilterNode           7     - FILTER #1
  5   ReturnNode           7     - RETURN e

Indexes used:
 none

Traversals on graphs:
 Id   Depth   Vertex collections   Edge collections   Filter conditions
  2   0..3                         Edge               

Optimization rules applied:
 none

请注意,执行计划表明不会使用任何索引来处理查询.

Notice that the execution plan indicates that no indices will be used to process the query.

我需要做些什么来使引擎使用Edge集合上的索引来处理结果吗?

Is there anything I need to do to make the engine use the index on the Edge collection to process the results?

谢谢

推荐答案

在ArangoDB 3.0中,遍历将始终使用边索引来查找连接的顶点,而不管查询中存在哪些过滤条件和存在哪些索引.

In ArangoDB 3.0 a traversal will always use the edge index to find connected vertices, regardless of which filter conditions are present in the query and regardless of which indexes exist.

在ArangoDB 3.1中,优化器将尝试为遍历的每个级别找到最佳的索引.它将检查遍历的筛选条件,并为每个级别选择其估计最低成本的索引.如果没有用户定义的索引,它将仍然使用边索引来查找连接的顶点.如果在边缘属性上存在过滤条件且也对其进行了索引,并且该索引具有比边缘索引更好的估计平均选择性,则将使用其他索引.

In ArangoDB 3.1 the optimizer will try to find the best possible index for each level of the traversal. It will inspect the traversal's filter condition and for each level pick the index for which it estimates the lowest cost. If there are no user-defined indexes, it will still use the edge index to find connected vertices. Other indexes will be used if there are filter conditions on edge attributes which are also indexed and the index has a better estimated average selectivity than the edge index.

在3.1.0中,即使遍历将始终使用索引,对于遍历,explain输出也将始终显示使用的索引:无".在说明输出中仅缺少索引显示.该问题已在ArangoDB 3.1.1中修复,它将显示优化程序为遍历的每个级别选择的各个索引.

In 3.1.0 the explain output will always show "Indexes used: none" for traversals, even though a traversal will always use an index. The index display is just missing in the explain output. This has been fixed in ArangoDB 3.1.1, which will show the individual indexes selected by the optimizer for each level of the traversal.

例如,以下查询在3.1中显示以下解释输出:

For example, the following query shows the following explain output in 3.1:

Query string:
 FOR v, e, p in 0..3 ANY 'v/test0' e 
   FILTER p.edges[0].type == 1 && p.edges[2].type == 2 
   RETURN p.vertices 

Execution plan:
 Id   NodeType          Est.   Comment
  1   SingletonNode        1   * ROOT
  2   TraversalNode     8000     - FOR v  /* vertex */, p  /* paths */ IN 0..3  /* min..maxPathDepth */ ANY 'v/test0' /* startnode */  e
  3   CalculationNode   8000     - LET #5 = ((p.`edges`[0].`type` == 1) && (p.`edges`[2].`type` == 2))   /* simple expression */
  4   FilterNode        8000     - FILTER #5
  5   CalculationNode   8000     - LET #7 = p.`vertices`   /* attribute expression */
  6   ReturnNode        8000     - RETURN #7

Indexes used:
 By   Type   Collection   Unique   Sparse   Selectivity   Fields                Ranges
  2   edge   e            false    false        10.00 %   [ `_from`, `_to` ]    base INBOUND
  2   edge   e            false    false        10.00 %   [ `_from`, `_to` ]    base OUTBOUND
  2   hash   e            false    false        63.60 %   [ `_to`, `type` ]     level 0 INBOUND
  2   hash   e            false    false        64.40 %   [ `_from`, `type` ]   level 0 OUTBOUND
  2   hash   e            false    false        63.60 %   [ `_to`, `type` ]     level 2 INBOUND
  2   hash   e            false    false        64.40 %   [ `_from`, `type` ]   level 2 OUTBOUND

其他索引位于[ "_to", "type" ][ "_from", "type" ]上.这些用于遍历的级别0和2,因为这些级别上的边缘存在可以使用这些索引的过滤条件.对于所有其他级别,遍历将使用范围"列中标有基本"的索引.

Additional indexes are present on [ "_to", "type" ] and [ "_from", "type" ]. Those are used on levels 0 and 2 of the traversal because there are filter conditions for the edges on these levels that can use these indexes. For all other levels, the traversal will use the indexes labeled with "base" in the "Ranges" column.

说明输出修复程序将随3.1.1一起提供,该版本将很快发布.

The explain output fix will become available with 3.1.1, which will be released soon.

这篇关于ArangoDB在遍历期间不使用索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆