summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMisha Ivkov <misha.ivkov@10gen.com>2019-06-04 16:30:32 -0400
committerMisha Ivkov <misha.ivkov@10gen.com>2019-06-07 15:30:36 -0400
commite67db1f1c523309be615ebf1ec7f12b944b21bd9 (patch)
treefc4dfd0e3ce5a72ec4d05ffd02239253ffea6430
parent6868af843a94de7b8e405b36f7f0a2ce1e160cbd (diff)
downloadmongo-e67db1f1c523309be615ebf1ec7f12b944b21bd9.tar.gz
SERVER-40546 max/min boundary checking on both
-rw-r--r--jstests/core/collation.js14
-rw-r--r--src/mongo/db/query/query_planner.cpp6
2 files changed, 18 insertions, 2 deletions
diff --git a/jstests/core/collation.js b/jstests/core/collation.js
index af87212346c..6b13cceadfd 100644
--- a/jstests/core/collation.js
+++ b/jstests/core/collation.js
@@ -1975,6 +1975,20 @@
.itcount());
assert.commandFailedWithCode(err, 51174);
+ // This query should fail, because the hinted index does not match the requested
+ // collation, and the 'max' value is a string, which means we cannot ignore the
+ // collation.
+ const caseInsensitive = {locale: "en", strength: 2};
+ assert.commandWorked(coll.dropIndexes());
+ assert.commandWorked(coll.createIndex({str: 1}));
+ err = assert.throws(() => coll.find({}, {_id: 0})
+ .min({str: MinKey})
+ .max({str: "Hello1"})
+ .hint({str: 1})
+ .collation(caseInsensitive)
+ .toArray());
+ assert.commandFailedWithCode(err, 51174);
+
// After building an index with the case-insensitive US English collation, the query should
// work. Furthermore, the bounds defined by the min and max should respect the
// case-insensitive collation.
diff --git a/src/mongo/db/query/query_planner.cpp b/src/mongo/db/query/query_planner.cpp
index 655a6816194..9e8349b18d5 100644
--- a/src/mongo/db/query/query_planner.cpp
+++ b/src/mongo/db/query/query_planner.cpp
@@ -657,8 +657,10 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan(
BSONObj minObj = query.getQueryRequest().getMin();
BSONObj maxObj = query.getQueryRequest().getMax();
- if (!indexCompatibleMaxMin(
- minObj.isEmpty() ? maxObj : minObj, query.getCollator(), *hintedIndexEntry)) {
+ if ((!minObj.isEmpty() &&
+ !indexCompatibleMaxMin(minObj, query.getCollator(), *hintedIndexEntry)) ||
+ (!maxObj.isEmpty() &&
+ !indexCompatibleMaxMin(maxObj, query.getCollator(), *hintedIndexEntry))) {
return Status(ErrorCodes::Error(51174),
"The index chosen is not compatible with min/max");
}