Mongodb查询分析器解析

Mongodb查询分析器

  • 动态相关项目中涉及到数据量大和吞吐量的接口,例如关注页面动态,附近动态,这部分数据都是存储在mongodb中,在线上数据中分类两个mongodb集合存储
  • 其中关注动态基于扩散写的设计,数据量已经快到 8 亿。
  • 在这里插入图片描述
  • 附近动态并没有写扩散的数据扩大,并且曝光量相比关注页面少一点,并且重要的是有TTL,因此附近动态相关的表数据50万以上
    在这里插入图片描述
    在这里插入图片描述
  • 在大数据量查询下,优化查询速度是提高系统性能的一个关键点,在Mysql中我们有explan 诊断工具,来帮助我们来对sql进行分析,同样的Mongodb中获取查询相关信息的诊断工具之一就是explain() 函数,在《MongoDB权威指南》(我只看了索引这一章)书中解释:
explain会返回查询使用的索引情况(如果有的话),耗时及扫描文档数的统计信息。.....使用explain就会得到当前查询所使用的索引,消耗了多少时间,已经数据库需要扫描多少文档才能得到结果。
  • 但是书中使用的Mongodb应该是3.2 版本之前的,因为给出的索引分析案例是如下:
{"cursor" : "BtreeCursor gender_1_user_name_1","isMultiKey" : false,"n" : 1,"nscannedObjects" : 0,"nscanned" : 1,"nscannedObjectsAllPlans" : 0,"nscannedAllPlans" : 1,"scanAndOrder" : false,"indexOnly" : true,"nYields" : 0,"nChunkSkips" : 0,"millis" : 0,"indexBounds" : {"gender" : [["M","M"]],"user_name" : [[{"$minElement" : 1},{"$maxElement" : 1}]]}
}
  • 我们在自己数据库中得到完全不一样的输出:
