summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorHenri Nikku <henri.nikku@mongodb.com>2022-08-12 14:51:30 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-08-12 16:11:10 +0000
commitb1d634bafebc84fbe820f5f6086bbd2813f546ec (patch)
treebc269f658f0c22c520cb5206dc40c563a7298e0e /src/mongo/db
parent77f370cef50d391e9dca103aadea15b8bccd300e (diff)
downloadmongo-b1d634bafebc84fbe820f5f6086bbd2813f546ec.tar.gz
SERVER-68241 index_tag invalid comparator
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/query/index_tag.cpp27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/mongo/db/query/index_tag.cpp b/src/mongo/db/query/index_tag.cpp
index 279788d1bef..2bfdd01d60f 100644
--- a/src/mongo/db/query/index_tag.cpp
+++ b/src/mongo/db/query/index_tag.cpp
@@ -60,18 +60,23 @@ int tagComparison(const MatchExpression* lhs, const MatchExpression* rhs) {
return lhsValue < rhsValue ? -1 : 1;
}
- // Next, order so that if there's a GEO_NEAR it's first.
- if (MatchExpression::GEO_NEAR == lhs->matchType()) {
- return -1;
- } else if (MatchExpression::GEO_NEAR == rhs->matchType()) {
- return 1;
- }
+ // Next, order geo and text predicates which MUST use an index before all others. We're not sure
+ // if this is strictly necessary for correctness, but putting these all together and first may
+ // help determine earlier if there is an index that must be used.
+ if (lhs->matchType() != rhs->matchType()) {
+ // Next, order so that if there's a GEO_NEAR it's first.
+ if (MatchExpression::GEO_NEAR == lhs->matchType()) {
+ return -1;
+ } else if (MatchExpression::GEO_NEAR == rhs->matchType()) {
+ return 1;
+ }
- // Ditto text.
- if (MatchExpression::TEXT == lhs->matchType()) {
- return -1;
- } else if (MatchExpression::TEXT == rhs->matchType()) {
- return 1;
+ // Ditto text.
+ if (MatchExpression::TEXT == lhs->matchType()) {
+ return -1;
+ } else if (MatchExpression::TEXT == rhs->matchType()) {
+ return 1;
+ }
}
// Next, order so that the first field of a compound index appears first.