diff options
-rw-r--r-- | src/mongo/db/exec/sbe/vm/vm.h | 18 | ||||
-rw-r--r-- | src/mongo/db/query/sbe_stage_builder_filter.cpp | 11 |
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)}; }; |