1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
/**
* Verify the usage of DISTINCT_SCAN when a regex ending with .* is a prefix of an index.
*
* @tags: [
* requires_fcv_53,
* assumes_read_concern_local,
* ]
*/
(function() {
"use strict";
load("jstests/libs/analyze_plan.js"); // For getPlanStages.
load("jstests/libs/fixture_helpers.js"); // For numberOfShardsForCollection.
const coll = db.regex_distinct;
coll.drop();
assert.commandWorked(coll.insertMany(
[{a: "abc", b: "foo"}, {a: "abc", b: "bar"}, {a: "abd", b: "far"}, {a: "aeb", b: "car"}]));
assert.commandWorked(coll.createIndex({a: 1}));
assert.eq(2, coll.distinct("a", {a: {"$regex": "^ab.*"}}).length);
const distinctScanStages =
getPlanStages(coll.explain().distinct("a", {a: {"$regex": "^ab.*"}}), "DISTINCT_SCAN");
assert.eq(distinctScanStages.length, FixtureHelpers.numberOfShardsForCollection(coll));
})();
|