Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在为 Web 应用程序设计一个带有 ArangoDB 的数据库。我编写了以下 AQL 查询:
FOR result IN Collection FILTER result.field != 'undefined' RETURN result
我为字段添加了某种类型的索引,但查询绝不使用任何索引。
在你看来问题是什么?我读到对于 == 运算符,我们可以使用哈希索引,对于 <= 或类似的运算符跳过列表。
现在,做同样事情的正确方法是什么?
(从上面粘贴我自己的评论作为答案,以便可以将问题标记为已回答):
如果!=运算符用于属性,则不会使用索引。
!=
首先,ArangoDB 中的哈希索引不支持这种类型的操作。
对于skiplist索引,该操作理论上可以转化为result.field < 'undefined' OR result.field > 'undefined',因此理论上可以从这样的索引中查询到两个不相交的范围。但总的来说,使用索引的目的是在查询中尽早过滤掉尽可能多的文档,而且在很多情况下!=不会导致大的减少
result.field < 'undefined' OR result.field > 'undefined'