【问题标题】:Array index on ArangoDbArangoDb 上的数组索引
【发布时间】:2017-10-29 07:32:03
【问题描述】:

我在 ArangoDb 中的集合包含具有此架构的对象(简化):

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

这是由 BorderEast aspnetcore-identity-arangodb 在 ArangoDb 上实现的 ASPNetCore.Identity

问题:

要使用 Facebook 进行身份验证,它使用 AQL 查询

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

效果很好但不使用任何索引

Indexes used:
    none

我已经尝试过索引:

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 });

没有一个被使用。

有人可以建议该查询的索引应该是什么样子吗?

【问题讨论】:

  • 推送了新的 nuget 包以支持您的索引。在某些时候,我会将查询放入配置中以使其更容易:)

标签: indexing asp.net-identity arangodb


【解决方案1】:

问题在于他们的查询。它需要重新编写,然后才能工作。它与使用in 比较运算符有关,如this answer 中所述:

“2.8 中的查询仍然不会使用该索引,因为数组索引仅用于 IN 比较运算符。”

因此,如果我们更改查询,我们会得到:

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

【讨论】:

  • @Ruslan,作为那个 repo 的作者,我会尽快更新代码并推出一个新的 nuget。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多