diff options
Diffstat (limited to 'jstests/core/query/regex/regex_distinct.js')
-rw-r--r-- | jstests/core/query/regex/regex_distinct.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/jstests/core/query/regex/regex_distinct.js b/jstests/core/query/regex/regex_distinct.js new file mode 100644 index 00000000000..7852950853c --- /dev/null +++ b/jstests/core/query/regex/regex_distinct.js @@ -0,0 +1,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)); +})(); |