问题:在数据库中,每个集合中有3个集合,每个集合中包含10万个文档,每个文档中的属性数为150,每个集合中的<属性是唯一的哈希索引。
现在我要合并所有集合并返回所有集合中“ ID”
相匹配的文档例如:collection1包含文档{"id":1,"firstname":"alex","gender":"male"}
collection2包含文档{"id":1,"middlename":"wilson","age":23}
collection3包含文档{"id":1,"lastname","alive":true}
所以我想像{"id":1,"firstname":"alex","gender":"male","middlename":"wilson","age":23,"lastname","alive":true}
查询工作正常,并给了我预期的结果,但是在大型集合中花费了太多时间,所以我想知道任何其他方法来编写查询或我的aql需要进行任何优化
AQL查询:
查询字符串(219个字符,可缓存:true): 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