summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/planner_ixselect.cpp
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2018-09-26 13:51:06 -0400
committerDavid Storch <david.storch@10gen.com>2018-10-03 16:03:23 -0400
commit5b30d4be9e43ef9d12b409a7249649806374b2e9 (patch)
tree261957b15ab68c16b0d173a01902caaf0c524a0b /src/mongo/db/query/planner_ixselect.cpp
parent231ec00544f7415bfcdcc51fabc55df6c7e6cb31 (diff)
downloadmongo-5b30d4be9e43ef9d12b409a7249649806374b2e9.tar.gz
SERVER-36896 Allow wildcard indices to support equality to empty object predicates.
Diffstat (limited to 'src/mongo/db/query/planner_ixselect.cpp')
-rw-r--r--src/mongo/db/query/planner_ixselect.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/mongo/db/query/planner_ixselect.cpp b/src/mongo/db/query/planner_ixselect.cpp
index 8a7f005d9c1..08a78e95491 100644
--- a/src/mongo/db/query/planner_ixselect.cpp
+++ b/src/mongo/db/query/planner_ixselect.cpp
@@ -130,7 +130,14 @@ void expandIndex(const IndexEntry& wildcardIndex,
bool canUseWildcardIndex(BSONElement elt, MatchExpression::MatchType matchType) {
if (elt.type() == BSONType::Object) {
- return false;
+ // $** indices break nested objects into separate keys, which means we can't naturally
+ // support comparison-to-object predicates. However, there is an exception: empty objects
+ // are indexed like regular leaf values. This means that equality-to-empty-object can be
+ // supported.
+ //
+ // Due to type bracketing, $lte:{} and $eq:{} are semantically equivalent.
+ return elt.embeddedObject().isEmpty() &&
+ (matchType == MatchExpression::EQ || matchType == MatchExpression::LTE);
}
if (elt.type() == BSONType::Array) {