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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.6.4
    • Fix Version/s: 2.6.5, 2.7.7
    • Component/s: Querying
    • Labels:
      None
    • Operating System:
      ALL
    • Backport Completed:
    • Steps To Reproduce:
      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
    • Linked BF Score:
      0

      Description

      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

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                1 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: