简体   繁体   English

ArangoDB图形遍历不使用组合索引

[英]ArangoDB graph traversal not utilizing combined index

I have those two queries, which should - based on my understanding - do basically the same. 我有这两个查询,根据我的理解,这两个查询应该基本相同。 One is doing a filter on my edge collection and is performing very well, while the other query is doing a graph traversal of depth 1 and performs quite poor, due to not utilizing the correct index. 一个正在对我的边缘集合进行过滤,并且效果非常好,而另一个查询由于未利用正确的索引而正在深度1的图形遍历,并且效果很差。

I have an accounts collection and a transfers collection and a combined index on transfers._to and transfers.quantity . 我有一个accounts集合和一个transfers集合,以及一个对transfers._totransfers.quantity的合并索引。

This is the filter query: 这是过滤器查询:

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

Which is correctly using the combined index: 哪个正确使用了组合索引:

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

On the other hand this is my graph traversal query: 另一方面,这是我的图形遍历查询:

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

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

Which only uses _to from the combined index for filtering the inbound edges, but fails to utilize quantity : 它仅使用组合索引中的_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

However, as I want to use the graph traversal, is there a way to utilize this combined index correctly? 但是,由于我要使用图遍历,有没有办法正确利用此组合索引?

Edit: I'm using ArangoDB 3.4.2 编辑:我正在使用ArangoDB 3.4.2

Vertex centric indexes (indexes that are created on an edge and include either the '_from' or the '_to' properties) are normally used in traversals when the filtering is done on the path rather than the edge itself. 顶点中心索引(在边缘上创建并包括'_from'或'_to'属性的索引)通常在遍历时使用遍历,而不是在边缘本身上进行遍历。 ( assuming the optimizer does not find a better plan of course) (假设优化器当然找不到更好的计划)

So in your query, try something like the following: 因此,在您的查询中,尝试执行以下操作:

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

You can find the docs about this index type here 您可以在此处找到有关此索引类型的文档

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

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