//db.moment.explain(executionStats).find({"subscriberID" :  NumberLong(1884831336), "type" : { "$in" : [1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] } }).sort({"auditTime" : -1});
{"queryPlanner": {"mongosPlannerVersion": 1,"winningPlan": {"stage": "SINGLE_SHARD","shards": [{"shardName": "cmgo-hgz5ixhj_0","connectionString": "cmgo-hgz5ixhj_0/100.120.151.75:7004,100.120.152.197:7000,100.93.47.81:7016","serverInfo": {"host": "TENCENT64.site","port": 7016,"version": "3.2.10-cmongo-","gitVersion": "nogitversion"},"plannerVersion": 1,"namespace": "moment.moment","indexFilterSet": false,"parsedQuery": {"$and": [{"subscriberID": {"$eq": NumberLong(1884831336)}},{"type": {"$in": [1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]}}]},"winningPlan": {"stage": "SORT","sortPattern": {"auditTime": -1},"inputStage": {"stage": "SORT_KEY_GENERATOR","inputStage": {"stage": "FETCH","filter": {"type": {"$in": [1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]}},"inputStage": {"stage": "IXSCAN","keyPattern": {"subscriberID": 1,"momentID": 1},"indexName": "idx_objectid_momentid","isMultiKey": false,"isUnique": true,"isSparse": false,"isPartial": false,"indexVersion": 1,"direction": "forward","indexBounds": {"subscriberID": ["[1884831336, 1884831336]"],"momentID": ["[MinKey, MaxKey]"]}}}}},"rejectedPlans": [{"stage": "FETCH","inputStage": {"stage": "SORT_MERGE","sortPattern": {"auditTime": -1},"inputStages": [{"stage": "IXSCAN","keyPattern": {"subscriberID": 1,"type": 1,"auditTime": 1},"indexName": "subscriberID_1_type_1_auditTime_1","isMultiKey": false,"isUnique": false,"isSparse": false,"isPartial": false,"indexVersion": 1,"direction": "backward","indexBounds": {"subscriberID": ["[1884831336, 1884831336]"],"type": ["[19.0, 19.0]"],"auditTime": ["[MaxKey, MinKey]"]}},{"stage": "IXSCAN","keyPattern": {"subscriberID": 1,"type": 1,"auditTime": 1},"indexName": "subscriberID_1_type_1_auditTime_1","isMultiKey": false,"isUnique": false,"isSparse": false,"isPartial": false,"indexVersion": 1,"direction": "backward","indexBounds": {"subscriberID": ["[1884831336, 1884831336]"],"type": ["[18.0, 18.0]"],"auditTime": ["[MaxKey, MinKey]"]}},{"stage": "IXSCAN","keyPattern": {"subscriberID": 1,"type": 1,"auditTime": 1},"indexName": "subscriberID_1_type_1_auditTime_1","isMultiKey": false,"isUnique": false,"isSparse": false,"isPartial": false,"indexVersion": 1,"direction": "backward","indexBounds": {"subscriberID": ["[1884831336, 1884831336]"],"type": ["[17.0, 17.0]"],"auditTime": ["[MaxKey, MinKey]"]}},{"stage": "IXSCAN","keyPattern": {"subscriberID": 1,"type": 1,"auditTime": 1},"indexName": "subscriberID_1_type_1_auditTime_1","isMultiKey": false,"isUnique": false,"isSparse": false,"isPartial": false,"indexVersion": 1,"direction": "backward","indexBounds": {"subscriberID": ["[1884831336, 1884831336]"],"type": ["[16.0, 16.0]"],"auditTime": ["[MaxKey, MinKey]"]}},{"stage": "IXSCAN","keyPattern": {"subscriberID": 1,"type": 1,"auditTime": 1},"indexName": "subscriberID_1_type_1_auditTime_1","isMultiKey": false,"isUnique": false,"isSparse": false,"isPartial": false,"indexVersion": 1,"direction": "backward","indexBounds": {"subscriberID": ["[1884831336, 1884831336]"],"type": ["[15.0, 15.0]"],"auditTime": ["[MaxKey, MinKey]"]}},{"stage": "IXSCAN","keyPattern": {"subscriberID": 1,"type": 1,"auditTime": 1},"indexName": "subscriberID_1_type_1_auditTime_1","isMultiKey": false,"isUnique": false,"isSparse": false,"isPartial": false,"indexVersion": 1,"direction": "backward","indexBounds": {"subscriberID": ["[1884831336, 1884831336]"],"type": ["[14.0, 14.0]"],"auditTime": ["[MaxKey, MinKey]"]}},{"stage": "IXSCAN","keyPattern": {"subscriberID": 1,"type": 1,"auditTime": 1},"indexName": "subscriberID_1_type_1_auditTime_1","isMultiKey": false,"isUnique": false,"isSparse": false,"isPartial": false,"indexVersion": 1,"direction": "backward","indexBounds": {"subscriberID": ["[1884831336, 1884831336]"],"type": ["[13.0, 13.0]"],"auditTime": ["[MaxKey, MinKey]"]}},{"stage": "IXSCAN","keyPattern": {"subscriberID": 1,"type": 1,"auditTime": 1},"indexName": "subscriberID_1_type_1_auditTime_1","isMultiKey": false,"isUnique": false,"isSparse": false,"isPartial": false,"indexVersion": 1,"direction": "backward","indexBounds": {"subscriberID": ["[1884831336, 1884831336]"],"type": ["[12.0, 12.0]"],"auditTime": ["[MaxKey, MinKey]"]}},{"stage": "IXSCAN","keyPattern": {"subscriberID": 1,"type": 1,"auditTime": 1},"indexName": "subscriberID_1_type_1_auditTime_1","isMultiKey": false,"isUnique": false,"isSparse": false,"isPartial": false,"indexVersion": 1,"direction": "backward","indexBounds": {"subscriberID": ["[1884831336, 1884831336]"],"type": ["[11.0, 11.0]"],"auditTime": ["[MaxKey, MinKey]"]}},{"stage": "IXSCAN","keyPattern": {"subscriberID": 1,"type": 1,"auditTime": 1},"indexName": "subscriberID_1_type_1_auditTime_1","isMultiKey": false,"isUnique": false,"isSparse": false,"isPartial": false,"indexVersion": 1,"direction": "backward","indexBounds": {"subscriberID": ["[1884831336, 1884831336]"],"type": ["[10.0, 10.0]"],"auditTime": ["[MaxKey, MinKey]"]}},{"stage": "IXSCAN","keyPattern": {"subscriberID": 1,"type": 1,"auditTime": 1},"indexName": "subscriberID_1_type_1_auditTime_1","isMultiKey": false,"isUnique": false,"isSparse": false,"isPartial": false,"indexVersion": 1,"direction": "backward","indexBounds": {"subscriberID": ["[1884831336, 1884831336]"],"type": ["[8.0, 8.0]"],"auditTime": ["[MaxKey, MinKey]"]}},{"stage": "IXSCAN","keyPattern": {"subscriberID": 1,"type": 1,"auditTime": 1},"indexName": "subscriberID_1_type_1_auditTime_1","isMultiKey": false,"isUnique": false,"isSparse": false,"isPartial": false,"indexVersion": 1,"direction": "backward","indexBounds": {"subscriberID": ["[1884831336, 1884831336]"],"type": ["[7.0, 7.0]"],"auditTime": ["[MaxKey, MinKey]"]}},{"stage": "IXSCAN","keyPattern": {"subscriberID": 1,"type": 1,"auditTime": 1},"indexName": "subscriberID_1_type_1_auditTime_1","isMultiKey": false,"isUnique": false,"isSparse": false,"isPartial": false,"indexVersion": 1,"direction": "backward","indexBounds": {"subscriberID": ["[1884831336, 1884831336]"],"type": ["[6.0, 6.0]"],"auditTime": ["[MaxKey, MinKey]"]}},{"stage": "IXSCAN","keyPattern": {"subscriberID": 1,"type": 1,"auditTime": 1},"indexName": "subscriberID_1_type_1_auditTime_1","isMultiKey": false,"isUnique": false,"isSparse": false,"isPartial": false,"indexVersion": 1,"direction": "backward","indexBounds": {"subscriberID": ["[1884831336, 1884831336]"],"type": ["[5.0, 5.0]"],"auditTime": ["[MaxKey, MinKey]"]}},{"stage": "IXSCAN","keyPattern": {"subscriberID": 1,"type": 1,"auditTime": 1},"indexName": "subscriberID_1_type_1_auditTime_1","isMultiKey": false,"isUnique": false,"isSparse": false,"isPartial": false,"indexVersion": 1,"direction": "backward","indexBounds": {"subscriberID": ["[1884831336, 1884831336]"],"type": ["[4.0, 4.0]"],"auditTime": ["[MaxKey, MinKey]"]}},{"stage": "IXSCAN","keyPattern": {"subscriberID": 1,"type": 1,"auditTime": 1},"indexName": "subscriberID_1_type_1_auditTime_1","isMultiKey": false,"isUnique": false,"isSparse": false,"isPartial": false,"indexVersion": 1,"direction": "backward","indexBounds": {"subscriberID": ["[1884831336, 1884831336]"],"type": ["[3.0, 3.0]"],"auditTime": ["[MaxKey, MinKey]"]}},{"stage": "IXSCAN","keyPattern": {"subscriberID": 1,"type": 1,"auditTime": 1},"indexName": "subscriberID_1_type_1_auditTime_1","isMultiKey": false,"isUnique": false,"isSparse": false,"isPartial": false,"indexVersion": 1,"direction": "backward","indexBounds": {"subscriberID": ["[1884831336, 1884831336]"],"type": ["[2.0, 2.0]"],"auditTime": ["[MaxKey, MinKey]"]}},{"stage": "IXSCAN","keyPattern": {"subscriberID": 1,"type": 1,"auditTime": 1},"indexName": "subscriberID_1_type_1_auditTime_1","isMultiKey": false,"isUnique": false,"isSparse": false,"isPartial": false,"indexVersion": 1,"direction": "backward","indexBounds": {"subscriberID": ["[1884831336, 1884831336]"],"type": ["[1.0, 1.0]"],"auditTime": ["[MaxKey, MinKey]"]}}]}},{"stage": "SORT","sortPattern": {"auditTime": -1},"inputStage": {"stage": "SORT_KEY_GENERATOR","inputStage": {"stage": "FETCH","inputStage": {"stage": "IXSCAN","keyPattern": {"subscriberID": 1,"unread": 1,"type": 1},"indexName": "subscriberID_1_unread_1_type_1","isMultiKey": false,"isUnique": false,"isSparse": false,"isPartial": false,"indexVersion": 1,"direction": "forward","indexBounds": {"subscriberID": ["[1884831336, 1884831336]"],"unread": ["[MinKey, MaxKey]"],"type": ["[1.0, 1.0]", "[2.0, 2.0]", "[3.0, 3.0]", "[4.0, 4.0]", "[5.0, 5.0]", "[6.0, 6.0]", "[7.0, 7.0]", "[8.0, 8.0]", "[10.0, 10.0]", "[11.0, 11.0]", "[12.0, 12.0]", "[13.0, 13.0]", "[14.0, 14.0]", "[15.0, 15.0]", "[16.0, 16.0]", "[17.0, 17.0]", "[18.0, 18.0]", "[19.0, 19.0]"]}}}}}]}]}},"executionStats": {"nReturned": 71,"executionTimeMillis": 4,"totalKeysExamined": 71,"totalDocsExamined": 71,"executionStages": {"stage": "SINGLE_SHARD","nReturned": 71,"executionTimeMillis": 4,"totalKeysExamined": 71,"totalDocsExamined": 71,"totalChildMillis": NumberLong(2),"shards": [{"shardName": "cmgo-hgz5ixhj_0","executionSuccess": true,"executionStages": {"stage": "SORT","nReturned": 71,"executionTimeMillisEstimate": 0,"works": 146,"advanced": 71,"needTime": 73,"needYield": 0,"saveState": 3,"restoreState": 3,"isEOF": 1,"invalidates": 0,"sortPattern": {"auditTime": -1},"memUsage": 13682,"memLimit": 33554432,"inputStage": {"stage": "SORT_KEY_GENERATOR","nReturned": 0,"executionTimeMillisEstimate": 0,"works": 73,"advanced": 0,"needTime": 1,"needYield": 0,"saveState": 3,"restoreState": 3,"isEOF": 1,"invalidates": 0,"inputStage": {"stage": "FETCH","filter": {"type": {"$in": [1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]}},"nReturned": 71,"executionTimeMillisEstimate": 0,"works": 72,"advanced": 71,"needTime": 0,"needYield": 0,"saveState": 3,"restoreState": 3,"isEOF": 1,"invalidates": 0,"docsExamined": 71,"alreadyHasObj": 0,"inputStage": {"stage": "IXSCAN","nReturned": 71,"executionTimeMillisEstimate": 0,"works": 72,"advanced": 71,"needTime": 0,"needYield": 0,"saveState": 3,"restoreState": 3,"isEOF": 1,"invalidates": 0,"keyPattern": {"subscriberID": 1,"momentID": 1},"indexName": "idx_objectid_momentid","isMultiKey": false,"isUnique": true,"isSparse": false,"isPartial": false,"indexVersion": 1,"direction": "forward","indexBounds": {"subscriberID": ["[1884831336, 1884831336]"],"momentID": ["[MinKey, MaxKey]"]},"keysExamined": 71,"dupsTested": 0,"dupsDropped": 0,"seenInvalidated": 0}}}}}]}},"ok": 1
}
  • 我看到我们测试库的版本是:3.4.21,既然和书上不一样,去官网看看吧,反正书上也是官网的翻译,Mongodb中explain()函数的网址,中文的Mongodb中explain() 网址
    在这里插入图片描述

  • 如上官网中发现,在3.2版本后新支持了一部分函数的分析,并且在预发规则上也有一点变化

//之前
db.collection.<method(...)>.explain()//现在
db.collection.explain().<method(...)>
  • 并且在explain()函数中还支持参数选择各种模式的分析方式,如下:
    在这里插入图片描述

  • 分为三种模式

    • queryPlanner(默认模式)
    • executionStats:返回关于查询过程中统计信息,包括使用的随意,扫描的文档数已经查查处理所用时间(毫秒计算)
    • allPlansExecution:查看计划选择期间收集的部分执行统计信息。
  • 我们主要用的是excutionStats模式来进行分析,如上最长的那个explain返回的json为例:

  • 对queryPlanner分析

    • queryPlanner : 标识queryPlanner的返回
    • queryPlanner.namespace:该值返回的是该query所查询的表
    • queryPlanner.indexFilterSet:针对该query是否有indexfilter
    • queryPlanner.winningPlan:查询优化器针对该query所返回的最优执行计划的详细内容。
    • queryPlanner.winningPlan.stage:最优执行计划的stage,这里返回是SORT,可以理解为通过返回的index位置去检索具体的文档,并且在内存中进行了排序(stage有多个模式,将在后文中进行解释)。
    • queryPlanner.winningPlan.inputStage:用来描述子stage,并且为其父stage提供文档和索引关键字。
    • queryPlanner.winningPlan.inputStage.stage: 此处是SORT_KEY_GENERATOR,这个在官网上找了好久只找到一个issues,最后在stackoverflow上找到了我需要的答案,最关键的一句话: means in-memory sorting,在内存中排序的
    • queryPlanner.winningPlan.keyPattern:所扫描的index内容,此处是"subscriberID" : 1,“momentID” : 1
    • queryPlanner.winningPlan.indexName:winning plan所选用的index。这里选用的idx_objectid_momentid 索引
    • queryPlanner.winningPlan.isMultiKey是否是Multikey,此处返回是false,如果索引建立在array上,此处将是true。
    • queryPlanner.winningPlan.direction:此query的查询顺序,此处是forward,如果查询顺序与设置顺序相反则必然是backward,此部分以下会用案例解释。
    • queryPlanner.winningPlan.indexBounds:winningplan所扫描的索引范围,如果没有制定范围就是[MaxKey, MinKey],这主要是直接定位到mongodb的chunck中去查找数据,加快数据读取。(chunk是指一个集合数据中的子集,在分片的时候,每个分区就是一个chunck)
    • queryPlanner.rejectedPlans:其他执行计划(非最优而被查询优化器reject的)的详细返回,其中具体信息与winningPlan的返回中意义相同
  • 对executionStats中时间分析

    • executionTimeMillis : 指我们预计的执行时间,越小越好,其中有三个这个时间数据,分别如下:
      • 第一层, executionStats.executionTimeMillis: 该query的整体查询时间。
      • 第二层,executionStats.executionStages.executionTimeMillisEstimate: 该查询根据index去检索document获得71条数据的时间。
      • 第三层,executionStats.executionStages.inputStage.executionTimeMillisEstimate:此处没有,该查询扫描71行index所用时间。
  • 对executionStats中扫描数量的分析

    • nReturned、totalKeysExamined、totalDocsExamined,分别代表查询返回条数,索引扫描条数,文档扫描条数,这些都是直观地影响到executionTimeMillis,我们需要扫描的越少速度越快。
    • 对应一个查询,理想状态下是 nReturned=totalKeysExamined=totalDocsExamined,也就是我们需要的数据都在索引数据文档中找到了
  • 对stage状态分析

    • stage的类型会影响totalKeysExamined和totalDocsExamined的最终扫描值
    • COLLSCAN:全表扫描
    • IXSCAN:索引扫描
    • FETCH:根据索引去检索指定document
    • SHARD_MERGE:将各个分片返回数据进行merge
    • SORT:表明在内存中进行了排序
    • SORT_KEY_GENERATOR : 表名在内存中排序
    • LIMIT:使用limit限制返回数
    • SKIP:使用skip进行跳过
    • IDHACK:针对_id进行查询
    • SHARDING_FILTER:通过mongos对分片数据进行查询
    • COUNT:利用db.coll.explain().count()之类进行count运算
    • COUNTSCAN:count不使用Index进行count时的stage返回
    • COUNT_SCAN:count使用了Index进行count时的stage返回
    • SUBPLA:未使用到索引的$or查询的stage返回
    • TEXT:使用全文索引进行查询时候的stage返回
    • PROJECTION:限定返回字段时候stage的返回
    • SINGLE_SHARD: 查询落到单个分片上查询
  • 我们生产中期望得到的是:

    • Fetch+IDHACK
    • Fetch+IXSCAN
    • Limit+(Fetch+IXSCAN)
    • PROJECTION+IXSCAN
    • SINGLE_SHARD+IXSCAN
    • COUNT_SCAN
  • 不希望看到的:

    • COLLSCAN,全表
    • SORT,使用排序但是没有命中索引,内存排序
    • 不要用SKIP去做跳过操作
    • SUBPLA,没有用到索引的or命令
    • COUNTSCAN,没有用到索引的count
  • 关于上面direction是backward的原因,有必要说明:

  • 我们在没有设置排序字段时候,因为走的索引是idx_objectid_momentid :{“subscriberID” : 1,“momentID” : 1},两个字段索引都是顺序创建的。如下在默认无指定排序情况下,momentID是顺序排列的。
    在这里插入图片描述

  • 如果我们强制这条语句走 subscriberID_1_type_1_auditTime_1 索引,那么他肯定是backround,因为你查询的顺序和你索引创建的顺序正好是相反的:

//db.moment.explain("executionStats").find({"subscriberID" :  NumberLong(1884831336), "type" : { "$in" : [1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] } }).sort({"auditTime": -1}).hint({"subscriberID" : 1,"type" : 1,"auditTime" : 1});
{"queryPlanner" : {"mongosPlannerVersion" : 1,"winningPlan" : {"stage" : "SINGLE_SHARD","shards" : [{"shardName" : "cmgo-hgz5ixhj_0","connectionString" : "cmgo-hgz5ixhj_0/100.120.151.75:7004,100.120.152.197:7000,100.93.47.81:7016","serverInfo" : {"host" : "TENCENT64.site","port" : 7016,"version" : "3.2.10-cmongo-","gitVersion" : "nogitversion"},"plannerVersion" : 1,"namespace" : "moment.moment","indexFilterSet" : false,"parsedQuery" : {"$and" : [{"subscriberID" : {"$eq" : NumberLong(1884831336)}},{"type" : {"$in" : [1,2,3,4,5,6,7,8,10,11,12,13,14,15,16,17,18,19]}}]},"winningPlan" : {"stage" : "FETCH","inputStage" : {"stage" : "SORT_MERGE","sortPattern" : {"auditTime" : -1},"inputStages" : [{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[19.0, 19.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[18.0, 18.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[17.0, 17.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[16.0, 16.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[15.0, 15.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[14.0, 14.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[13.0, 13.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[12.0, 12.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[11.0, 11.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[10.0, 10.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[8.0, 8.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[7.0, 7.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[6.0, 6.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[5.0, 5.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[4.0, 4.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[3.0, 3.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[2.0, 2.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[1.0, 1.0]"],"auditTime" : ["[MaxKey, MinKey]"]}}]}},"rejectedPlans" : [ ]}]}},"executionStats" : {"nReturned" : 71,"executionTimeMillis" : 3,"totalKeysExamined" : 71,"totalDocsExamined" : 71,"executionStages" : {"stage" : "SINGLE_SHARD","nReturned" : 71,"executionTimeMillis" : 3,"totalKeysExamined" : 71,"totalDocsExamined" : 71,"totalChildMillis" : NumberLong(1),"shards" : [{"shardName" : "cmgo-hgz5ixhj_0","executionSuccess" : true,"executionStages" : {"stage" : "FETCH","nReturned" : 71,"executionTimeMillisEstimate" : 0,"works" : 161,"advanced" : 71,"needTime" : 89,"needYield" : 0,"saveState" : 1,"restoreState" : 1,"isEOF" : 1,"invalidates" : 0,"docsExamined" : 71,"alreadyHasObj" : 0,"inputStage" : {"stage" : "SORT_MERGE","nReturned" : 71,"executionTimeMillisEstimate" : 0,"works" : 160,"advanced" : 71,"needTime" : 89,"needYield" : 0,"saveState" : 1,"restoreState" : 1,"isEOF" : 1,"invalidates" : 0,"sortPattern" : {"auditTime" : -1},"dupsTested" : 71,"dupsDropped" : 0,"inputStages" : [{"stage" : "IXSCAN","nReturned" : 0,"executionTimeMillisEstimate" : 0,"works" : 1,"advanced" : 0,"needTime" : 0,"needYield" : 0,"saveState" : 1,"restoreState" : 1,"isEOF" : 1,"invalidates" : 0,"keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[19.0, 19.0]"],"auditTime" : ["[MaxKey, MinKey]"]},"keysExamined" : 0,"dupsTested" : 0,"dupsDropped" : 0,"seenInvalidated" : 0},{"stage" : "IXSCAN","nReturned" : 0,"executionTimeMillisEstimate" : 0,"works" : 1,"advanced" : 0,"needTime" : 0,"needYield" : 0,"saveState" : 1,"restoreState" : 1,"isEOF" : 1,"invalidates" : 0,"keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[18.0, 18.0]"],"auditTime" : ["[MaxKey, MinKey]"]},"keysExamined" : 0,"dupsTested" : 0,"dupsDropped" : 0,"seenInvalidated" : 0},{"stage" : "IXSCAN","nReturned" : 0,"executionTimeMillisEstimate" : 0,"works" : 1,"advanced" : 0,"needTime" : 0,"needYield" : 0,"saveState" : 1,"restoreState" : 1,"isEOF" : 1,"invalidates" : 0,"keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[17.0, 17.0]"],"auditTime" : ["[MaxKey, MinKey]"]},"keysExamined" : 0,"dupsTested" : 0,"dupsDropped" : 0,"seenInvalidated" : 0},{"stage" : "IXSCAN","nReturned" : 0,"executionTimeMillisEstimate" : 0,"works" : 1,"advanced" : 0,"needTime" : 0,"needYield" : 0,"saveState" : 1,"restoreState" : 1,"isEOF" : 1,"invalidates" : 0,"keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[16.0, 16.0]"],"auditTime" : ["[MaxKey, MinKey]"]},"keysExamined" : 0,"dupsTested" : 0,"dupsDropped" : 0,"seenInvalidated" : 0},{"stage" : "IXSCAN","nReturned" : 0,"executionTimeMillisEstimate" : 0,"works" : 1,"advanced" : 0,"needTime" : 0,"needYield" : 0,"saveState" : 1,"restoreState" : 1,"isEOF" : 1,"invalidates" : 0,"keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[15.0, 15.0]"],"auditTime" : ["[MaxKey, MinKey]"]},"keysExamined" : 0,"dupsTested" : 0,"dupsDropped" : 0,"seenInvalidated" : 0},{"stage" : "IXSCAN","nReturned" : 0,"executionTimeMillisEstimate" : 0,"works" : 1,"advanced" : 0,"needTime" : 0,"needYield" : 0,"saveState" : 1,"restoreState" : 1,"isEOF" : 1,"invalidates" : 0,"keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[14.0, 14.0]"],"auditTime" : ["[MaxKey, MinKey]"]},"keysExamined" : 0,"dupsTested" : 0,"dupsDropped" : 0,"seenInvalidated" : 0},{"stage" : "IXSCAN","nReturned" : 0,"executionTimeMillisEstimate" : 0,"works" : 1,"advanced" : 0,"needTime" : 0,"needYield" : 0,"saveState" : 1,"restoreState" : 1,"isEOF" : 1,"invalidates" : 0,"keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[13.0, 13.0]"],"auditTime" : ["[MaxKey, MinKey]"]},"keysExamined" : 0,"dupsTested" : 0,"dupsDropped" : 0,"seenInvalidated" : 0},{"stage" : "IXSCAN","nReturned" : 6,"executionTimeMillisEstimate" : 0,"works" : 7,"advanced" : 6,"needTime" : 0,"needYield" : 0,"saveState" : 1,"restoreState" : 1,"isEOF" : 1,"invalidates" : 0,"keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[12.0, 12.0]"],"auditTime" : ["[MaxKey, MinKey]"]},"keysExamined" : 6,"dupsTested" : 0,"dupsDropped" : 0,"seenInvalidated" : 0},{"stage" : "IXSCAN","nReturned" : 0,"executionTimeMillisEstimate" : 0,"works" : 1,"advanced" : 0,"needTime" : 0,"needYield" : 0,"saveState" : 1,"restoreState" : 1,"isEOF" : 1,"invalidates" : 0,"keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[11.0, 11.0]"],"auditTime" : ["[MaxKey, MinKey]"]},"keysExamined" : 0,"dupsTested" : 0,"dupsDropped" : 0,"seenInvalidated" : 0},{"stage" : "IXSCAN","nReturned" : 0,"executionTimeMillisEstimate" : 0,"works" : 1,"advanced" : 0,"needTime" : 0,"needYield" : 0,"saveState" : 1,"restoreState" : 1,"isEOF" : 1,"invalidates" : 0,"keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[10.0, 10.0]"],"auditTime" : ["[MaxKey, MinKey]"]},"keysExamined" : 0,"dupsTested" : 0,"dupsDropped" : 0,"seenInvalidated" : 0},{"stage" : "IXSCAN","nReturned" : 0,"executionTimeMillisEstimate" : 0,"works" : 1,"advanced" : 0,"needTime" : 0,"needYield" : 0,"saveState" : 1,"restoreState" : 1,"isEOF" : 1,"invalidates" : 0,"keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[8.0, 8.0]"],"auditTime" : ["[MaxKey, MinKey]"]},"keysExamined" : 0,"dupsTested" : 0,"dupsDropped" : 0,"seenInvalidated" : 0},{"stage" : "IXSCAN","nReturned" : 0,"executionTimeMillisEstimate" : 0,"works" : 1,"advanced" : 0,"needTime" : 0,"needYield" : 0,"saveState" : 1,"restoreState" : 1,"isEOF" : 1,"invalidates" : 0,"keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[7.0, 7.0]"],"auditTime" : ["[MaxKey, MinKey]"]},"keysExamined" : 0,"dupsTested" : 0,"dupsDropped" : 0,"seenInvalidated" : 0},{"stage" : "IXSCAN","nReturned" : 0,"executionTimeMillisEstimate" : 0,"works" : 1,"advanced" : 0,"needTime" : 0,"needYield" : 0,"saveState" : 1,"restoreState" : 1,"isEOF" : 1,"invalidates" : 0,"keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[6.0, 6.0]"],"auditTime" : ["[MaxKey, MinKey]"]},"keysExamined" : 0,"dupsTested" : 0,"dupsDropped" : 0,"seenInvalidated" : 0},{"stage" : "IXSCAN","nReturned" : 3,"executionTimeMillisEstimate" : 0,"works" : 4,"advanced" : 3,"needTime" : 0,"needYield" : 0,"saveState" : 1,"restoreState" : 1,"isEOF" : 1,"invalidates" : 0,"keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[5.0, 5.0]"],"auditTime" : ["[MaxKey, MinKey]"]},"keysExamined" : 3,"dupsTested" : 0,"dupsDropped" : 0,"seenInvalidated" : 0},{"stage" : "IXSCAN","nReturned" : 8,"executionTimeMillisEstimate" : 0,"works" : 9,"advanced" : 8,"needTime" : 0,"needYield" : 0,"saveState" : 1,"restoreState" : 1,"isEOF" : 1,"invalidates" : 0,"keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[4.0, 4.0]"],"auditTime" : ["[MaxKey, MinKey]"]},"keysExamined" : 8,"dupsTested" : 0,"dupsDropped" : 0,"seenInvalidated" : 0},{"stage" : "IXSCAN","nReturned" : 25,"executionTimeMillisEstimate" : 0,"works" : 26,"advanced" : 25,"needTime" : 0,"needYield" : 0,"saveState" : 1,"restoreState" : 1,"isEOF" : 1,"invalidates" : 0,"keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[3.0, 3.0]"],"auditTime" : ["[MaxKey, MinKey]"]},"keysExamined" : 25,"dupsTested" : 0,"dupsDropped" : 0,"seenInvalidated" : 0},{"stage" : "IXSCAN","nReturned" : 28,"executionTimeMillisEstimate" : 0,"works" : 29,"advanced" : 28,"needTime" : 0,"needYield" : 0,"saveState" : 1,"restoreState" : 1,"isEOF" : 1,"invalidates" : 0,"keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[2.0, 2.0]"],"auditTime" : ["[MaxKey, MinKey]"]},"keysExamined" : 28,"dupsTested" : 0,"dupsDropped" : 0,"seenInvalidated" : 0},{"stage" : "IXSCAN","nReturned" : 1,"executionTimeMillisEstimate" : 0,"works" : 2,"advanced" : 1,"needTime" : 0,"needYield" : 0,"saveState" : 1,"restoreState" : 1,"isEOF" : 1,"invalidates" : 0,"keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 1,"direction" : "backward","indexBounds" : {"subscriberID" : ["[1884831336, 1884831336]"],"type" : ["[1.0, 1.0]"],"auditTime" : ["[MaxKey, MinKey]"]},"keysExamined" : 1,"dupsTested" : 0,"dupsDropped" : 0,"seenInvalidated" : 0}]}}}]}},"ok" : 1
}
  • 以上语句也就是我们动态中用的第二多的一条语句,当关注页面查看第二页动态时候,会带上_id,这个时候我们用hint 命令强制他走了 subscriberID_1_type_1_auditTime_1 索引,此时他的查询是FETCH + SORT_MERGE,其中SORT_MERGE 也是在内存进行排序并且合并得到最好结果。

  • 以上分析起来索引应该有优化的空间,例如我建立以下索引:

db.moment.createIndex({"subscriberID" : 1,"type" : 1,"auditTime" : -1 })
  • 看起来完美契合我们的查询:
db.moment.explain("executionStats").find({ "subscriberID" : NumberLong(2000103230), "type" : { "$in" : [1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] } }).sort({"auditTime": -1});
//得到的执行结果:
{"queryPlanner" : {"plannerVersion" : 1,"namespace" : "moment.moment","indexFilterSet" : false,"parsedQuery" : {"$and" : [{"subscriberID" : {"$eq" : NumberLong(2000103230)}},{"type" : {"$in" : [1,2,3,4,5,6,7,8,10,11,12,13,14,15,16,17,18,19]}}]},"winningPlan" : {"stage" : "SORT","sortPattern" : {"auditTime" : -1},"inputStage" : {"stage" : "SORT_KEY_GENERATOR","inputStage" : {"stage" : "FETCH","filter" : {"type" : {"$in" : [1,2,3,4,5,6,7,8,10,11,12,13,14,15,16,17,18,19]}},"inputStage" : {"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"unread" : 1},"indexName" : "subscriberID_1_unread_1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"unread" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "forward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"unread" : ["[MinKey, MaxKey]"]}}}}},"rejectedPlans" : [{"stage" : "FETCH","inputStage" : {"stage" : "SORT_MERGE","sortPattern" : {"auditTime" : -1},"inputStages" : [{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : -1},"indexName" : "subscriberID_1_type_1_auditTime_-1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "forward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[1.0, 1.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : -1},"indexName" : "subscriberID_1_type_1_auditTime_-1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "forward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[2.0, 2.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : -1},"indexName" : "subscriberID_1_type_1_auditTime_-1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "forward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[3.0, 3.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : -1},"indexName" : "subscriberID_1_type_1_auditTime_-1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "forward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[4.0, 4.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : -1},"indexName" : "subscriberID_1_type_1_auditTime_-1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "forward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[5.0, 5.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : -1},"indexName" : "subscriberID_1_type_1_auditTime_-1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "forward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[6.0, 6.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : -1},"indexName" : "subscriberID_1_type_1_auditTime_-1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "forward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[7.0, 7.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : -1},"indexName" : "subscriberID_1_type_1_auditTime_-1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "forward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[8.0, 8.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : -1},"indexName" : "subscriberID_1_type_1_auditTime_-1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "forward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[10.0, 10.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : -1},"indexName" : "subscriberID_1_type_1_auditTime_-1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "forward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[11.0, 11.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : -1},"indexName" : "subscriberID_1_type_1_auditTime_-1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "forward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[12.0, 12.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : -1},"indexName" : "subscriberID_1_type_1_auditTime_-1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "forward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[13.0, 13.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : -1},"indexName" : "subscriberID_1_type_1_auditTime_-1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "forward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[14.0, 14.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : -1},"indexName" : "subscriberID_1_type_1_auditTime_-1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "forward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[15.0, 15.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : -1},"indexName" : "subscriberID_1_type_1_auditTime_-1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "forward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[16.0, 16.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : -1},"indexName" : "subscriberID_1_type_1_auditTime_-1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "forward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[17.0, 17.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : -1},"indexName" : "subscriberID_1_type_1_auditTime_-1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "forward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[18.0, 18.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : -1},"indexName" : "subscriberID_1_type_1_auditTime_-1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "forward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[19.0, 19.0]"],"auditTime" : ["[MaxKey, MinKey]"]}}]}},{"stage" : "SORT","sortPattern" : {"auditTime" : -1},"inputStage" : {"stage" : "SORT_KEY_GENERATOR","inputStage" : {"stage" : "FETCH","filter" : {"type" : {"$in" : [1,2,3,4,5,6,7,8,10,11,12,13,14,15,16,17,18,19]}},"inputStage" : {"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"momentID" : 1},"indexName" : "idx_objectid_momentid","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"momentID" : [ ]},"isUnique" : true,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "forward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"momentID" : ["[MinKey, MaxKey]"]}}}}},{"stage" : "SORT","sortPattern" : {"auditTime" : -1},"inputStage" : {"stage" : "SORT_KEY_GENERATOR","inputStage" : {"stage" : "FETCH","inputStage" : {"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"unread" : 1,"type" : 1},"indexName" : "subscriberID_1_unread_1_type_1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"unread" : [ ],"type" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "forward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"unread" : ["[MinKey, MaxKey]"],"type" : ["[1.0, 1.0]","[2.0, 2.0]","[3.0, 3.0]","[4.0, 4.0]","[5.0, 5.0]","[6.0, 6.0]","[7.0, 7.0]","[8.0, 8.0]","[10.0, 10.0]","[11.0, 11.0]","[12.0, 12.0]","[13.0, 13.0]","[14.0, 14.0]","[15.0, 15.0]","[16.0, 16.0]","[17.0, 17.0]","[18.0, 18.0]","[19.0, 19.0]"]}}}}},{"stage" : "FETCH","inputStage" : {"stage" : "SORT_MERGE","sortPattern" : {"auditTime" : -1},"inputStages" : [{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "backward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[19.0, 19.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "backward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[18.0, 18.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "backward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[17.0, 17.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "backward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[16.0, 16.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "backward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[15.0, 15.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "backward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[14.0, 14.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "backward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[13.0, 13.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "backward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[12.0, 12.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "backward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[11.0, 11.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "backward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[10.0, 10.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "backward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[8.0, 8.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "backward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[7.0, 7.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "backward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[6.0, 6.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "backward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[5.0, 5.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "backward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[4.0, 4.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "backward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[3.0, 3.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "backward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[2.0, 2.0]"],"auditTime" : ["[MaxKey, MinKey]"]}},{"stage" : "IXSCAN","keyPattern" : {"subscriberID" : 1,"type" : 1,"auditTime" : 1},"indexName" : "subscriberID_1_type_1_auditTime_1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"type" : [ ],"auditTime" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "backward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"type" : ["[1.0, 1.0]"],"auditTime" : ["[MaxKey, MinKey]"]}}]}}]},"executionStats" : {"executionSuccess" : true,"nReturned" : 4,"executionTimeMillis" : 1,"totalKeysExamined" : 4,"totalDocsExamined" : 4,"executionStages" : {"stage" : "SORT","nReturned" : 4,"executionTimeMillisEstimate" : 0,"works" : 12,"advanced" : 4,"needTime" : 6,"needYield" : 0,"saveState" : 0,"restoreState" : 0,"isEOF" : 1,"invalidates" : 0,"sortPattern" : {"auditTime" : -1},"memUsage" : 764,"memLimit" : 33554432,"inputStage" : {"stage" : "SORT_KEY_GENERATOR","nReturned" : 4,"executionTimeMillisEstimate" : 0,"works" : 6,"advanced" : 4,"needTime" : 1,"needYield" : 0,"saveState" : 0,"restoreState" : 0,"isEOF" : 1,"invalidates" : 0,"inputStage" : {"stage" : "FETCH","filter" : {"type" : {"$in" : [1,2,3,4,5,6,7,8,10,11,12,13,14,15,16,17,18,19]}},"nReturned" : 4,"executionTimeMillisEstimate" : 0,"works" : 5,"advanced" : 4,"needTime" : 0,"needYield" : 0,"saveState" : 0,"restoreState" : 0,"isEOF" : 1,"invalidates" : 0,"docsExamined" : 4,"alreadyHasObj" : 0,"inputStage" : {"stage" : "IXSCAN","nReturned" : 4,"executionTimeMillisEstimate" : 0,"works" : 5,"advanced" : 4,"needTime" : 0,"needYield" : 0,"saveState" : 0,"restoreState" : 0,"isEOF" : 1,"invalidates" : 0,"keyPattern" : {"subscriberID" : 1,"unread" : 1},"indexName" : "subscriberID_1_unread_1","isMultiKey" : false,"multiKeyPaths" : {"subscriberID" : [ ],"unread" : [ ]},"isUnique" : false,"isSparse" : false,"isPartial" : false,"indexVersion" : 2,"direction" : "forward","indexBounds" : {"subscriberID" : ["[2000103230, 2000103230]"],"unread" : ["[MinKey, MaxKey]"]},"keysExamined" : 4,"seeks" : 1,"dupsTested" : 0,"dupsDropped" : 0,"seenInvalidated" : 0}}}}},"serverInfo" : {"host" : "mongodb-0","port" : 27017,"version" : "3.4.21","gitVersion" : "ba2e818de44c9a331ce09a624780a2bd841cf6e4"},"ok" : 1
}
  • 我们看到结果依然是 SORT + SORT_KEY_GENERATOR,意思是我们依然需要在内存中排序,原因在于当我们建立:{“subscriberID” : 1,“type” : 1,“auditTime” : -1 } 索引的时候,MongoDB会按照如下方式给我吗组织索引数据:
    • 优先按subscriberID 的顺序,
    • 然后 type顺序
    • 最后才是 auditTime 的逆序,如下案例
mongos> db.moment.find({ "subscriberID" : NumberLong(1896740278), "type" : { "$in" : [1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] } });
{ "_id" : ObjectId("5fd09738fb1a7b001444e64b"), "type" : 1, "momentID" : NumberLong(257617647), "memberID" : NumberLong(1519251653), "subscriberID" : NumberLong(1896740278), "auditStatus" : 0, "unread" : true, "createTime" : ISODate("2020-12-09T09:21:59Z"),  }
{ "_id" : ObjectId("60a3a82062c4680014c7dd21"), "type" : 1, "momentID" : NumberLong(405945302), "subscriberID" : NumberLong(1896740278), "unread" : true, "auditTime" : ISODate("2021-05-18T11:42:25Z"), "createTime" : ISODate("2021-05-18T11:28:11Z"),  }
{ "_id" : ObjectId("60a65571d359c60014c6149c"), "type" : 1, "momentID" : NumberLong(406114684), "subscriberID" : NumberLong(1896740278), "unread" : true, "auditTime" : ISODate("2021-05-20T12:26:25Z"), "createTime" : ISODate("2021-05-20T12:10:39Z"),  }
{ "_id" : ObjectId("60d3000178512e001443830f"), "type" : 1, "momentID" : NumberLong(408785569), "subscriberID" : NumberLong(1896740278), "unread" : true, "auditTime" : ISODate("2021-06-23T09:33:53Z"), "createTime" : ISODate("2021-06-23T09:26:52Z"),  }
{ "_id" : ObjectId("60e6d944ccc7d000148edac2"), "type" : 1, "momentID" : NumberLong(409971805), "subscriberID" : NumberLong(1896740278), "unread" : true, "auditTime" : ISODate("2021-07-08T10:53:56Z"), "createTime" : ISODate("2021-07-08T10:45:38Z"),  }
{ "_id" : ObjectId("60eb97d3f12ad4001491f83f"), "type" : 1, "momentID" : NumberLong(410215242), "subscriberID" : NumberLong(1896740278), "unread" : true, "auditTime" : ISODate("2021-07-12T01:16:03Z"), "createTime" : ISODate("2021-07-12T01:07:27Z"),  }
{ "_id" : ObjectId("61016cc1b572ea001497550f"), "type" : 1, "momentID" : NumberLong(411549007), "subscriberID" : NumberLong(1896740278), "unread" : true, "auditTime" : ISODate("2021-07-28T14:42:09Z"), "createTime" : ISODate("2021-07-28T14:42:09Z"),  }
  • 可以看到在objectId相同的时候,他是按照momentID的顺序排列,但是auditTime的顺序只有在momentID相同的时候才是逆序,实际按索引来看他还是乱序的。因此我们在对时间排序的时候,他依然需要在内存排序。

  • 那么我们应该创建如下的索引:

db.moment.createIndex({"subscriberID" : 1,"auditTime" : -1 ,"type" : 1})         
db.moment.createIndex({"type" : 1,"auditTime" : -1,"subscriberID" : 1})
  • 因为我们是分片的数据库,按照subscriberID分片,因此,这两个索引效果是一样的。但是两个都创建的话,MongoDB会给你选择第一个,排序优先

  • 在我们项目中,查询关注动态部分有两个查询语句,一条查询第一页,一条查询之后的页面数据,带有_id,占比如下:

  • 总的查询数:2,007,778

请添加图片描述

  • 第二页以及以后的查询数:584258

请添加图片描述

  • 第二页查询占比28% 左右,也就是大多其实都是在第一页查看,由此看来索引还是有优化空间的。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/310300.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

[Java基础]Collections概述和使用

代码如下: package CollectionDemo01;import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List;public class CollectionDemo01 {public static void main(String[] args){List<Integer> list new ArrayList&l…

链路追踪在ERP系统中的应用实践

源宝导读&#xff1a;随着ERP的部署架构越来越复杂&#xff0c;对运维监控、问题排查等工作增加了难度&#xff0c;本文将介绍通过引入链路追踪技术&#xff0c;提高ERP系统问题排查效率&#xff0c;支撑更全面监控系统运行情况的实践过程。一、导读随着ERP的部署架构越来越复杂…

[Java基础]File基础

File类概述和构造方法: 代码如下: package FileStudyPack;import java.io.File;public class FileDemo01 {public static void main(String[] args){File f1 new File("D:\\JavaDemo\\java.txt");System.out.println(f1);File f2 new File("D:\\JavaDemo&quo…

java 日志乱码_【开发者成长】JAVA 线上故障排查完整套路!

云栖号资讯&#xff1a;【点击查看更多行业资讯】在这里您可以找到不同行业的第一手的上云资讯&#xff0c;还在等什么&#xff0c;快来&#xff01;线上故障主要会包括 CPU、磁盘、内存以及网络问题&#xff0c;而大多数故障可能会包含不止一个层面的问题&#xff0c;所以进行…

谈谈登录密码传输这件小事

背景 大大小小的系统其实都离不开登录这个小小的功能&#xff0c;前段时间老黄在审查公司部分系统代码时&#xff0c;发现不少系统的登录还是很粗暴的&#xff0c;粗暴到让人不敢说话的那种。说到登录&#xff0c;结合标题&#xff0c;其实大部分人应该都猜到那个粗暴到让人不敢…

技术分享杂七杂八技术

技术分享 听花谷 距离名宿 6~7 公里左右&#xff0c;丽江网红基地&#xff0c;有举办婚礼的地方听花谷&#xff0c;坐落于玉龙雪山脚下&#xff0c;前有玉龙雪山&#xff0c;后有原始森林。园内共有三处白色空间&#xff0c;第一处共有三层&#xff0c;婚礼举行&#xff0c;发…

java 操作日志设计_日志系统新贵 Loki,确实比笨重的ELK轻

本文同步Java知音社区&#xff0c;专注于Java作者&#xff1a;linkt1234http://blog.csdn.net/Linkthaha/article/details/100575278最近&#xff0c;在对公司容器云的日志方案进行设计的时候&#xff0c;发现主流的ELK或者EFK比较重&#xff0c;再加上现阶段对于ES复杂的搜索功…

Istio1.5 Envoy 数据面 WASM 实践

Istio 1.5 回归单体架构&#xff0c;并抛却原有的 out-of-process 的数据面扩展方式&#xff0c;转而拥抱基于 WASM 的 in-proxy 扩展&#xff0c;以期获得更好的性能。本文基于网易杭州研究院轻舟云原生团队的调研与探索&#xff0c;介绍 WASM 的社区发展与实践。超简单版解释…

elasticSearch -- (文档,类型,索引)

问题:大规模数据如何检索 当系统数据量达到10亿&#xff0c;100亿级别的时候&#xff0c;我们系统该如何去解决这种问题。 数据库选择—mysql&#xff0c; sybase&#xff0c;oracle&#xff0c;mongodb&#xff0c;hbase…单点故障如何解决—lvs&#xff0c; F5&#xff0c;…

asp后台调用产品数据_后台产品经理,需掌握这些数据交互知识

人们每天都在接收信息和发送信息&#xff0c;在传递信息的过程中&#xff0c;明白对方要表达的意思。数据也是如此&#xff0c;在系统交换数据的过程中&#xff0c;就伴随着数据交互。本篇文章将为大家具体分析前端和后台的数据交互与协议。本文所说的”数据交换” 是指在计算机…

使用c# .net core开发国标gb28181 sip +流媒体服务完成视频监控实例教程 亲身完美体验过程...

目前使用C# .net core 来实现国标gb28181标准的摄像头播放、ptz云台控制、视频回放等视频监控功能&#xff0c;项目可运行于linux/docker/.net core环境&#xff0c;也是当前非常罕有的能做到毫秒级国标gb28181公网视频传送案例&#xff0c;也是少有的能同时具有播放、ptz云台控…

[Java基础]字节流读数据

代码如下: package InstreamPack;import java.io.FileInputStream; import java.io.IOException;public class FileInputStreamDemo01 {public static void main(String[] args) throws IOException {FileInputStream fis new FileInputStream("D:\\JavaDemo\\java.txt&…

丁可以组什么词_有哪些量词可以用来描述生意经?

分别有&#xff1a;本&#xff0c; 一(本)生意经。笔&#xff0c; 一(笔)生意经。次&#xff0c;一(次)生意量词用名量词&#xff1a;表示事物的计量单位。基本定义&#xff1a;通常用来表示人、事物或动作的数量单位的词&#xff0c;叫做量词。量词 lingc&#xff0c;与代表可…

硬核技能k8s初体验

&#xff0c;Kubernetes 是一个软件系统&#xff0c;使你在数以万计的电脑节点上运行软件时就像所有节点是以单个大节点一样&#xff0c; 它将底层基础设施抽象&#xff0c;这样做同时简化了应用开发、部署&#xff0c;以及对开发和运维团队的管理。Kubernetes集群架构Kubernet…

线上问题排查流程

问题排查 针对各种常见的线上问题&#xff0c;梳理下排查思路。 业务问题 线上问题大多数时候都是业务问题引发的问题&#xff0c;当线上环境绝大多数请求都是正常&#xff0c;当有部分或者某一个用户有问题&#xff0c;此时怎么针对性的排查在当前微服务体系下&#xff0c;…

springboot超详细教程_CG原画插画教程:超详细线稿教程

艺学绘小编收集整理了超详细线稿教程今天我们从起稿开始1. 用圆表示出人物的头部、胸腔和骨盆&#xff0c;分别画出头部的十字线和身体的中线&#xff0c;表示头和身体的朝向。用“火柴棍”表示四肢的动作形态。▼2. 根据圆和十字线画出脸的轮廓&#xff0c;再在身体骨架上画出…

Asp.Net.Core WebApi 版本控制

前言在后端Api的开发过程中,无法避免的会遇到接口迭代的过程,如何保证新老接口的共存和接口的向前的兼容呢,这时候就需要对Api进行版本的控制,那如何优雅的控制Api的版本呢&#xff1f;开始Microsoft.AspNetCore.Mvc.Versioning 是一个微软官方推出的一个用于管理Api版本的包,配…