[SERVER-12843] Encoding of projection for query plan cache should be order-insensitive Created: 22/Feb/14  Updated: 11/Jul/16  Resolved: 24/Feb/14

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.6.0-rc0
Fix Version/s: 2.6.0-rc1

Type: Bug Priority: Major - P3
Reporter: J Rassi Assignee: Benety Goh
Resolution: Done Votes: 0
Labels: 26qa
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-13008 Encoding of projection for query plan... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

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
		}
	}
]
>



 Comments   
Comment by Githook User [ 24/Feb/14 ]

Author:

{u'username': u'benety', u'name': u'Benety Goh', u'email': u'benety@mongodb.com'}

Message: SERVER-12843 Encoding of projection for query plan cache should be order-insensitive
Branch: master
https://github.com/mongodb/mongo/commit/d137daf04d83465bfbceacc96b56d13ae0a3c4e8

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