问题:在数据库中,有3个集合,每个集合包含10,00,000个文档,每个文档中的属性数为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查询:
查询字符串(219个字符,可缓存:真):
FOR c1 IN coll1
sort c1.id ASC
FOR c2 IN coll2
FOR c3 IN coll3
FILTER ((c1.id == c2.id ) && (c2.id == c3.id))
limit 10000
RETURN MERGE(c1, c2,c3)
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
1条答案
按热度按时间nvbavucw1#
使用此查询所花费的查询执行时间较少