summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/plan_cache.cpp
diff options
context:
space:
mode:
authorIan Boros <ian.boros@10gen.com>2018-05-08 17:31:47 -0400
committerIan Boros <ian.boros@10gen.com>2018-05-10 15:35:39 -0400
commitb09ce3bdc6ae82e99576a2530b25a77fe3c72ee1 (patch)
treedf5f1e82bff99c0b5bb4e0f048ca91aa462ff0bf /src/mongo/db/query/plan_cache.cpp
parentec4a3883899f3ea9f4600b786596f0b17fd00106 (diff)
downloadmongo-b09ce3bdc6ae82e99576a2530b25a77fe3c72ee1.tar.gz
SERVER-33678 make regex options a factor in query shapes
Diffstat (limited to 'src/mongo/db/query/plan_cache.cpp')
-rw-r--r--src/mongo/db/query/plan_cache.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/mongo/db/query/plan_cache.cpp b/src/mongo/db/query/plan_cache.cpp
index e530f18af59..0a609fb43c3 100644
--- a/src/mongo/db/query/plan_cache.cpp
+++ b/src/mongo/db/query/plan_cache.cpp
@@ -578,6 +578,17 @@ void PlanCache::encodeKeyForMatch(const MatchExpression* tree, StringBuilder* ke
encodeGeoNearMatchExpression(static_cast<const GeoNearMatchExpression*>(tree), keyBuilder);
}
+ // REGEX requires that we encode the flags so that regexes with different options appear
+ // as different query shapes.
+ if (MatchExpression::REGEX == tree->matchType()) {
+ const auto reMatchExpression = static_cast<const RegexMatchExpression*>(tree);
+ std::string flags = reMatchExpression->getFlags();
+ // Sort the flags, so that queries with the same regex flags in different orders will have
+ // the same shape.
+ std::sort(flags.begin(), flags.end());
+ encodeUserString(flags, keyBuilder);
+ }
+
// Encode indexability.
const IndexToDiscriminatorMap& discriminators =
_indexabilityState.getDiscriminators(tree->path());