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

Bad index selection on aggregate with $match + $sort

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Duplicate
    • None
    • None
    • Aggregation Framework
    • None
    • ALL

    Description

      I have a collection with 2m records. unique index on _id and foo columns

      db.col.aggregate([ { "$match" : { "foo" : "abcd" } }, { "$sort" : { "_id" : 1 } } ])
      

      takes about 5 seconds to return;

      db.col.aggregate([ { "$match" : { "foo" : "abcd" } } ])
      

      returns instantly. An explain shows that the first one chooses to use the _id index for some reason therefore causing a whole table scan. I seem to recall this also being an issue back in mongo 2.4 but is still there in mongo 3

      Attachments

        Issue Links

          Activity

            People

              charlie.swanson@mongodb.com Charlie Swanson
              mark.zealey Mark Zealey
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: