Indexing 调查慢速查询和索引

Indexing 调查慢速查询和索引,indexing,aws-documentdb,Indexing,Aws Documentdb,在日志中,我发现查询速度很慢,但手动运行时速度很快,或者至少考虑了索引。 日志告诉我查询部分没有使用可用的索引。 运行查询时会考虑索引。 在AWS DocumentDB上运行(该数据库与MongoDB 3.6基本兼容)。 日志告诉我(互联网的匿名字段名;-): 在更新上对此运行解释时 collection.explain().update( {"array.field1": BinData(3, "Hzy2Q0TBYEAWadeCtxpXuA==")}, {$set: {"arr

在日志中,我发现查询速度很慢,但手动运行时速度很快,或者至少考虑了索引。
日志告诉我查询部分没有使用可用的索引。
运行查询时会考虑索引。
在AWS DocumentDB上运行(该数据库与MongoDB 3.6基本兼容)。
日志告诉我(互联网的匿名字段名;-):

在更新上对此运行解释时

collection.explain().update(
    {"array.field1": BinData(3, "Hzy2Q0TBYEAWadeCtxpXuA==")},
    {$set: {"array.$.field2":174}}
)
queryPlanner向我展示了这一点

{
  "queryPlanner": {
    "plannerVersion": 1,
    "namespace": "collection",
    "winningPlan": {
      "stage": "UPDATE",
      "inputStages": [
        {
          "stage": "LIMIT_SKIP",
          "inputStage": {
            "stage": "FETCH",
            "inputStage": {
              "stage": "IXSCAN",
              "indexName": "arrayField1"
            }
          }
        },
        {
          "stage": "IXSCAN",
          "indexName": "_idDocField3",
          "direction": "forward"
        }
      ]
    }
  },
  "serverInfo": {
    "host": "xxxxxxx",
    "port": 27017,
    "version": "3.6.0"
  },
  "ok": 1
}
可用索引包括:

  • \u id{u id:1},操作:~56000
  • \u id docField3{{u id:1,docField3:1},操作:~4200000
  • arrayField1{“array.field1”:1},操作:~400
  • arrayField1DocField3{“array.field1”:1,docField3:1},ops:0
array
是一个包含文档的数组,ID是UUID。
收集规模约为40000000

这些文件有点矛盾:


多键索引不能覆盖数组字段上的查询

但是,从3.6开始,如果>>索引跟踪导致索引为多键的字段,则多键索引可以覆盖对非数组字段的查询。在>MongoDB 3.4或更高版本中在除MMAPv1之外的存储引擎上创建的多键索引跟踪此数据

删除复合索引并依赖索引交集是一个好主意吗?
或者切换复合索引的顺序?
有谁能帮我优化一下吗?

请注意,DocumentDB与MongoDB“兼容”,所以MongoDB文档的任何部分都不相关。这可能是矛盾的,因为它们是两个完全不同的产品,碰巧看起来很相似。请注意,DocumentDB与MongoDB“兼容”,因此MongoDB文档的任何部分都不相关。这可能是矛盾的,因为它们是两种完全不同的产品,碰巧看起来很相似。
{
  "queryPlanner": {
    "plannerVersion": 1,
    "namespace": "collection",
    "winningPlan": {
      "stage": "UPDATE",
      "inputStages": [
        {
          "stage": "LIMIT_SKIP",
          "inputStage": {
            "stage": "FETCH",
            "inputStage": {
              "stage": "IXSCAN",
              "indexName": "arrayField1"
            }
          }
        },
        {
          "stage": "IXSCAN",
          "indexName": "_idDocField3",
          "direction": "forward"
        }
      ]
    }
  },
  "serverInfo": {
    "host": "xxxxxxx",
    "port": 27017,
    "version": "3.6.0"
  },
  "ok": 1
}