mongodb

 db.testData.find({"groups":{$gt:10,$lt:15}}).explain()
{
        "cursor" : "BasicCursor",
        "isMultiKey" : false,
        "n" : 4,
        "nscannedObjects" : 10000,
        "nscanned" : 10000,
        "nscannedObjectsAllPlans" : 10000,
        "nscannedAllPlans" : 10000,
        "scanAndOrder" : false,
        "indexOnly" : false,
        "nYields" : 0,
        "nChunkSkips" : 0,
        "millis" : 10,
        "indexBounds" : {

        },
        "server" : "ubuntu:27017"
}
> db.testData.ensureIndex({"groups":1})
> db.testData.find({"groups":{$gt:10,$lt:15}}).explain()
{
        "cursor" : "BtreeCursor groups_1",
        "isMultiKey" : false,
        "n" : 4,
        "nscannedObjects" : 4,
        "nscanned" : 4,
        "nscannedObjectsAllPlans" : 4,
        "nscannedAllPlans" : 4,
        "scanAndOrder" : false,
        "indexOnly" : false,
        "nYields" : 0,
        "nChunkSkips" : 0,
        "millis" : 0,
        "indexBounds" : {
                "groups" : [
                        [
                                10,
                                15
                        ]
                ]
        },
        "server" : "ubuntu:27017"
}
> db.testData.find({"groups":{$gt:10,$lt:15}}).explain()
{
        "cursor" : "BtreeCursor groups_1",
        "isMultiKey" : false,
        "n" : 4,
        "nscannedObjects" : 4,
        "nscanned" : 4,
        "nscannedObjectsAllPlans" : 4,
        "nscannedAllPlans" : 4,
        "scanAndOrder" : false,
        "indexOnly" : false,
        "nYields" : 0,
        "nChunkSkips" : 0,
        "millis" : 0,
        "indexBounds" : {
                "groups" : [
                        [
                                10,
                                15
                        ]
                ]
        },
        "server" : "ubuntu:27017"
}

mongodb查询 加索引 减索引 的查询效果差别 :

nscanned体现了Mongo扫描字段索引的条数,而nscannedObjects则为最终结果中查询过的文档数目。n则表示了返回文档的数目。nscannedObjects至少包含了所有的返回文档,即使Mongo明确了可以通过查看绝对匹配文件的索引。因此可以得出nscanned >= nscannedObjects >= n。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值