【发布时间】:2019-11-25 15:09:23
【问题描述】:
问题: 在数据库中,每个集合中有 3 个集合,包含 10,00,000 个文档,每个文档中的属性数为 150,每个集合中的 "ID" 属性是唯一的哈希索引。
现在我想合并所有集合并返回 "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
【问题讨论】:
-
您的问题缺少执行计划(或更好的查询分析)以及数据集的描述。