summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNikita Lapkov <nikita.lapkov@mongodb.com>2021-02-17 15:25:50 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-02-22 12:19:56 +0000
commit6aa6f8b5edeec42d8a571965d525252b99aa626d (patch)
tree056d13710593e3040ff7cd1f45334e1e66825667 /src
parente7d1cce728991a6e930c86d7a1e7145507a34517 (diff)
downloadmongo-6aa6f8b5edeec42d8a571965d525252b99aa626d.tar.gz
SERVER-54490 Fix incorrect sort order for NaN and missing values in SBE
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/exec/sbe/values/value.cpp9
-rw-r--r--src/mongo/db/query/sbe_stage_builder.cpp5
2 files changed, 10 insertions, 4 deletions
diff --git a/src/mongo/db/exec/sbe/values/value.cpp b/src/mongo/db/exec/sbe/values/value.cpp
index 3f8e9c7834d..f2dc9c1723a 100644
--- a/src/mongo/db/exec/sbe/values/value.cpp
+++ b/src/mongo/db/exec/sbe/values/value.cpp
@@ -31,6 +31,7 @@
#include "mongo/db/exec/sbe/values/value.h"
+#include "mongo/base/compare_numbers.h"
#include "mongo/db/exec/js_function.h"
#include "mongo/db/exec/sbe/values/bson.h"
#include "mongo/db/exec/sbe/values/value_builder.h"
@@ -690,13 +691,13 @@ std::pair<TypeTags, Value> compareValue(TypeTags lhsTag,
return {TypeTags::NumberInt32, bitcastFrom<int32_t>(result)};
}
case TypeTags::NumberDouble: {
- auto result = compareHelper(numericCast<double>(lhsTag, lhsValue),
- numericCast<double>(rhsTag, rhsValue));
+ auto result = compareDoubles(numericCast<double>(lhsTag, lhsValue),
+ numericCast<double>(rhsTag, rhsValue));
return {TypeTags::NumberInt32, bitcastFrom<int32_t>(result)};
}
case TypeTags::NumberDecimal: {
- auto result = compareHelper(numericCast<Decimal128>(lhsTag, lhsValue),
- numericCast<Decimal128>(rhsTag, rhsValue));
+ auto result = compareDecimals(numericCast<Decimal128>(lhsTag, lhsValue),
+ numericCast<Decimal128>(rhsTag, rhsValue));
return {TypeTags::NumberInt32, bitcastFrom<int32_t>(result)};
}
default:
diff --git a/src/mongo/db/query/sbe_stage_builder.cpp b/src/mongo/db/query/sbe_stage_builder.cpp
index 3a0d9821add..14c9870fb94 100644
--- a/src/mongo/db/query/sbe_stage_builder.cpp
+++ b/src/mongo/db/query/sbe_stage_builder.cpp
@@ -501,6 +501,11 @@ std::pair<std::unique_ptr<sbe::PlanStage>, PlanStageSlots> SlotBasedStageBuilder
sbe::makeE<sbe::EVariable>(*collatorSlot));
}
+ // According to MQL semantics, missing values are treated as nulls during sorting.
+ getSortFieldExpr = makeFunction("fillEmpty"sv,
+ std::move(getSortFieldExpr),
+ makeConstant(sbe::value::TypeTags::Null, 0));
+
projectMap.emplace(sortFieldVar, std::move(getSortFieldExpr));
}