我试图检查一个查询,但我不确定“nscannedObjectsAllPlans”和“nscannedAllPlans”在做什么,因为我看到如果我直接从索引字段“purchaseState”运行查询
对于“ nscannedObjects ”、“ nscanned ”、“ nscannedObjectsAllPlans ”和“ nscannedAllPlans ” ,我得到相同的扫描项目结果
但是,一旦我在查询中添加了大于 400 的价格, nscannedObjectsAllPlans现在大于nscannedObjects 我想知道 nscannedObjectsAllPlans是否是运行带有 purchase_state 索引和 purchase_state_Id 索引的计划的扫描对象的总数?还是只是说明两个指数计划结果中的较大者?
我向购买状态添加了一个索引,然后我在购买状态和 Id 上添加了一个索引
db.toys.ensureIndex({"purchaseState" : 1})
db.toys.ensureIndex({"purchaseState" : 1, "_id" : 1})
**db.toys.find({"purchaseState" : "NY"}).pretty().explain()**
"cursor" : "BtreeCursor purchaseState_1",
"isMultiKey" : false,
"n" : 1596,
"nscannedObjects" : 1596,
"nscanned" : 1596,
"nscannedObjectsAllPlans" : 1596,
"nscannedAllPlans" : 1596,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 3,
"indexBounds" : {
"purchaseState" : [
[
"NY",
"NY"
]
]
},
"server" : "XXXXXXX:27017"
**db.toys.find({"purchaseState" : "NY", "price": { $gt : 400 }}).pretty().explain()**
"cursor" : "BtreeCursor purchaseState_1",
"isMultiKey" : false,
"n" : 1423,
"nscannedObjects" : 1596,
"nscanned" : 1596,
"nscannedObjectsAllPlans" : 1808,
"nscannedAllPlans" : 1808,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 10,
"indexBounds" : {
"purchaseState" : [
[
"NY",
"NY"
]
]
},
"server" : "XXXXXXX:27017"