summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/window_function/partition_iterator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/pipeline/window_function/partition_iterator.cpp')
-rw-r--r--src/mongo/db/pipeline/window_function/partition_iterator.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/mongo/db/pipeline/window_function/partition_iterator.cpp b/src/mongo/db/pipeline/window_function/partition_iterator.cpp
index 83925b862b3..6188845d516 100644
--- a/src/mongo/db/pipeline/window_function/partition_iterator.cpp
+++ b/src/mongo/db/pipeline/window_function/partition_iterator.cpp
@@ -205,15 +205,6 @@ optional<int> numericBound(WindowBounds::Bound<int> bound) {
bound);
}
-// Assumes both arguments are numeric, and performs Decimal128 addition on them.
-Value decimalAdd(const Value& left, const Value& right) {
- // Widening to Decimal128 is a convenient way to avoid having many cases for different numeric
- // types. The 'threshold' values we compute are only used to choose a set of documents; the
- // user can't observe the type.
- return Value(left.coerceToDecimal().add(right.coerceToDecimal()));
-}
-
-
} // namespace
optional<std::pair<int, int>> PartitionIterator::getEndpointsRangeBased(
@@ -247,7 +238,18 @@ optional<std::pair<int, int>> PartitionIterator::getEndpointsRangeBased(
dateAdd(base.coerceToDate(), *range.unit, delta.coerceToInt(), TimeZone())};
} else {
tassert(5429406, "Range-based bounds are specified as a number", delta.numeric());
- return decimalAdd(base, delta);
+ if (base.getType() == BSONType::NumberDouble) {
+ // When we compare a double and a Decimal128, we convert the Decimal128 to double
+ // and compare two double values. Since converting a double to Decimal128 is
+ // expensive and since during the comparison we will convert the Decimal128 to
+ // double, we compute the threshold as double from the beginning when the base
+ // value is already a double.
+ return Value(base.getDouble() + delta.coerceToDouble());
+ }
+ // Widening to Decimal128 is a convenient way to avoid having many cases for different
+ // numeric types. The 'threshold' values we compute are only used to choose a set of
+ // documents; the user can't observe the type.
+ return Value(base.coerceToDecimal().add(delta.coerceToDecimal()));
}
};
auto hasExpectedType = [&](const Value& v) -> bool {