diff options
author | Mihai Andrei <mihai.andrei@mongodb.com> | 2023-02-07 00:58:25 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-02-07 02:32:02 +0000 |
commit | b185d04364c298e701943a1e800c4036ce8df6e7 (patch) | |
tree | 6a91575c0096863e38b1b0fd12d1bfd90d55ac7f /jstests/aggregation | |
parent | 967a6745ba487edaff558e36fdc572c6ca066fea (diff) | |
download | mongo-b185d04364c298e701943a1e800c4036ce8df6e7.tar.gz |
SERVER-71798 Expand the set of queries eligible for SBE in the 6.3 release
Diffstat (limited to 'jstests/aggregation')
-rw-r--r-- | jstests/aggregation/add_with_date.js | 2 | ||||
-rw-r--r-- | jstests/aggregation/explain_limit.js | 2 | ||||
-rw-r--r-- | jstests/aggregation/optimize_away_pipeline.js | 89 |
3 files changed, 49 insertions, 44 deletions
diff --git a/jstests/aggregation/add_with_date.js b/jstests/aggregation/add_with_date.js index b80c304e42c..4d76a6908d7 100644 --- a/jstests/aggregation/add_with_date.js +++ b/jstests/aggregation/add_with_date.js @@ -28,8 +28,6 @@ assert.commandWorked(coll.insert({ nanDecimal: NumberDecimal("NaN"), })); -const isSBEEnabled = checkSBEEnabled(db, ["featureFlagSbeFull"]); - // Adding a Decimal128 value to a date literal. assert.eq(ISODate("2019-01-30T07:30:10.957Z"), getResultOfExpression({$add: ["$decimalVal", ISODate("2019-01-30T07:30:10.137Z")]})); diff --git a/jstests/aggregation/explain_limit.js b/jstests/aggregation/explain_limit.js index 7ce18401062..5e017f9b74e 100644 --- a/jstests/aggregation/explain_limit.js +++ b/jstests/aggregation/explain_limit.js @@ -18,7 +18,7 @@ let coll = db.explain_limit; const kCollSize = 105; const kLimit = 10; -const isSBEEnabled = checkSBEEnabled(db, ["featureFlagSbeFull"]); +const isSBEEnabled = checkSBEEnabled(db); // Return whether or explain() was successful and contained the appropriate fields given the // requested verbosity. Checks that the number of documents examined and returned are correct given diff --git a/jstests/aggregation/optimize_away_pipeline.js b/jstests/aggregation/optimize_away_pipeline.js index 065691a0663..453ee78db40 100644 --- a/jstests/aggregation/optimize_away_pipeline.js +++ b/jstests/aggregation/optimize_away_pipeline.js @@ -639,33 +639,66 @@ function assertProjectionIsNotRemoved(pipeline, projectionType = "PROJECTION_SIM assertProjectionCanBeRemovedBeforeGroup( [{$project: {a: 1, b: 1}}, {$group: {_id: "$a", s: {$sum: "$b"}}}]); -assertProjectionCanBeRemovedBeforeGroup( - [{$project: {'a.b': 1, 'b.c': 1}}, {$group: {_id: "$a.b", s: {$sum: "$b.c"}}}], - "PROJECTION_DEFAULT"); - -// Test that an inclusion projection is NOT optimized away if it is NOT redundant. This one fails to -// include a dependency of the $group and so will have an impact on the query results. +// Test that an inclusion projection is NOT optimized away if it is NOT redundant. This one +// fails to include a dependency of the $group and so will have an impact on the query results. assertProjectionIsNotRemoved([{$project: {a: 1}}, {$group: {_id: "$a", s: {$sum: "$b"}}}]); -// Test similar cases with dotted paths. -assertProjectionIsNotRemoved([{$project: {'a.b': 1}}, {$group: {_id: "$a.b", s: {$sum: "$b"}}}], - "PROJECTION_DEFAULT"); -assertProjectionIsNotRemoved([{$project: {'a.b': 1}}, {$group: {_id: "$a.b", s: {$sum: "$a.c"}}}], - "PROJECTION_DEFAULT"); // TODO SERVER-67323 This one could be removed, but is left for future work. assertProjectionIsNotRemoved( [{$project: {a: 1, b: 1}}, {$group: {_id: "$a.b", s: {$sum: "$b.c"}}}]); -// Spinoff on the one above: Without supporting this kind of prefixing analysis, we can confuse -// ourselves with our dependency analysis. If the $group depends on both "path" and "path.subpath" -// then it will generate a $project on only "path" to express its dependency set. We then fail to -// optimize that out. +// If the $group depends on both "path" and "path.subpath" then it will generate a $project on only +// "path" to express its dependency set. We then fail to optimize that out. As a future improvement, +// we could improve the optimizer to ensure that a projection stage is not present in the resulting +// plan. pipeline = [{$group: {_id: "$a.b", s: {$first: "$a"}}}]; // TODO SERVER-XYZ Assert this can be optimized out. // assertProjectionCanBeRemovedBeforeGroup(pipeline, "PROJECTION_DEFAULT"); // assertProjectionCanBeRemovedBeforeGroup(pipeline, "PROJECTION_SIMPLE"); assertProjectionIsNotRemoved(pipeline); +// Though $group is generally eligible for pushdown into SBE, such a pushdown may be inhibited by +// dotted as well as computed projections. As such we only run the test cases below if SBE is fully +// enabled. +const sbeFull = checkSBEEnabled(db, ["featureFlagSbeFull"], true /* checkAllNodes */); +if (sbeFull) { + assertProjectionCanBeRemovedBeforeGroup( + [{$project: {'a.b': 1, 'b.c': 1}}, {$group: {_id: "$a.b", s: {$sum: "$b.c"}}}], + "PROJECTION_DEFAULT"); + + // Test that a computed projection at the front of the pipeline is pushed down, even if there's + // no finite dependency set. + pipeline = [{$project: {x: {$add: ["$a", 1]}}}]; + assertPipelineDoesNotUseAggregation( + {pipeline: pipeline, expectedStages: ["COLLSCAN", "PROJECTION_DEFAULT"]}); + + // The projections below are not removed because they fail to include the $group's dependencies. + assertProjectionIsNotRemoved([{$project: {'a.b': 1}}, {$group: {_id: "$a.b", s: {$sum: "$b"}}}], + "PROJECTION_DEFAULT"); + assertProjectionIsNotRemoved( + [{$project: {'a.b': 1}}, {$group: {_id: "$a.b", s: {$sum: "$a.c"}}}], "PROJECTION_DEFAULT"); + + pipeline = [{$project: {a: {$add: ["$a", 1]}}}, {$group: {_id: "$a", s: {$sum: "$b"}}}]; + assertPipelineIfGroupPushdown( + // Test that a computed projection at the front of the pipeline is pushed down when there's + // a finite dependency set. Additionally, the group pushdown shouldn't erase the computed + // projection. + function() { + explain = coll.explain().aggregate(pipeline); + assertPipelineDoesNotUseAggregation( + {pipeline: pipeline, expectedStages: ["COLLSCAN", "PROJECTION_DEFAULT", "GROUP"]}); + }, + // Test that a computed projection at the front of the pipeline is pushed down when there's + // a finite dependency set. + function() { + explain = coll.explain().aggregate(pipeline); + assertPipelineUsesAggregation({ + pipeline: pipeline, + expectedStages: ["COLLSCAN", "PROJECTION_DEFAULT", "$group"], + }); + }); +} + // We generate a projection stage from dependency analysis, even if the pipeline begins with an // exclusion projection. pipeline = [{$project: {c: 0}}, {$group: {_id: "$a", b: {$sum: "$b"}}}]; @@ -696,32 +729,6 @@ pipeline = [{$project: {x: 0}}]; assertPipelineDoesNotUseAggregation( {pipeline: pipeline, expectedStages: ["PROJECTION_SIMPLE", "COLLSCAN"]}); -// Test that a computed projection at the front of the pipeline is pushed down, even if there's no -// finite dependency set. -pipeline = [{$project: {x: {$add: ["$a", 1]}}}]; -assertPipelineDoesNotUseAggregation( - {pipeline: pipeline, expectedStages: ["COLLSCAN", "PROJECTION_DEFAULT"]}); - -pipeline = [{$project: {a: {$add: ["$a", 1]}}}, {$group: {_id: "$a", s: {$sum: "$b"}}}]; -assertPipelineIfGroupPushdown( - // Test that a computed projection at the front of the pipeline is pushed down when there's a - // finite dependency set. Additionally, the group pushdown shouldn't erase the computed - // projection. - function() { - explain = coll.explain().aggregate(pipeline); - assertPipelineDoesNotUseAggregation( - {pipeline: pipeline, expectedStages: ["COLLSCAN", "PROJECTION_DEFAULT", "GROUP"]}); - }, - // Test that a computed projection at the front of the pipeline is pushed down when there's a - // finite dependency set. - function() { - explain = coll.explain().aggregate(pipeline); - assertPipelineUsesAggregation({ - pipeline: pipeline, - expectedStages: ["COLLSCAN", "PROJECTION_DEFAULT", "$group"], - }); - }); - // getMore cases. // Test getMore on a collection with an optimized away pipeline. |