查询:
db.myColl.find({"M.ST": "mostrepresentedvalueinthecollection", "M.TS": new Date(2014,2,1)}).explain()
解释输出:
"cursor" : "BtreeCursor M.ST_1_M.TS_1",
"isMultiKey" : false,
"n" : 587606,
"nscannedObjects" : 587606,
"nscanned" : 587606,
"nscannedObjectsAllPlans" : 587606,
"nscannedAllPlans" : 587606,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 9992,
"nChunkSkips" : 0,
"millis" : 174820,
"indexBounds" : {
"M.ST" : [
[
"mostrepresentedvalueinthecollection",
"mostrepresentedvalueinthecollection"
]
],
"M.TS" : [
[
ISODate("2014-03-01T00:00:00Z"),
ISODate("2014-03-01T00:00:00Z")
]
]
},
"server" : "myServer"
附加细节:myColl 包含大约 40m 文档,平均对象大小为 300b。
我不明白为什么 indexOnly 没有设置为 true,我在 {"M.ST":1, "M.TS":1} 上有一个复合索引
mongo 主机是一个带有 16gb RAM 和 500gb 磁盘空间(旋转磁盘)的 unix 机器。数据库的总索引大小为 10gb,我们有大约 1k upserts/sec,在这 1K 20 上是插入,其余的是增量。
我们有另一个查询,它在查找查询中添加了第三个字段(称为“MX”),以及“M.ST”、“MX”、“M.TS”上的复合索引。那是闪电般的速度,只扫描 330 个文档。
知道有什么问题吗?
谢谢。
编辑:这是示例文档的结构:
{
"_id" : "somestring",
"D" : {
"20140301" : {
"IM" : {
"CT" : 143
}
},
"20140302" : {
"IM" : {
"CT" : 44
}
},
"20140303" : {
"IM" : {
"CT" : 206
}
},
"20140314" : {
"IM" : {
"CT" : 5
}
}
},
"Y" : "someotherstring",
"IM" : {
"CT" : 1
},
"M" : {
"X" : 99999,
"ST" : "mostrepresentedvalueinthecollection",
"TS" : ISODate("2014-03-01T00:00:00.000Z")
},
}
这个想法是按月存储一些分析指标,“D”字段表示包含该月每一天的数据的文档数组。