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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.6.0-rc0
    • Fix Version/s: 2.6.0-rc1
    • Component/s: Querying
    • Labels:
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      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

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

                Dates

                Created:
                Updated:
                Resolved: