diff options
author | Ribhav Jain <ribhav.jain@mongodb.com> | 2022-01-10 21:52:45 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-01-10 22:56:08 +0000 |
commit | f97ee7d37f1a0e18f248d0726823445019409b50 (patch) | |
tree | 62a042cd9ccd853791198d9ed7b92456ea12ec8f /jstests/core | |
parent | 386986a651b852c3c98b426ea60a023d99e4a5a4 (diff) | |
download | mongo-f97ee7d37f1a0e18f248d0726823445019409b50.tar.gz |
SERVER-61750: Use DISTINCT_SCAN when a regex is a prefix of an index
Diffstat (limited to 'jstests/core')
-rw-r--r-- | jstests/core/regex_distinct.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/jstests/core/regex_distinct.js b/jstests/core/regex_distinct.js new file mode 100644 index 00000000000..7852950853c --- /dev/null +++ b/jstests/core/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)); +})(); |