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

Query planner sort analysis incorrectly allows index key pattern plugin fields to provide sort

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.6.5, 2.7.7
    • Affects Version/s: 2.6.4
    • Component/s: Querying
    • None
    • ALL
    • Hide
      use test;
       
      db.sorthashed.insert([
          {str:'bravo'},
          {str:'alpha'},
          {str:'tango'},
          {str:'charlie'}
      ]); // intentionally inserted out of alpha order, field in question is `str`
      db.sorthashed.find({}).sort({str:1}).pretty(); // shows in order
       
      db.sorthashed.ensureIndex({str:'hashed'},{background:false});
      db.sorthashed.find({}).sort({str:1}).pretty(); // shows in order
      
      db.sorthashed.find({str: {$in: ['bravo', 'alpha', 'tango', 'charlie']}}).sort({str:1}) // shows out of order
      
      Show
      use test; db.sorthashed.insert([ {str: 'bravo' }, {str: 'alpha' }, {str: 'tango' }, {str: 'charlie' } ]); // intentionally inserted out of alpha order, field in question is `str` db.sorthashed.find({}).sort({str:1}).pretty(); // shows in order db.sorthashed.ensureIndex({str: 'hashed' },{background: false }); db.sorthashed.find({}).sort({str:1}).pretty(); // shows in order db.sorthashed.find({str: {$ in : [ 'bravo' , 'alpha' , 'tango' , 'charlie' ]}}).sort({str:1}) // shows out of order
    • 0

      It seems when query planner uses hashed index for search, the same hashed index will be used for sorting. The use-case is a light modification of use-case listed in SERVER-13899

      Reproduced on mongod-2.6.4

            Assignee:
            rassi J Rassi
            Reporter:
            korum Konstantin Kardamanov
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: