【发布时间】:2021-03-22 14:43:00
【问题描述】:
我无法理解如何在 ArangoDB 中正确使用以顶点为中心的索引。
在我的烹饪应用程序中,我有以下图表架构:(recipe)-[hasConstituent]->(ingredient)
假设我想要所有需要少于 0 克胡萝卜的食谱。结果当然是空的。
FOR recipe, constituent, p IN INBOUND 'ingredients/carrot' hasConstituent
FILTER constituent.quantity.value < 0
RETURN recipe._key
胡萝卜关联了 400.000 个食谱,这个查询需要大约 3.9 秒。很好。
现在我在_to,quantity.value 属性的hasConstituent 集合中创建一个以顶点为中心的索引,估计选择性为100%。
我希望它按数字顺序对索引进行排序,然后显着提高 FILTER 或 SORT/LIMIT 请求的速度,但现在之前的请求需要大约 7.9 秒...如果我使索引“稀疏”,它需要与没有索引相同的时间(~3.9s)
我在这里错过了什么?
最难理解的是解释结果给出的执行计划与profile结果不同。这是解释,一切都很好,应该立即获取结果:
Execution plan:
Id NodeType Est. Comment
1 SingletonNode 1 * ROOT
5 TraversalNode 1 - FOR recipe /* vertex */, constituent /* edge */ IN 1..1 /* min..maxPathDepth */ INBOUND 'ingredients/carrot' /* startnode */ hasConstituent
6 CalculationNode 1 - LET #8 = (constituent.`quantity`.`value` < 0) /* simple expression */
7 FilterNode 1 - FILTER #8
8 CalculationNode 1 - LET #10 = recipe.`_key` /* attribute expression */
9 ReturnNode 1 - RETURN #10
但在个人资料中:
Execution plan:
Id NodeType Calls Items Runtime [s] Comment
1 SingletonNode 1 1 0.00000 * ROOT
5 TraversalNode 433 432006 7.64893 - FOR recipe /* vertex */, constituent /* edge */ IN 1..1 /* min..maxPathDepth */ INBOUND 'ingredients/carrot' /* startnode */ hasConstituent
6 CalculationNode 433 432006 0.28761 - LET #8 = (constituent.`quantity`.`value` < 0) /* simple expression */
7 FilterNode 1 0 0.08704 - FILTER #8
8 CalculationNode 1 0 0.00000 - LET #10 = recipe.`_key` /* attribute expression */
9 ReturnNode 1 0 0.00001 - RETURN #10
我精确地在两个结果中都使用了索引:
Indexes used:
By Name Type Collection Unique Sparse Selectivity Fields Ranges
5 recipeByIngrQty persistent hasConstituent false false 100.00 % [ `_to`, `quantity.value` ] base INBOUND
非常欢迎任何帮助
【问题讨论】:
标签: arangodb