summaryrefslogtreecommitdiff
path: root/jstests/core/views
diff options
context:
space:
mode:
authorAnton Korshunov <anton.korshunov@mongodb.com>2019-02-27 16:22:31 +0000
committerAnton Korshunov <anton.korshunov@mongodb.com>2019-04-03 12:19:22 +0100
commitd47bbc343af0b5bbde7b810f63e6b3404ea9e4d6 (patch)
treee2778eef1df27012e2540d3333ec95184d359fff /jstests/core/views
parent6c2bd4b1be257ba7b9335e40c2af18ff25b7fcdd (diff)
downloadmongo-d47bbc343af0b5bbde7b810f63e6b3404ea9e4d6.tar.gz
SERVER-24860 Optimize away entire pipeline if it can be answered using a query
Diffstat (limited to 'jstests/core/views')
-rw-r--r--jstests/core/views/views_collation.js14
-rw-r--r--jstests/core/views/views_find.js20
2 files changed, 18 insertions, 16 deletions
diff --git a/jstests/core/views/views_collation.js b/jstests/core/views/views_collation.js
index 428927751c8..32b103ae2fb 100644
--- a/jstests/core/views/views_collation.js
+++ b/jstests/core/views/views_collation.js
@@ -494,12 +494,13 @@
let explain, cursorStage;
// Test that aggregate against a view with a default collation correctly uses the collation.
+ // We expect the pipeline to be optimized away, so there should be no pipeline stages in
+ // the explain.
assert.eq(1, viewsDB.case_sensitive_coll.aggregate([{$match: {f: "case"}}]).itcount());
assert.eq(3, viewsDB.case_insensitive_view.aggregate([{$match: {f: "case"}}]).itcount());
explain = viewsDB.case_insensitive_view.explain().aggregate([{$match: {f: "case"}}]);
- cursorStage = getAggPlanStage(explain, "$cursor");
- assert.neq(null, cursorStage, tojson(explain));
- assert.eq(1, cursorStage.$cursor.queryPlanner.collation.strength, tojson(cursorStage));
+ assert.neq(null, explain.queryPlanner, tojson(explain));
+ assert.eq(1, explain.queryPlanner.collation.strength, tojson(explain));
// Test that count against a view with a default collation correctly uses the collation.
assert.eq(1, viewsDB.case_sensitive_coll.count({f: "case"}));
@@ -518,6 +519,8 @@
assert.eq(1, cursorStage.$cursor.queryPlanner.collation.strength, tojson(cursorStage));
// Test that find against a view with a default collation correctly uses the collation.
+ // We expect the pipeline to be optimized away, so there should be no pipeline stages in
+ // the explain output.
let findRes = viewsDB.runCommand({find: "case_sensitive_coll", filter: {f: "case"}});
assert.commandWorked(findRes);
assert.eq(1, findRes.cursor.firstBatch.length);
@@ -525,7 +528,6 @@
assert.commandWorked(findRes);
assert.eq(3, findRes.cursor.firstBatch.length);
explain = viewsDB.runCommand({explain: {find: "case_insensitive_view", filter: {f: "case"}}});
- cursorStage = getAggPlanStage(explain, "$cursor");
- assert.neq(null, cursorStage, tojson(explain));
- assert.eq(1, cursorStage.$cursor.queryPlanner.collation.strength, tojson(cursorStage));
+ assert.neq(null, explain.queryPlanner, tojson(explain));
+ assert.eq(1, explain.queryPlanner.collation.strength, tojson(explain));
}());
diff --git a/jstests/core/views/views_find.js b/jstests/core/views/views_find.js
index df263e3f441..a4d24d1b9b3 100644
--- a/jstests/core/views/views_find.js
+++ b/jstests/core/views/views_find.js
@@ -78,20 +78,20 @@
// Find with explicit explain modes works on a view.
let explainPlan = assert.commandWorked(viewsDB.identityView.find().explain("queryPlanner"));
- assert.eq(explainPlan.stages[0].$cursor.queryPlanner.namespace, "views_find.coll");
- assert(!explainPlan.stages[0].$cursor.hasOwnProperty("executionStats"));
+ assert.eq(explainPlan.queryPlanner.namespace, "views_find.coll");
+ assert(!explainPlan.hasOwnProperty("executionStats"));
explainPlan = assert.commandWorked(viewsDB.identityView.find().explain("executionStats"));
- assert.eq(explainPlan.stages[0].$cursor.queryPlanner.namespace, "views_find.coll");
- assert(explainPlan.stages[0].$cursor.hasOwnProperty("executionStats"));
- assert.eq(explainPlan.stages[0].$cursor.executionStats.nReturned, 5);
- assert(!explainPlan.stages[0].$cursor.executionStats.hasOwnProperty("allPlansExecution"));
+ assert.eq(explainPlan.queryPlanner.namespace, "views_find.coll");
+ assert(explainPlan.hasOwnProperty("executionStats"));
+ assert.eq(explainPlan.executionStats.nReturned, 5);
+ assert(!explainPlan.executionStats.hasOwnProperty("allPlansExecution"));
explainPlan = assert.commandWorked(viewsDB.identityView.find().explain("allPlansExecution"));
- assert.eq(explainPlan.stages[0].$cursor.queryPlanner.namespace, "views_find.coll");
- assert(explainPlan.stages[0].$cursor.hasOwnProperty("executionStats"));
- assert.eq(explainPlan.stages[0].$cursor.executionStats.nReturned, 5);
- assert(explainPlan.stages[0].$cursor.executionStats.hasOwnProperty("allPlansExecution"));
+ assert.eq(explainPlan.queryPlanner.namespace, "views_find.coll");
+ assert(explainPlan.hasOwnProperty("executionStats"));
+ assert.eq(explainPlan.executionStats.nReturned, 5);
+ assert(explainPlan.executionStats.hasOwnProperty("allPlansExecution"));
// Only simple 0 or 1 projections are allowed on views.
assert.writeOK(viewsDB.coll.insert({arr: [{x: 1}]}));