This is an automated email from the ASF dual-hosted git repository.

hello-stephen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 5d56602a645 [opt](function) speed up zero-scale decimal casts (#65410)
5d56602a645 is described below

commit 5d56602a645db2cd02b5f5947c2e11431da7fd70
Author: Mryange <[email protected]>
AuthorDate: Mon Jul 13 11:34:33 2026 +0800

    [opt](function) speed up zero-scale decimal casts (#65410)
    
    ### What problem does this PR solve?
    
    Integer-to-DecimalV3 casts with zero scale previously went through the
    generic decimal cast path even when the target decimal precision can
    represent the full integer input range. For example, casting an INT
    column to DECIMALV3(10, 0) still used the common _from_int helper, which
    computes decimal scaling and range-related values that are unnecessary
    when the scale is zero and the cast cannot narrow the integer range.
    
    Root cause: the DecimalV3 cast implementation did not have a direct fast
    path for non-narrowing integer casts to zero-scale decimal types.
    
    This change adds a direct zero-scale DecimalV3 path for integer and
    boolean inputs when the target decimal range is not narrower than the
    input range. The fast path writes the input value directly into the
    decimal native value and preserves the existing generic path for
    narrowing casts, non-zero-scale casts, and overflow-sensitive cases.
    
    Local optest profiling for:
    
    select sum(cast(quantity as decimalv3(10,0))) from q14_avg_expr_100m;
    
    showed the cast expression time improving from about 119.0 ms to about
    109.7 ms on 100M rows, roughly an 8% reduction in this expression
    counter.
---
 be/src/exprs/function/cast/cast_to_decimal.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/be/src/exprs/function/cast/cast_to_decimal.h 
b/be/src/exprs/function/cast/cast_to_decimal.h
index 0617aca16ea..8dc4c6b4aea 100644
--- a/be/src/exprs/function/cast/cast_to_decimal.h
+++ b/be/src/exprs/function/cast/cast_to_decimal.h
@@ -780,6 +780,17 @@ public:
         params.is_strict = (CastMode == CastModeType::StrictMode);
         size_t size = vec_from.size();
 
+        if constexpr (IsDataTypeDecimalV3<ToDataType>) {
+            if (to_scale == 0 && !narrow_integral) {
+                for (size_t i = 0; i < size; i++) {
+                    vec_to_data[i].value =
+                            static_cast<typename 
ToFieldType::NativeType>(vec_from_data[i]);
+                }
+                block.get_by_position(result).column = std::move(col_to);
+                return Status::OK();
+            }
+        }
+
         RETURN_IF_ERROR(std::visit(
                 [&](auto multiply_may_overflow, auto narrow_integral) {
                     for (size_t i = 0; i < size; i++) {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to