【问题标题】:ArangoDB graph traversal not utilizing combined indexArangoDB 图遍历不使用组合索引
【发布时间】:2019-06-14 16:56:20
【问题描述】:

我有这两个查询,根据我的理解,它们应该基本相同。一个正在对我的边缘集合进行过滤并且性能非常好,而另一个查询正在执行深度为 1 的图形遍历并且由于没有使用正确的索引而性能很差。

我有一个accounts 集合和一个transfers 集合以及transfers._totransfers.quantity 的组合索引。

这是过滤器查询:

 FOR transfer IN transfers  
    FILTER transfer._to == "accounts/testaccount" && transfer.quantity > 100
    RETURN transfer

哪个是正确使用组合索引:

Execution plan:
 Id   NodeType            Est.   Comment
  1   SingletonNode          1   * ROOT
  6   IndexNode       18930267     - FOR transfer IN transfers   /* skiplist index scan */
  5   ReturnNode      18930267       - RETURN transfer

Indexes used:
 By   Type       Collection   Unique   Sparse   Selectivity   Fields                  Ranges
  6   skiplist   transfers    false    false        10.11 %   [ `_to`, `quantity` ]   ((transfer.`_to` == "accounts/testaccount") && (transfer.`quantity` > 100))

Optimization rules applied:
 Id   RuleName
  1   use-indexes
  2   remove-filter-covered-by-index
  3   remove-unnecessary-calculations-2

另一方面,这是我的图遍历查询:

 FOR account IN accounts
     FILTER account._id == "accounts/testaccount"

     FOR v, e IN 1..1 INBOUND account transfers
         FILTER e.quantity > 100
         RETURN e

仅使用组合索引中的_to 过滤入站边缘,但未能使用quantity

Execution plan:
 Id   NodeType          Est.   Comment
  1   SingletonNode        1   * ROOT
  9   IndexNode            1     - FOR account IN accounts   /* primary index scan */
  5   TraversalNode        9       - FOR v  /* vertex */, e  /* edge */ IN 1..1  /* min..maxPathDepth */ INBOUND account /* startnode */  transfers
  6   CalculationNode      9         - LET #7 = (e.`quantity` > 100)   /* simple expression */
  7   FilterNode           9         - FILTER #7
  8   ReturnNode           9         - RETURN e

Indexes used:
 By   Type       Collection   Unique   Sparse   Selectivity   Fields                  Ranges
  9   primary    accounts     true     false       100.00 %   [ `_key` ]              (account.`_id` == "accounts/testaccount")
  5   skiplist   transfers    false    false            n/a   [ `_to`, `quantity` ]   base INBOUND

Traversals on graphs:
 Id   Depth   Vertex collections   Edge collections   Options                                   Filter conditions
  5   1..1                         transfers          uniqueVertices: none, uniqueEdges: path   

Optimization rules applied:
 Id   RuleName
  1   use-indexes
  2   remove-filter-covered-by-index
  3   remove-unnecessary-calculations-2

但是,由于我想使用图遍历,有没有办法正确利用这个组合索引?

编辑:我正在使用 ArangoDB 3.4.2

【问题讨论】:

    标签: arangodb aql


    【解决方案1】:

    以顶点为中心的索引(在边上创建并包含“_from”或“_to”属性的索引)通常用于在路径上而不是边本身上进行过滤时的遍历。 (当然假设优化器没有找到更好的方案)

    因此,在您的查询中,请尝试以下操作:

    FOR account IN accounts
     FILTER account._id == "accounts/testaccount"
       FOR v, e IN 1..1 INBOUND account transfers
       FILTER p.edges[*].quantity ALL > 100
    RETURN e
    

    你可以找到关于这个索引类型的文档here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-04
      • 1970-01-01
      相关资源
      最近更新 更多