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

Mryange pushed a commit to branch opt_perf_4.1
in repository https://gitbox.apache.org/repos/asf/doris.git


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

commit da3705cb3746464a41bebbc65512e40daf91f809
Author: Mryange <[email protected]>
AuthorDate: Tue Jul 14 14:46:16 2026 +0800

    [opt](function) speed up zero-scale decimal casts (#65410) (#65576)
    
    ### 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.
    
    ### What problem does this PR solve?
    
    Issue Number: close #xxx
    
    Related PR: #xxx
    
    Problem Summary:
    
    ### Release note
    
    None
    
    ### Check List (For Author)
    
    - Test <!-- At least one of them must be included. -->
        - [ ] Regression test
        - [ ] Unit Test
        - [ ] Manual test (add detailed scripts or steps below)
        - [ ] No need to test or manual test. Explain why:
    - [ ] This is a refactor/code format and no logic has been changed.
            - [ ] Previous test can cover this change.
            - [ ] No code files have been changed.
            - [ ] Other reason <!-- Add your reason?  -->
    
    - Behavior changed:
        - [ ] No.
        - [ ] Yes. <!-- Explain the behavior change -->
    
    - Does this need documentation?
        - [ ] No.
    - [ ] Yes. <!-- Add document PR link here. eg:
    https://github.com/apache/doris-website/pull/1214 -->
    
    ### Check List (For Reviewer who merge this PR)
    
    - [ ] Confirm the release note
    - [ ] Confirm test cases
    - [ ] Confirm document
    - [ ] Add branch pick label <!-- Add branch pick label that this PR
    should merge into -->
---
 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 17e9af68723..7a65d07a5db 100644
--- a/be/src/exprs/function/cast/cast_to_decimal.h
+++ b/be/src/exprs/function/cast/cast_to_decimal.h
@@ -781,6 +781,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