查询null时候用不上索引。只能进行过滤。建议使用空值或者有意义值来填充。
db.POCCOLL.explain(“executionStats”).count({“fld0″:{$eq: NumberLong(497408)},”fld15”:null})
“inputStage” : {
“stage” : “FETCH”,
“filter” : {
“fld15” : {
“$eq” : null
}
},
“nReturned” : 16,
“executionTimeMillisEstimate” : 0,
“works” : 17,
“advanced” : 16,
“needTime” : 0,
“needYield” : 0,
“saveState” : 0,
“restoreState” : 0,
“isEOF” : 1,
“docsExamined” : 16,
“alreadyHasObj” : 0,
“inputStage” : {
“stage” : “IXSCAN”,
“nReturned” : 16,
“executionTimeMillisEstimate” : 0,
“works” : 17,
“advanced” : 16,
“needTime” : 0,
“needYield” : 0,
“saveState” : 0,
“restoreState” : 0,
“isEOF” : 1,
“keyPattern” : {
“fld0” : 1,
“fld15” : 1
},
“indexName” : “fld0_1_fld15_1”,
“isMultiKey” : false,
“multiKeyPaths” : {
“fld0” : [ ],
“fld15” : [ ]
},
“isUnique” : false,
“isSparse” : false,
“isPartial” : false,
“indexVersion” : 2,
“direction” : “forward”,
“indexBounds” : {
“fld0” : [
“[497408, 497408]”
],
“fld15” : [
“[undefined, undefined]”,
“[null, null]”
]
},
“keysExamined” : 17,
“seeks” : 1,
“dupsTested” : 0,
“dupsDropped” : 0
db.POCCOLL.explain(“executionStats”).count({“fld0″:{$eq: NumberLong(497408)},”fld15”:1})
“executionStats” : {
“executionSuccess” : true,
“nReturned” : 0,
“executionTimeMillis” : 0,
“totalKeysExamined” : 1,
“totalDocsExamined” : 0,
“executionStages” : {
“stage” : “COUNT”,
“nReturned” : 0,
“executionTimeMillisEstimate” : 0,
“works” : 1,
“advanced” : 0,
“needTime” : 0,
“needYield” : 0,
“saveState” : 0,
“restoreState” : 0,
“isEOF” : 1,
“nCounted” : 0,
“nSkipped” : 0,
“inputStage” : {
“stage” : “COUNT_SCAN”,
“nReturned” : 0,
“executionTimeMillisEstimate” : 0,
“works” : 1,
“advanced” : 0,
“needTime” : 0,
“needYield” : 0,
“saveState” : 0,
“restoreState” : 0,
“isEOF” : 1,
“keysExamined” : 1,
“keyPattern” : {
“fld0” : 1,
“fld15” : 1
},
“indexName” : “fld0_1_fld15_1”,
“isMultiKey” : false,
“multiKeyPaths” : {
“fld0” : [ ],
“fld15” : [ ]
},
“isUnique” : false,
“isSparse” : false,
“isPartial” : false,
“indexVersion” : 2,
“indexBounds” : {
“startKey” : {
“fld0” : NumberLong(497408),
“fld15” : 1
},
“startKeyInclusive” : true,
“endKey” : {
“fld0” : NumberLong(497408),
“fld15” : 1
},
“endKeyInclusive” : true
}
}
}