summaryrefslogtreecommitdiff
path: root/jstests/cqf/residual_pred_costing.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/cqf/residual_pred_costing.js')
-rw-r--r--jstests/cqf/residual_pred_costing.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/jstests/cqf/residual_pred_costing.js b/jstests/cqf/residual_pred_costing.js
new file mode 100644
index 00000000000..07bc7211836
--- /dev/null
+++ b/jstests/cqf/residual_pred_costing.js
@@ -0,0 +1,35 @@
+/**
+ * Tests scenario related to SERVER-21697.
+ */
+(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_residual_pred_costing;
+t.drop();
+
+const bulk = t.initializeUnorderedBulkOp();
+const nDocs = 2000;
+for (let i = 0; i < nDocs; i++) {
+ bulk.insert({a: i % 10, b: i % 10, c: i % 10, d: i % 10});
+}
+assert.commandWorked(bulk.execute());
+
+assert.commandWorked(t.createIndex({a: 1, b: 1, c: 1, d: 1}));
+assert.commandWorked(t.createIndex({a: 1, b: 1, d: 1}));
+assert.commandWorked(t.createIndex({a: 1, d: 1}));
+
+let res = t.explain("executionStats")
+ .aggregate([{$match: {a: {$eq: 0}, b: {$eq: 0}, c: {$eq: 0}}}, {$sort: {d: 1}}]);
+assert.eq(nDocs * 0.1, res.executionStats.nReturned);
+
+// Demonstrate we can pick the indexing covering most fields.
+const indexNode = res.queryPlanner.winningPlan.optimizerPlan.child.leftChild;
+assert.eq("IndexScan", indexNode.nodeType);
+assert.eq("a_1_b_1_c_1_d_1", indexNode.indexDefName);
+}());