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

count command performance optimization should support more complex queries

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.5, 3.0.0-rc8
    • Component/s: Querying
    • Query Optimization
    • Fully Compatible

      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.

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            andrew.ryder@mongodb.com Andrew Ryder (Inactive)
            Votes:
            6 Vote for this issue
            Watchers:
            34 Start watching this issue

              Created:
              Updated: