The following two queries should have the same shape:
> db.foo.getPlanCache().listQueryShapes() [ ] > db.foo.find({a:1},{b:1,a:1}) > db.foo.find({a:1},{a:1,b:1}) > db.foo.getPlanCache().listQueryShapes() [ { "query" : { "a" : 1 }, "sort" : { }, "projection" : { "a" : 1, "b" : 1 } }, { "query" : { "a" : 1 }, "sort" : { }, "projection" : { "b" : 1, "a" : 1 } } ]
Not only do some drivers (e.g. pymongo) store projection specifiers in unordered maps, but the shell and drivers also re-order projection specifiers (e.g. to move the _id projection to the front), so a user can't easily determine the order of a projection just from looking at application code:
> db.foo.getPlanCache().listQueryShapes() [ ] > db.foo.find({a:1},{a:1,_id:0}) // user enters _id:0 last.... > db.foo.getPlanCache().listQueryShapes() [ { "query" : { "a" : 1 }, "sort" : { }, "projection" : { "_id" : 0, // ... but the shell re-orders it to be first "a" : 1 } } ] >
- is related to
-
SERVER-13008 Encoding of projection for query plan cache should be type-insensitive
- Closed