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

count command performance optimization should support more complex queries

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Major - P3 Major - P3
    • None
    • 2.6.5, 3.0.0-rc8
    • Querying
    • Query Optimization
    • Fully Compatible

    Description

      With a valid index to cover the queries, the following in the shell:

      db.coll.count({foo:{$in:[1,2]}});
      

      Is consistently upwards of an order of magnitude slower than:

      db.coll.count({foo:1}) + db.coll.count({foo:2})
      

      In my test, where 700k documents match each predicate, the first variant takes ~1500ms to run, the second variant (without $in) takes ~120ms.

      To reproduce requires no special documents, surrounding indexes don't matter, the index in use can be compound (include other fields), other documents present in the collection don't matter (overall cardinality is irrelevant, though the effect requires low cardinality for the items in test purely to measure it temporally).

      The effect described above does not apply to a regular query, it applies only to the count command. Thus, "explain" does not reveal the reason why in 2.6.5, however, it is possible to observe a difference in the plans by running count a newfangled 3.0 explainable collection.

      Attachments

        Activity

          People

            backlog-query-optimization Backlog - Query Optimization
            andrew.ryder@mongodb.com Andrew Ryder (Inactive)
            Votes:
            6 Vote for this issue
            Watchers:
            32 Start watching this issue

            Dates

              Created:
              Updated: