diff options
author | Svilen Mihaylov <svilen.mihaylov@mongodb.com> | 2022-01-31 21:05:27 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-01-31 21:48:46 +0000 |
commit | 50db8e9573e191ba2c193b4ef3dba6b5c6488f82 (patch) | |
tree | 1d211e40920b5952af569bb6e9fa7dd830d5bbaa /jstests/cqf_parallel | |
parent | b696e034fe97e7699dd45ac2595422e1d510ba2c (diff) | |
download | mongo-50db8e9573e191ba2c193b4ef3dba6b5c6488f82.tar.gz |
SERVER-62434 Implement query optimizer based on Path algebra and Cascades
Diffstat (limited to 'jstests/cqf_parallel')
-rw-r--r-- | jstests/cqf_parallel/basic_exchange.js | 22 | ||||
-rw-r--r-- | jstests/cqf_parallel/groupby.js | 37 | ||||
-rw-r--r-- | jstests/cqf_parallel/index.js | 25 |
3 files changed, 84 insertions, 0 deletions
diff --git a/jstests/cqf_parallel/basic_exchange.js b/jstests/cqf_parallel/basic_exchange.js new file mode 100644 index 00000000000..3be8768b0de --- /dev/null +++ b/jstests/cqf_parallel/basic_exchange.js @@ -0,0 +1,22 @@ +(function() { +"use strict"; + +load("jstests/libs/optimizer_utils.js"); // For checkCascadesOptimizerEnabled. +if (!checkCascadesOptimizerEnabled(db)) { + jsTestLog("Skipping test because the optimizer is not enabled"); + return; +} + +const t = db.cqf_exchange; +t.drop(); + +assert.commandWorked(t.insert({a: {b: 1}})); +assert.commandWorked(t.insert({a: {b: 2}})); +assert.commandWorked(t.insert({a: {b: 3}})); +assert.commandWorked(t.insert({a: {b: 4}})); +assert.commandWorked(t.insert({a: {b: 5}})); + +const res = t.explain("executionStats").aggregate([{$match: {'a.b': 2}}]); +assert.eq(1, res.executionStats.nReturned); +assert.eq("Exchange", res.queryPlanner.winningPlan.optimizerPlan.child.nodeType); +}()); diff --git a/jstests/cqf_parallel/groupby.js b/jstests/cqf_parallel/groupby.js new file mode 100644 index 00000000000..91fa3fc80fa --- /dev/null +++ b/jstests/cqf_parallel/groupby.js @@ -0,0 +1,37 @@ +(function() { +"use strict"; + +load("jstests/libs/optimizer_utils.js"); // For checkCascadesOptimizerEnabled. +if (!checkCascadesOptimizerEnabled(db)) { + jsTestLog("Skipping test because the optimizer is not enabled"); + return; +} + +const t = db.cqf_exchange; +t.drop(); + +assert.commandWorked(t.insert({a: 1})); +assert.commandWorked(t.insert({a: 2})); +assert.commandWorked(t.insert({a: 3})); +assert.commandWorked(t.insert({a: 4})); +assert.commandWorked(t.insert({a: 5})); + +// Demonstrate local-global optimization. +const res = t.explain("executionStats").aggregate([{$group: {_id: "$a", cnt: {$sum: 1}}}]); +assert.eq(5, res.executionStats.nReturned); + +assert.eq("Exchange", res.queryPlanner.winningPlan.optimizerPlan.child.nodeType); +assert.eq("Centralized", res.queryPlanner.winningPlan.optimizerPlan.child.distribution.type); + +assert.eq("GroupBy", res.queryPlanner.winningPlan.optimizerPlan.child.child.child.nodeType); + +assert.eq("Exchange", res.queryPlanner.winningPlan.optimizerPlan.child.child.child.child.nodeType); +assert.eq("HashPartitioning", + res.queryPlanner.winningPlan.optimizerPlan.child.child.child.child.distribution.type); + +assert.eq("GroupBy", + res.queryPlanner.winningPlan.optimizerPlan.child.child.child.child.child.nodeType); +assert.eq("UnknownPartitioning", + res.queryPlanner.winningPlan.optimizerPlan.child.child.child.child.child.properties + .physicalProperties.distribution.type); +}());
\ No newline at end of file diff --git a/jstests/cqf_parallel/index.js b/jstests/cqf_parallel/index.js new file mode 100644 index 00000000000..c155e9b9f61 --- /dev/null +++ b/jstests/cqf_parallel/index.js @@ -0,0 +1,25 @@ +(function() { +"use strict"; + +load("jstests/libs/optimizer_utils.js"); // For checkCascadesOptimizerEnabled. +if (!checkCascadesOptimizerEnabled(db)) { + jsTestLog("Skipping test because the optimizer is not enabled"); + return; +} + +const coll = db.cqf_parallel_index; +coll.drop(); + +const bulk = coll.initializeUnorderedBulkOp(); +for (let i = 0; i < 1000; i++) { + bulk.insert({a: i}); +} +assert.commandWorked(bulk.execute()); + +assert.commandWorked(coll.createIndex({a: 1})); + +let res = coll.explain("executionStats").aggregate([{$match: {a: {$lt: 10}}}]); +assert.eq(10, res.executionStats.nReturned); +assert.eq("IndexScan", + res.queryPlanner.winningPlan.optimizerPlan.child.child.leftChild.child.nodeType); +}()); |