简体   繁体   English

ArangoDb 上的数组索引

[英]Array index on ArangoDb

My collection in ArangoDb have objects with this schema (simplified):我在 ArangoDb 中的集合具有具有此架构的对象(简化):

{
    "userName": "Billy",
    "email": "Billy@test.com",
    "logins": [
      {
        "authenticationTokens": [],
        "loginProvider": "Facebook",
        "providerKey": "123",
        "providerDisplayName": null
      }
    ],
    "roles": [],
    "claims": []
}

That's ASPNetCore.Identity implementation on ArangoDb by BorderEast aspnetcore-identity-arangodb这是 BorderEast aspnetcore-identity-arangodb在 ArangoDb 上的 ASPNetCore.Identity 实现

PROBLEM:问题:

To auth using Facebook it uses AQL query要使用 Facebook 进行身份验证,它使用 AQL 查询

for u in IdentityUser for l in u.logins filter l.loginProvider == "Facebook" && l.providerKey == "123" return u

which works well but does not use any index运行良好但不使用任何索引

Indexes used:
    none

I have tried indices:我试过指数:

db.IdentityUser.ensureIndex({ type: "hash", fields: [ "logins[*].loginProvider", "logins[*].providerKey" ] });
db.IdentityUser.ensureIndex({ type: "hash", fields: [ "logins[*].loginProvider" ] });
db.IdentityUser.ensureIndex({ type: "hash", fields: [ "logins[*].providerKey" ], unique: true });

None of them is used.它们都没有被使用。

Can someone advise how the index should look like for that query?有人可以建议该查询的索引应该是什么样子吗?

The issue lies with they query.问题在于他们的查询。 It needs to be re-written and then it will work.它需要重新编写,然后才能工作。 It has to do with using the in comparison operator as discussed in this answer :它与使用in比较运算符有关,如本答案中所述

"Still the query in 2.8 won't use that index because the array indexes are only used for the IN comparison operator." “2.8 中的查询仍然不会使用该索引,因为数组索引仅用于 IN 比较运算符。”

So if we change the query we get this:因此,如果我们更改查询,我们会得到:

Query string:
 for u in IdentityUser 
  let l = u.logins[*].loginProvider
  let p = u.logins[*].providerKey
  filter  "google"  in l and "googlekey" in p
  return u

Execution plan:
 Id   NodeType          Est.   Comment
  1   SingletonNode        1   * ROOT
  8   IndexNode            1     - FOR u IN IdentityUser   /* persistent index scan */
  9   CalculationNode      1       - LET #7 = ("googlekey" in u.`logins`[*].`providerKey`)   /* simple expression */   /* collections used: u : IdentityUser */
  6   FilterNode           1       - FILTER #7
  7   ReturnNode           1       - RETURN u

Indexes used:
 By   Type         Collection     Unique   Sparse   Selectivity   Fields                          Ranges
  8   persistent   IdentityUser   false    false            n/a   [ `logins[*].loginProvider` ]   ("google" in u.`logins`[*].`loginProvider`)

Optimization rules applied:
 Id   RuleName
  1   move-calculations-up
  2   remove-unnecessary-calculations
  3   use-indexes
  4   remove-filter-covered-by-index

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM