简体   繁体   English

ArangoDB在遍历期间不使用索引

[英]ArangoDB Not Using Index During Traversal

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

The 'Edge' edge collection has a hash index defined for attributes ModelType, TargetType, SourceType, in that order. “Edge”边集合具有按顺序为属性ModelType,TargetType,SourceType定义的哈希索引。

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. 请注意,执行计划表明不会使用任何索引来处理查询。

Is there anything I need to do to make the engine use the index on the Edge collection to process the results? 我需要做些什么来让引擎使用Edge集合上的索引来处理结果吗?

Thanks 谢谢

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.0中,遍历将始终使用边索引来查找连接的顶点,无论查询中存在哪些过滤条件,也不管存在哪些索引。

In ArangoDB 3.1 the optimizer will try to find the best possible index for each level of the traversal. 在ArangoDB 3.1中,优化器将尝试为每个遍历级别找到最佳索引。 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. 如果边缘属性上存在过滤条件,并且索引具有比边缘索引更好的估计平均选择性,则将使用其他索引。

In 3.1.0 the explain output will always show "Indexes used: none" for traversals, even though a traversal will always use an index. 在3.1.0中,解释输出将始终显示“使用的索引:无”用于遍历,即使遍历将始终使用索引。 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. 这已在ArangoDB 3.1.1中修复,它将显示优化程序为每个遍历级别选择的各个索引。

For example, the following query shows the following explain output in 3.1: 例如,以下查询显示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

Additional indexes are present on [ "_to", "type" ] and [ "_from", "type" ] . 附加索引存在于[ "_to", "type" ][ "_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. 这些用于遍历的级别0和级别2,因为这些级别上的边缘存在可以使用这些索引的过滤条件。 For all other levels, the traversal will use the indexes labeled with "base" in the "Ranges" column. 对于所有其他级别,遍历将使用“范围”列中标有“base”的索引。

The explain output fix will become available with 3.1.1, which will be released soon. 解释输出修复程序将随3.1.1一起提供,将很快发布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM