summaryrefslogtreecommitdiff
path: root/jstests/aggregation
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/aggregation')
-rw-r--r--jstests/aggregation/group_conversion_to_distinct_scan.js12
1 files changed, 12 insertions, 0 deletions
diff --git a/jstests/aggregation/group_conversion_to_distinct_scan.js b/jstests/aggregation/group_conversion_to_distinct_scan.js
index 226dea6f584..5b947b47e02 100644
--- a/jstests/aggregation/group_conversion_to_distinct_scan.js
+++ b/jstests/aggregation/group_conversion_to_distinct_scan.js
@@ -474,6 +474,18 @@ assertResultsMatchWithAndWithoutHintandIndexes(pipeline, [{_id: 1}, {_id: 2}, {_
explain = coll.explain().aggregate(pipeline);
assert.eq(null, getAggPlanStage(explain, "DISTINCT_SCAN"), explain);
+//
+// Verify that a $sort-$group pipeline with a $first accumulator can use DISTINCT_SCAN, even when
+// the group _id field is a singleton object instead of a fieldPath.
+//
+pipeline = [{$sort: {a: 1, b: 1}}, {$group: {_id: {v: "$a"}, accum: {$first: "$b"}}}];
+assertResultsMatchWithAndWithoutHintandIndexes(
+ pipeline, [{_id: {v: null}, accum: null}, {_id: {v: 1}, accum: 1}, {_id: {v: 2}, accum: 2}]);
+explain = coll.explain().aggregate(pipeline);
+assert.neq(null, getAggPlanStage(explain, "DISTINCT_SCAN"), explain);
+assert.eq({a: 1, b: 1, c: 1}, getAggPlanStage(explain, "DISTINCT_SCAN").keyPattern);
+assert.eq(null, getAggPlanStage(explain, "SORT"), explain);
+
////////////////////////////////////////////////////////////////////////////////////////////////
// We execute all the collation-related tests three times with three different configurations
// (no index, index without collation, index with collation).