summaryrefslogtreecommitdiff
path: root/jstests/aggregation
diff options
context:
space:
mode:
authorKatherine Wu <katherine.wu@mongodb.com>2020-06-24 10:41:45 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-01-08 22:29:53 +0000
commit87d0144984752767599297de915c45d828316896 (patch)
treeacb0c955ed3027249b9e1c564b0d13ed6d47e764 /jstests/aggregation
parent455bdbb8bcc2166a14fe009d28e71ee6bf4de59e (diff)
downloadmongo-87d0144984752767599297de915c45d828316896.tar.gz
SERVER-40090 DISTINCT_SCAN is only used when certain format of $group _id is specified
(cherry picked from commit 20c0cc8c93f9ce27207067b0776bad08f84b47d0)
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).