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

Query with empty in clause performs collection scan

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor - P4 Minor - P4
    • None
    • 4.0.17
    • None
    • Query Optimization
    • ALL
    • Hide

      db.collection.explain().aggregate([{$match: {Field: {$in: []}}}])

      or

      db.collection.find({Field: {$in: []}}).explain("executionStats")

      Where there is no index on Field 

      Show
      db.collection.explain().aggregate([{$match: {Field: {$in: []}}}]) or db.collection.find({Field: {$in: []}}).explain("executionStats") Where there is no index on Field 

    Description

      Both find and aggregate will perform a scan when the search criteria is {$in: [ ]} and the searched field is not indexed. 

      IMHO the query should either immediately return zero documents or throw an error due to the empty array.

      Attachments

        Activity

          People

            backlog-query-optimization Backlog - Query Optimization
            peter.williamson@mongodb.com Peter Williamson
            Votes:
            1 Vote for this issue
            Watchers:
            11 Start watching this issue

            Dates

              Created:
              Updated: