mongo索引全部命中,仍验证文档问题

发布问题 回首页

mongo索引全部命中,仍验证文档问题

★ 0 成为第一个关注这个问题的人

最近遇到一个问题,非常不理解,请各路大神帮忙分析下
我有一个collection,有200w条数据,建了一个索引如下:
db.getCollection(“mycollection”).createIndex({“cityId” : 1, “opStatus” : 1, “vehicleStatus”: 1, “vehiclePos” : “2dsphere”, “hbTime” : 1}, {name: “idx_city_opstatus_pos”, background: true});
索引包含5个字段 cityId(int), opStatus(int), vehicleStatus(int), vehiclePos(位置,lng, lat), hbTime(date)。
然后下面是我的查询,查询条件完全跟索引一致:
db.getCollection(“mycollection”).explain(“executionStats”).count({“cityId”:17, “opStatus”:100, “hbTime”: {$gte: ISODate(“2018-07-28T00:00:00.000Z”)}, “vehicleStatus”:0,
vehiclePos: {
$geoWithin: {
$geometry: {
type: “Polygon”,
coordinates: [[[103.982647,30.779225],[103.969601,30.776718],[103.950375,30.760493],[103.943337,30.751347],[103.939217,30.745151],[103.93544,30.729658],[103.934925,30.713721],[103.932179,30.689514],[103.934239,30.673422],[103.93853,30.661167],[103.939389,30.645661],[103.94471,30.628233],[103.946942,30.615824],[103.950032,30.609028],[103.955868,30.604152],[103.964966,30.600015],[103.974922,30.595878],[103.986939,30.58716],[103.992947,30.586273],[104.00462,30.586273],[104.011315,30.585682],[104.01492,30.583317],[104.019211,30.580509],[104.029682,30.574154],[104.042557,30.570607],[104.038609,30.563513],[104.036892,30.541634],[104.037407,30.526996],[104.074143,30.5267],[104.083584,30.526996],[104.09972,30.525222],[104.09869,30.555678],[104.103153,30.568242],[104.120148,30.56839],[104.148129,30.571198],[104.164093,30.574746],[104.170273,30.578145],[104.174908,30.582874],[104.180058,30.590115],[104.187954,30.598538],[104.201,30.606959],[104.20512,30.611392],[104.20615,30.617597],[104.205464,30.634584],[104.206665,30.644627],[104.207695,30.650978],[104.207695,30.657328],[104.20718,30.667959],[104.205635,30.675489],[104.20409,30.697485],[104.202889,30.707817],[104.200314,30.725379],[104.197911,30.730396],[104.192074,30.73497],[104.182461,30.744413],[104.169243,30.75651],[104.163922,30.759903],[104.157913,30.764033],[104.10899,30.785566],[104.10281,30.786009],[104.076718,30.784534],[104.062126,30.785124],[104.038609,30.781732],[104.026078,30.779815],[103.994664,30.780995],[103.982647,30.779225]]]
}
}
}}, {hint: “idx_city_opstatus_pos”});

执行查询计划后发现:
“executionSuccess” : true,
“nReturned” : 0,
“executionTimeMillis” : 1174,
“totalKeysExamined” : 133221,
“totalDocsExamined” : 131684,
我想知道,既然查询条件跟索引字段是完全匹配的,为什么还扫描了文档,即totalDocsExamined为什么不是0?

JavaBeta 在大约 之前添加了 Open 状态
  • 提问于
  • Answers0 个
  • 浏览 5 次
  • 最新活跃于

问题状态

  • Open

类别

1 个 参与者

mongo索引全部命中,仍验证文档问题》有13个想法

  1. 谢答,但个人认为不准确,1.mr我觉得不适合实时计算,更贴合后期数据统计需求,2.aggregate必须支持自定义函数,就好像你定义个abc(1,2)一样肯定是计算了,现在的问题是abc(1,2)这个参数我想传个字段进去,比如abc($qty,2)这样….他就不好使了….难道大家没有在aggregate中用字段进行计算的经历么?

发表评论