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

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • 2.6.0-rc0
    • 2.6.0-rc1
    • Querying
    • Fully Compatible
    • ALL

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

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: