I know it is not efficient, but it is useless in the following case.
And I should mention that the index is highly selective. Who can tell
me the reason??
query:
db.PfpModelTaskDO.find({ nextService: { $nin: [ "taskOverService",
"taskFailedService" ] }})
collection:
PFP:PRIMARY> db.PfpModelTaskDO.stats()
{
"ns" : "taobaoP4PTask.PfpModelTaskDO",
"count" : 1043643,
"size" : 972910876,
"avgObjSize" : 932.2257476934162,
"storageSize" :
3295053824,
"numExtents" : 29,
"nindexes" : 5,
"lastExtentSize" : 555698944,
"paddingFactor" : 1.7799999999019072,
"flags" : 1,
"totalIndexSize" : 394747904,
"indexSizes" : {
"_id_" : 57008128,
"gmtCreate_1" : 53673984,
"taskStatus_1_taskRandomCount_1_nextTime_1" : 92520448,
"sellerID_1_taskStatus_1_requestService_1_nextService_1_gmtCreate_1" :
143974400,
"nextService_1" : 47570944
},
"ok" : 1
}
query plan 1, without hint:
PFP:PRIMARY> db.PfpModelTaskDO.find({ nextService: { $nin:
[ "taskOverService", "taskFailedService" ] }}).explain()
{
"cursor" : "BasicCursor",
"nscanned" : 1043643,
"nscannedObjects" : 1043643,
"n" : 0,
"millis" : 1647,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
}
}
query plan 2, with hint:
PFP:PRIMARY> db.PfpModelTaskDO.find({ nextService: { $nin:
[ "taskOverService",
"taskFailedService" ] }}).hint("nextService_1").explain()
{
"cursor" : "BtreeCursor nextService_1",
"nscanned" : 1043643,
"nscannedObjects" : 1043643,
"n" : 0,
"millis" : 2056,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
"nextService" : [
[
{
"$minElement" : 1
},
{
"$maxElement" : 1
}
]
]
}
}