gpt4 book ai didi

arrays - ArangoDB 索引和数组

转载 作者:行者123 更新时间:2023-12-02 08:54:58 25 4
gpt4 key购买 nike

我正在尝试使用文档集合进行快速查找,示例文档文档人{

...
groups: ["admin", "user", "godmode"],
contacts: [
{
label: "main office",
items: [
{ type: "phone", value: '333444222' },
{ type: "phone", value: '555222555' },
{ type: "email", value: '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6f0d000d2f08020e0603410c0002" rel="noreferrer noopener nofollow">[email protected]</a>' }
]
}
]
...
}
  1. 为“groups”字段创建哈希索引

    查询:For P in Person FILTER "admin"IN P.groups RETURN P结果:工作正常,但没有通过解释查询使用索引问题:如何使用带有数组过滤器和索引的查询?性能是主要因素

  2. 为“contacts[].items[].value”创建哈希索引

    查询:For P in Person FILTER "333444222"== P.contacts[*].items[*].value RETURN P结果:不支持通配符的双重使用?索引未使用,查询为空问题:如何使用索引组织快速查找这个结构?

附注还尝试了 MATCHES 函数、多杠杆 for-in、从未使用过的数组的哈希索引ArangoDB版本2.6.8

最佳答案

从 ArangoDB 2.8 版开始可以使用索引。对于第一个查询(FILTER "admin"IN p.groups),字段 groups[*] 上的数组哈希索引将起作用:

db._create("persons");
db.persons.insert(personDateFromOriginalExample);
db.persons.ensureIndex({ type: "hash", fields: [ "groups[*]" ] });

2.8之前的版本中不存在这种类型的索引。有了数组索引,查询将产生以下执行计划(显示实际使用了索引):

Execution plan:
Id NodeType Est. Comment
1 SingletonNode 1 * ROOT
6 IndexNode 1 - FOR p IN persons /* hash index scan */
3 CalculationNode 1 - LET #1 = "admin" in p.`groups` /* simple expression */ /* collections used: p : persons */
4 FilterNode 1 - FILTER #1
5 ReturnNode 1 - RETURN p

Indexes used:
By Type Collection Unique Sparse Selectivity Fields Ranges
6 hash persons false false 100.00 % [ `groups[*]` ] "admin" in p.`groups`

数组索引不支持第二个查询,因为它包含多层嵌套。 2.8 中的数组索引仅限于一级,例如groups[*]contacts[*].label 可以使用,但 groups[*].items[*].value 不行。

关于arrays - ArangoDB 索引和数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32772023/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com