[SERVER-5189] Retrieving fields from a covered index doesn't use the covered index when fields are specified with _true_ instead of _1_ Created: 03/Mar/12  Updated: 15/Feb/13  Resolved: 03/Nov/12

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.0.1
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Mark Kwan Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-3156 query projection spec using 'true' in... Closed
Operating System: ALL
Participants:

 Description   

When only retrieving fields from a covered index, if the fields to be returned are specified with true instead of 1, explain() indicates that the covered index isn't used.

PRIMARY> db.version();
2.0.1
PRIMARY> db.temp.getIndexes();
[
        {
                "v" : 1,
                "key" : {
                        "_id" : 1
                },
                "ns" : "test.temp",
                "name" : "_id_"
        }
]
PRIMARY> db.temp.find({_id:'1'},{_id:true}).explain();
{
        "cursor" : "BtreeCursor _id_",
        "nscanned" : 0,
        "nscannedObjects" : 0,
        "n" : 0,
        "millis" : 13,
        "nYields" : 0,
        "nChunkSkips" : 0,
        "isMultiKey" : false,
        "indexOnly" : false,
        "indexBounds" : {
                "_id" : [
                        [
                                "1",
                                "1"
                        ]
                ]
        }
}
PRIMARY> db.temp.find({_id:'1'},{_id:1}).explain();
{
        "cursor" : "BtreeCursor _id_",
        "nscanned" : 0,
        "nscannedObjects" : 0,
        "n" : 0,
        "millis" : 0,
        "nYields" : 0,
        "nChunkSkips" : 0,
        "isMultiKey" : false,
        "indexOnly" : true,
        "indexBounds" : {
                "_id" : [
                        [
                                "1",
                                "1"
                        ]
                ]
        }
}

If explain is truly correct here, this seems to violate the principle of least astonishment.



 Comments   
Comment by Mark Kwan [ 03/Mar/12 ]

It seems like my queries on large datasets are much faster now with _id:1, so it appears that this isn't just a cosmetic issue with explain.

Generated at Thu Feb 08 03:08:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.