summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew Paroski <drew.paroski@mongodb.com>2021-10-04 20:26:05 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-10-05 20:55:24 +0000
commit547e8e91188f686f6074b83e6a7732a25ea7f9bc (patch)
tree028b30b4ece222fa214909fd06c13d12afc29480
parent03e2efc547344112c1129ee4eb34908e8b67569f (diff)
downloadmongo-547e8e91188f686f6074b83e6a7732a25ea7f9bc.tar.gz
SERVER-60453 Fix sbe::vm::genericCompare() to be consistent about how it handles NaN
-rw-r--r--src/mongo/db/exec/sbe/vm/vm.h18
-rw-r--r--src/mongo/db/query/sbe_stage_builder_filter.cpp11
2 files changed, 13 insertions, 16 deletions
diff --git a/src/mongo/db/exec/sbe/vm/vm.h b/src/mongo/db/exec/sbe/vm/vm.h
index 73bad25f65f..60f41c298e1 100644
--- a/src/mongo/db/exec/sbe/vm/vm.h
+++ b/src/mongo/db/exec/sbe/vm/vm.h
@@ -73,15 +73,19 @@ std::pair<value::TypeTags, value::Value> genericCompare(
case value::TypeTags::NumberDecimal: {
auto result = [&]() {
if (lhsTag == value::TypeTags::NumberDouble) {
- return op(compareDoubleToDecimal(
- value::numericCast<double>(lhsTag, lhsValue),
- value::numericCast<Decimal128>(rhsTag, rhsValue)),
+ if (value::isNaN(lhsTag, lhsValue) || value::isNaN(rhsTag, rhsValue)) {
+ return false;
+ }
+ return op(compareDoubleToDecimal(value::bitcastTo<double>(lhsValue),
+ value::bitcastTo<Decimal128>(rhsValue)),
0);
} else if (rhsTag == value::TypeTags::NumberDouble) {
- return op(
- compareDecimalToDouble(value::numericCast<Decimal128>(lhsTag, lhsValue),
- value::numericCast<double>(rhsTag, rhsValue)),
- 0);
+ if (value::isNaN(lhsTag, lhsValue) || value::isNaN(rhsTag, rhsValue)) {
+ return false;
+ }
+ return op(compareDecimalToDouble(value::bitcastTo<Decimal128>(lhsValue),
+ value::bitcastTo<double>(rhsValue)),
+ 0);
} else {
return op(value::numericCast<Decimal128>(lhsTag, lhsValue),
value::numericCast<Decimal128>(rhsTag, rhsValue));
diff --git a/src/mongo/db/query/sbe_stage_builder_filter.cpp b/src/mongo/db/query/sbe_stage_builder_filter.cpp
index e489dbabcd0..8e3c768e3d2 100644
--- a/src/mongo/db/query/sbe_stage_builder_filter.cpp
+++ b/src/mongo/db/query/sbe_stage_builder_filter.cpp
@@ -792,15 +792,8 @@ void generateComparison(MatchExpressionVisitorContext* context,
// SBE EConstant assumes ownership of the value so we have to make a copy here.
auto [tag, val] = sbe::value::copyValue(tagView, valView);
- // When 'rhs' is not NaN, return false if lhs is NaN. Otherwise, use usual comparison
- // semantics.
- return {makeBinaryOp(
- sbe::EPrimBinary::logicAnd,
- makeNot(makeFillEmptyFalse(makeFunction("isNaN", makeVariable(inputSlot)))),
- makeFillEmptyFalse(makeBinaryOp(binaryOp,
- makeVariable(inputSlot),
- makeConstant(tag, val),
- context->state.env))),
+ return {makeFillEmptyFalse(makeBinaryOp(
+ binaryOp, makeVariable(inputSlot), makeConstant(tag, val), context->state.env)),
std::move(inputStage)};
};