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

$in queries do not use clustered index

    XMLWordPrintable

Details

    • Improvement
    • Status: Open
    • Major - P3
    • Resolution: Unresolved
    • 5.0.0
    • None
    • None

    Description

      A query that uses $in on _id does not plan against a clustered index if one exists. If no suitable secondary index exists, we fall back to a collection scan.

      This affects queries directly on time-series buckets collections.

      test> db.createCollection('clustered', {clusteredIndex: {key: {_id: 1}, unique: true}})
      test> db.clustered.find({_id: {$in: [0,1,2,3]}}).explain()
      {
        explainVersion: '1',
        queryPlanner: {
          namespace: 'test.clustered',
          indexFilterSet: false,
          parsedQuery: { _id: { '$in': [ 0, 1, 2, 3 ] } },
          queryHash: '0D7870DC',
          planCacheKey: '0D7870DC',
          maxIndexedOrSolutionsReached: false,
          maxIndexedAndSolutionsReached: false,
          maxScansToExplodeReached: false,
          winningPlan: {
            stage: 'COLLSCAN',
            filter: { _id: { '$in': [ 0, 1, 2, 3 ] } },
            direction: 'forward'
          },
          rejectedPlans: []
        },
      

      Attachments

        Activity

          People

            michael.gargiulo@mongodb.com Michael Gargiulo
            louis.williams@mongodb.com Louis Williams
            Votes:
            2 Vote for this issue
            Watchers:
            12 Start watching this issue

            Dates

              Created:
              Updated: