Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-12843

Encoding of projection for query plan cache should be order-insensitive

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.6.0-rc1
    • Affects Version/s: 2.6.0-rc0
    • Component/s: Querying
    • Fully Compatible
    • ALL

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

            Assignee:
            benety.goh@mongodb.com Benety Goh
            Reporter:
            rassi J Rassi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: