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

count command performance optimization should support more complex queries

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: 2.6.5, 3.0.0-rc8
    • Fix Version/s: Backlog
    • Component/s: Querying
    • Labels:
    • Backwards Compatibility:
      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

          Issue Links

            Activity

              People

              Assignee:
              backlog-query-optimization Backlog - Query Optimization
              Reporter:
              andrew.ryder Andrew Ryder (Inactive)
              Participants:
              Votes:
              7 Vote for this issue
              Watchers:
              33 Start watching this issue

                Dates

                Created:
                Updated: