diff options
author | Yoonsoo Kim <yoonsoo.kim@mongodb.com> | 2022-05-04 20:36:39 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-05-04 22:17:46 +0000 |
commit | 25c0fbade9ec93a3c5458fc5c7d2481adad064c7 (patch) | |
tree | 42e5ea6adc8ef426f56b4d398b7af91d9f26489f /jstests/noPassthroughWithMongod/group_pushdown.js | |
parent | 2276eedfbdf6a42d9a70986f88b984950be3a251 (diff) | |
download | mongo-25c0fbade9ec93a3c5458fc5c7d2481adad064c7.tar.gz |
SERVER-65465 Have the SBE $sum use a simple `sum` for a count-like sum
Diffstat (limited to 'jstests/noPassthroughWithMongod/group_pushdown.js')
-rw-r--r-- | jstests/noPassthroughWithMongod/group_pushdown.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/jstests/noPassthroughWithMongod/group_pushdown.js b/jstests/noPassthroughWithMongod/group_pushdown.js index 0f127a67792..53fb17ce8f2 100644 --- a/jstests/noPassthroughWithMongod/group_pushdown.js +++ b/jstests/noPassthroughWithMongod/group_pushdown.js @@ -155,6 +155,25 @@ assert.eq( coll.aggregate([{$match: {item: "c"}}]).toArray(), [{"_id": 5, "item": "c", "price": 5, "quantity": 10, "date": ISODate("2014-02-15T09:05:00Z")}]); +// Run a simple $group with {$sum: 1} accumulator, and check if it gets pushed down. +assertResultsMatchWithAndWithoutGroupPushdown( + coll, + [{$group: {_id: "$item", c: {$sum: NumberInt(1)}}}], + [{_id: "a", c: NumberInt(2)}, {_id: "b", c: NumberInt(2)}, {_id: "c", c: NumberInt(1)}], + 1); + +assertResultsMatchWithAndWithoutGroupPushdown( + coll, + [{$group: {_id: "$item", c: {$sum: NumberLong(1)}}}], + [{_id: "a", c: NumberLong(2)}, {_id: "b", c: NumberLong(2)}, {_id: "c", c: NumberLong(1)}], + 1); + +assertResultsMatchWithAndWithoutGroupPushdown( + coll, + [{$group: {_id: "$item", c: {$sum: 1}}}], + [{_id: "a", c: 2}, {_id: "b", c: 2}, {_id: "c", c: 1}], + 1); + // Run a simple $group with supported $sum accumulator, and check if it gets pushed down. assertResultsMatchWithAndWithoutGroupPushdown( coll, @@ -577,6 +596,12 @@ assert.neq(null, getAggPlanStage(explain, "GROUP"), explain); // Verifies that a basic sharded $sum accumulator works. assertShardedGroupResultsMatch(coll, [{$group: {_id: "$item", s: {$sum: "$quantity"}}}]); +// Verifies that a sharded count-like accumulator works +assertShardedGroupResultsMatch(coll, [{$group: {_id: "$item", s: {$sum: NumberInt(1)}}}]); +assertShardedGroupResultsMatch(coll, [{$group: {_id: "$item", s: {$sum: NumberLong(1)}}}]); +assertShardedGroupResultsMatch(coll, [{$group: {_id: "$item", s: {$sum: 1}}}]); +assertShardedGroupResultsMatch(coll, [{$group: {_id: "$item", s: {$count: {}}}}]); + // When there's overflow for 'NumberLong', the mongod sends back the partial sum as a doc with // 'subTotal' and 'subTotalError' fields. So, we need an overflow case to verify such behavior. const tcoll = db.group_pushdown1; |