Join Arangodb连接查询优化

Join Arangodb连接查询优化,join,arangodb,aql,Join,Arangodb,Aql,问题: 在数据库中,每个集合中有3个集合,包含10,00000个文档,每个文档中的属性数为150,并且在每个集合中,“ID”属性是唯一的哈希索引 现在我想合并所有集合并返回文档,其中“ID”在所有集合中都是匹配项 例如: 集合1包含文档{“id”:1,“firstname”:“alex”,“gender”:“male”} 集合2包含文档{“id”:1,“middlename”:“wilson”,“age”:23} 集合3包含文档{“id”:1,“lastname”,“alive”:true} 所

问题: 在数据库中,每个集合中有3个集合,包含10,00000个文档,每个文档中的属性数为150,并且在每个集合中,“ID”属性是唯一的哈希索引

现在我想合并所有集合并返回文档,其中“ID”在所有集合中都是匹配项

例如: 集合1包含文档
{“id”:1,“firstname”:“alex”,“gender”:“male”}
集合2包含文档
{“id”:1,“middlename”:“wilson”,“age”:23}
集合3包含文档
{“id”:1,“lastname”,“alive”:true}

所以我想像这样返回文档
{“id”:1,“firstname”:“alex”,“gender”:“male”,“middlename”:“wilson”,“age”:23,“lastname”,“alive”:true}

查询工作正常,并给了我预期的结果,但在大量收集中花费了太多的时间,所以我想知道任何其他方法来编写查询,或者在我的aql中需要任何优化

AQL查询:

Execution plan:
 Id   NodeType             Est.   Comment
  1   SingletonNode           1   * ROOT
 15   IndexNode         1000000     - FOR c1 IN coll1   /* hash index scan */
 13   IndexNode         1000000       - FOR c2 IN coll2   /* hash index scan */
 12   IndexNode         1000000         - FOR c3 IN coll3   /* hash index scan */
  9   LimitNode           10000           - LIMIT 0, 10000
 10   CalculationNode     10000           - LET #7 = MERGE(c1, c2, c3)   /* simple expression */   /* collections used: c1 : coll1, c2 : coll2, c3 : coll3 */
 11   ReturnNode          10000           - RETURN #7

Indexes used:
 By   Name                      Type   Collection   Unique   Sparse   Selectivity   Fields              Ranges
 15   idx_1650897367446061056   hash   coll1        true     false       100.00 %   [ `id` ]   *
 13   idx_1650897883340210176   hash   coll2        true     false       100.00 %   [ `id` ]   (c1.`id` == c2.`id`)
 12   idx_1650895606437117952   hash   coll3        true     false       100.00 %   [ `id` ]   (c2.`id` == c3.`id`)

Functions used:
 Name    Deterministic   Cacheable   Uses V8
 MERGE   true            true        false  

Optimization rules applied:
 Id   RuleName
  1   use-indexes
  2   remove-filter-covered-by-index
  3   use-index-for-sort
  4   remove-unnecessary-calculations-2
查询字符串(219个字符,可缓存:true):

AQL解释:

Execution plan:
 Id   NodeType             Est.   Comment
  1   SingletonNode           1   * ROOT
 15   IndexNode         1000000     - FOR c1 IN coll1   /* hash index scan */
 13   IndexNode         1000000       - FOR c2 IN coll2   /* hash index scan */
 12   IndexNode         1000000         - FOR c3 IN coll3   /* hash index scan */
  9   LimitNode           10000           - LIMIT 0, 10000
 10   CalculationNode     10000           - LET #7 = MERGE(c1, c2, c3)   /* simple expression */   /* collections used: c1 : coll1, c2 : coll2, c3 : coll3 */
 11   ReturnNode          10000           - RETURN #7

Indexes used:
 By   Name                      Type   Collection   Unique   Sparse   Selectivity   Fields              Ranges
 15   idx_1650897367446061056   hash   coll1        true     false       100.00 %   [ `id` ]   *
 13   idx_1650897883340210176   hash   coll2        true     false       100.00 %   [ `id` ]   (c1.`id` == c2.`id`)
 12   idx_1650895606437117952   hash   coll3        true     false       100.00 %   [ `id` ]   (c2.`id` == c3.`id`)

Functions used:
 Name    Deterministic   Cacheable   Uses V8
 MERGE   true            true        false  

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

使用此查询所花费的查询执行时间较少

您的问题缺少执行计划(或更好的查询分析)以及数据集的描述。
FOR c1 IN coll1 
 limit 10000
     sort c1.id ASC
         FOR c2 IN coll2
           FOR c3 IN coll3
              FILTER ((c1.id == c2.id ) && (c2.id == c3.id))
     RETURN MERGE(c1, c2,c3)