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

Optimize aggregation on sharded setup if first stage is exact match on shard key with $in

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • None
    • Fully Compatible
    • Query 12 (04/04/16), Query 13 (04/22/16)

      When a $match contains an $in array with a single exact shard key match, the aggregation is not targetted to a single shard.

      The listed repro produces the following output on 3.0.10:

      $ mongo aggregation.js
      MongoDB shell version: 3.0.10
      connecting to: test
      { "e1" : null }
      {
      	"e2" : {
      		"shardsPart" : [
      			{
      				"$match" : {
      					"a" : {
      						"$in" : [
      							1
      						]
      					}
      				}
      			}
      		],
      		"mergerPart" : [ ]
      	}
      }
      

      And the following output on 3.2.4:

      $ mongo aggregation.js                                             
      MongoDB shell version: 3.2.4
      connecting to: test
      { "e1" : null }
      {
      	"e2" : {
      		"shardsPart" : [
      			{
      				"$match" : {
      					"a" : {
      						"$in" : [
      							1
      						]
      					}
      				}
      			}
      		],
      		"mergerPart" : [ ]
      	}
      }
      

      Notes:

      1. a find with / without the $in is correctly targetted to a single shard.
      2. I haven't tested multiple $in all targetted but it is likely that will also invoke a merge
      3. this issue is unrelated to SERVER-18940 as it is an exact shard key match.
      4. This issue is an related but distinct from SERVER-7656.

            Assignee:
            benjamin.murphy Benjamin Murphy
            Reporter:
            jim.oleary@mongodb.com James O'Leary
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved: