diff options
author | Eric Cox <eric.cox@mongodb.com> | 2021-04-28 15:44:53 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-04-30 14:51:37 +0000 |
commit | 49f6fcebd3c4a97abcd05c862ad1204eed9d66ef (patch) | |
tree | 23464ec2056ff4303fd34dbe2d2afaa09ab73eff /jstests | |
parent | f36132ec219dd8cfdab420403f10d18666249947 (diff) | |
download | mongo-49f6fcebd3c4a97abcd05c862ad1204eed9d66ef.tar.gz |
SERVER-56083 [SBE] Expressions unsupported in SBE for agg operations prevent SBE engine from being selected even if not pushed down
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/noPassthroughWithMongod/sbe_agg_pushdown.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/jstests/noPassthroughWithMongod/sbe_agg_pushdown.js b/jstests/noPassthroughWithMongod/sbe_agg_pushdown.js new file mode 100644 index 00000000000..c3f8d9259b2 --- /dev/null +++ b/jstests/noPassthroughWithMongod/sbe_agg_pushdown.js @@ -0,0 +1,57 @@ +// Tests aggregation queries containing a mix of SBE supported and unspported expressions execute +// the pushed down query with SBE. +// TODO: Remove this file when all agg expressions are supported by SBE. + +(function() { +"use strict"; + +load("jstests/libs/sbe_util.js"); // For checkSBEEnabled. + +const isSBEEnabled = checkSBEEnabled(db); +if (!isSBEEnabled) { + jsTestLog("Skipping test because the SBE feature flag is disabled"); + return; +} + +const coll = db.jstests_sbe_pushdown; +coll.drop(); + +// Helper that runs a 'pipeline' with explain mode to determine if SBE was used to execute the +// pushed down query or not. It does this by checking the 'explainVersion' of the plan against the +// 'expectedExplainVersion' input. If the plan has an 'explainVersion' of "2", then SBE was used to +// execute the pushed down query. Otherwise, an 'explainVersion' of "1" means the classic engine was +// used to execute the pushed down query. +function assertPushdownQueryExecMode(pipeline, expectedExplainVersion) { + assert(expectedExplainVersion === "1" || expectedExplainVersion === "2"); + const actualExplainVersion = coll.explain().aggregate(pipeline).explainVersion; + assert.eq(actualExplainVersion, expectedExplainVersion); +} + +assert.commandWorked(coll.insertMany([ + {_id: 0, a: 1, b: ISODate("2021-04-28T00:00:00Z")}, + {_id: 1, a: 2, b: ISODate("2021-04-28T10:00:00Z")}, + {_id: 2, a: 3, b: ISODate("2021-04-28T20:00:00Z")}, +])); + +// Test query with no supported expressions is executed with the classic engine. +assertPushdownQueryExecMode([{$project: {_id: 0, c: {$dateToString: {date: "$b"}}}}], "1"); + +// Test query that contains an expression unsupported by SBE that isn't pushed down. In this case, +// we still expect SBE to be used if the unsupported expression isn't pushed down. +assertPushdownQueryExecMode( + [ + {$match: {a: 2}}, + {$_internalInhibitOptimization: {}}, + {$project: {_id: 0, c: {$dateToString: {date: "$b"}}}} + ], + "2"); + +// Test query with an unsupported expression in a $project stage that's pushed down executes with +// the classic engine. +assertPushdownQueryExecMode( + [{$match: {a: 2}}, {$project: {_id: 0, c: {$dateToString: {date: "$b"}}}}], "1"); + +// Test query with fully supported expressions are executed with SBE when pushed down. +assertPushdownQueryExecMode( + [{$match: {$expr: {$eq: ["$b", {$dateFromParts: {year: 2021, month: 4, day: 28}}]}}}], "2"); +}()); |