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

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Aggregation Framework
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible
    • Sprint:
      Query 12 (04/04/16), Query 13 (04/22/16)

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: