[SERVER-23330] Optimize aggregation on sharded setup if first stage is exact match on shard key with $in Created: 24/Mar/16  Updated: 11/Apr/16  Resolved: 07/Apr/16

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: James O'Leary Assignee: Benjamin Murphy
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-18940 Optimise sharded aggregations that ar... Closed
duplicates SERVER-21065 Optimizer should consider predicate w... Closed
Related
is related to SERVER-7656 Optimize aggregation on sharded setup... Closed
Backwards Compatibility: Fully Compatible
Sprint: Query 12 (04/04/16), Query 13 (04/22/16)
Participants:

 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.

Generated at Thu Feb 08 04:03:04 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.