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

mongoS changes projections for queries for unsharded collections unnecessarily

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.4
    • Component/s: Querying, Sharding
    • None

      In a sharded cluster, but using an unsharded collection, mongoS, given the query:

      mongos.getDB("db").foo.find({a:1}, {a:1}).sort({b:1})
      Index:{a:1}
      

      Will rewrite to:

      .find({a:1}, {a:1, b:1}).sort({b:1})
      

      This can be observed by running the mongoD at logLevel:2 or greater.

      As this is targeting a single shard, the query can run as is, mongoD will return everything in correct sorted order.

      Two possible answers:

      1. This is the correct behavior, we will always rewrite (and accept the cost of adding projections). Better for query plan cache filters.
      2. This isn't correct behavior and when a single shard is targeted the query shouldn't be rewritten. Better for speed and efficiency.

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            charlie.page@10gen.com Charlie Page
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: