as my current task I have to optimize the indexes so that some of our queries run faster. I read this article: http://emptysqua.re/blog/optimizing-mongodb-compound-indexes/
as this guys suggests My optimal query is when:
nscanned= nscannedObject = n
Well, I was able to achieve that. The problem however that the query satisfying this formula is slower than the one does not ! Here is my explain output :
{
"cursor" : "BtreeCursor previous_sticky_1",
"nscanned" : 65019,
"nscannedObjects" : 65019,
"n" : 65019,
"millis" : 5456,
"nYields" : 76,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
}//everything is ok ( nscanned= nscannedObject = n )
{
"cursor" : "BtreeCursor subnetInfo.giAddr_1",
"nscanned" : 65023,
"nscannedObjects" : 65023,
"n" : 65019,
"scanAndOrder" : true,
"millis" : 3355,
"nYields" : 37,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false
} // nscanned = nscannedObject > n but , "millis = 3355 < 5456 " ???
Can you guys suggest why is that ? and which index to use ? subnetInfo.giAddr_1 or previous_sticky_1 ?