db.runCommand({ "aggregate": "collection_name", "pipeline": [ { "$match": { "CompanyId": { "$gte": 720, "$lte": 740 } } }, { "$project": { "CompanyId": 1, "_id": 0} }, { "$group": { "_id": "$CompanyId", "total": { "$sum": 1 } } } ]})
db.collection_name.find({"CompanyId": {"$gte": 720, "$lte": 740}}, {"CompanyId": 1, "_id": 0})
解釋第二個查詢許多蒙戈頁面錯誤當查詢被索引覆蓋
{
"cursor" : "BtreeCursor CompanyId_1",
"isMultiKey" : false,
"n" : 491699,
"nscannedObjects" : 0,
"nscanned" : 491699,
"nscannedObjectsAllPlans" : 0,
"nscannedAllPlans" : 491699,
"scanAndOrder" : false,
"indexOnly" : true,
"nYields" : 3841,
"nChunkSkips" : 0,
"millis" : 424,
"indexBounds" : {
"CompanyId" : [
[
720,
740
]
]
},
"filterSet" : false
}
查詢被指數所覆蓋的,但有許多nYields。 Mongo索引的總大小是700Mb。服務器有6GB RAM。
Agreggation查詢很慢(5-25秒),mongostat顯示很多頁面錯誤(700頁錯誤) 即使在運行命令後,頁面錯誤也一樣。
db.runCommand({ touch: "collection_name", index: true })
請幫忙理解,它是怎麼回事。聚合查詢必須由索引覆蓋。爲什麼有這麼多頁面錯誤?
上CompanyId定義指標不包括 – Disposer 2014-11-25 08:28:45
聚集查詢,它將從磁盤加載的文件。目前彙總不能使用覆蓋索引 – Sammaye 2014-11-25 09:33:09
@Sammaye:雖然這個評論很簡短,但我認爲它值得升級到答案,也許有一個鏈接到文檔。 – 2014-11-25 12:30:28