diff options
author | Svilen Mihaylov <svilen.mihaylov@mongodb.com> | 2022-05-27 19:35:12 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-05-27 20:47:40 +0000 |
commit | c812983558ae5a4543db6b16f26ce1190edfdef7 (patch) | |
tree | c5c6f7f06d9a7500e944f4ebeb9ddd3e6f8cf40c /jstests/cqf/array_match.js | |
parent | a474d4efa5a999526e696423af5d30f4f5187613 (diff) | |
download | mongo-c812983558ae5a4543db6b16f26ce1190edfdef7.tar.gz |
SERVER-62961 Fix ABT->SBE lowering of EvalFilter paths to correctly handle comparisons with arrays
Diffstat (limited to 'jstests/cqf/array_match.js')
-rw-r--r-- | jstests/cqf/array_match.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/jstests/cqf/array_match.js b/jstests/cqf/array_match.js new file mode 100644 index 00000000000..59e3047adb7 --- /dev/null +++ b/jstests/cqf/array_match.js @@ -0,0 +1,57 @@ +(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_array_match; +t.drop(); + +assert.commandWorked(t.insert({a: 2, b: 1})); +assert.commandWorked(t.insert({a: [2], b: 1})); +assert.commandWorked(t.insert({a: [[2]], b: 1})); + +assert.commandWorked(t.createIndex({a: 1})); + +{ + const res = t.explain("executionStats").aggregate([{$match: {a: {$eq: [2]}}}]); + assert.eq(2, res.executionStats.nReturned); + assert.eq("PhysicalScan", res.queryPlanner.winningPlan.optimizerPlan.child.child.nodeType); +} + +// Generate enough documents for index to be preferable. +for (let i = 0; i < 100; i++) { + assert.commandWorked(t.insert({a: i + 10})); +} + +{ + const res = t.explain("executionStats").aggregate([{$match: {a: {$eq: [2]}}}]); + assert.eq(2, res.executionStats.nReturned); + + const indexUnionNode = res.queryPlanner.winningPlan.optimizerPlan.child.child.leftChild.child; + assert.eq("Union", indexUnionNode.nodeType); + assert.eq("IndexScan", indexUnionNode.children[0].nodeType); + assert.eq([2], indexUnionNode.children[0].interval[0].lowBound.bound.value); + assert.eq("IndexScan", indexUnionNode.children[1].nodeType); + assert.eq(2, indexUnionNode.children[1].interval[0].lowBound.bound.value); +} + +assert.commandWorked(t.dropIndex({a: 1})); +assert.commandWorked(t.createIndex({b: 1, a: 1})); + +{ + const res = t.explain("executionStats").aggregate([{$match: {b: 1, a: {$eq: [2]}}}]); + assert.eq(2, res.executionStats.nReturned); + + // Verify we still get index scan even if the field appears as second index field. + const indexUnionNode = res.queryPlanner.winningPlan.optimizerPlan.child.child.leftChild.child; + assert.eq("Union", indexUnionNode.nodeType); + assert.eq("IndexScan", indexUnionNode.children[0].nodeType); + assert.eq([2], indexUnionNode.children[0].interval[1].lowBound.bound.value); + assert.eq("IndexScan", indexUnionNode.children[1].nodeType); + assert.eq(2, indexUnionNode.children[1].interval[1].lowBound.bound.value); +} +}()); |