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

unnecessarily large nScanned occurs during sharded $in queries with sort() and limit()

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Duplicate
    • Affects Version/s: 1.8.2
    • Fix Version/s: None
    • Component/s: Querying
    • Labels:
      None

      Description

      A large number of nScannedObjects occurs when a sharded $in query contains both a limit() and sort() clause.

      For example, we have a checkins collection which is sharded by

      {uid: 1}

      and contains the index

      {uid: 1, _id: -1}

      . A db.checkins.find({uid: {$in: [400438]}}).limit(2).sort({_id: -1}) will scan just the two documents returned. db.checkins.find({uid: {$in: [400438, 32]}}).limit(2).sort({_id: -1}) will scan thousands of documents.

      The attachment walks through the example with an interactive console.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: