[opt](function) speed up zero-scale decimal casts#65410
Conversation
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
|
/review |
There was a problem hiding this comment.
Automated review summary for PR 65410.
I did not find a blocking correctness issue in this patch, so I am leaving a comment-only review with no inline comments.
Critical checkpoint conclusions:
- Goal and coverage: the PR adds a fast path for integer/bool to DecimalV3 casts when target scale is zero and the target integral range is not narrower. Existing BE cast unit templates cover scale-zero integer-to-DecimalV3 cases, including non-narrowing combinations that now enter this branch, plus existing bool coverage.
- Scope: the change is small and localized to
be/src/exprs/function/cast/cast_to_decimal.h. - Error/null semantics: the fast path matches the old generic path for
to_scale == 0 && !narrow_integral; the old path used multiplier 1, skipped range checks, assigned the native decimal value, and returned success. Nullable wrapping stays outside this branch for the same non-narrowing condition. - Concurrency/lifecycle: no new shared state, threads, locks, static initialization, or lifecycle behavior.
- Configuration/compatibility/persistence: no new configs, no FE-BE protocol or storage-format change, and no edit-log or transaction persistence impact.
- Parallel paths: narrowing casts, non-zero-scale casts, DecimalV2, float, string, and decimal-source casts remain on the existing generic paths.
- Performance/observability: the optimization removes generic dispatch and scale work only for the proven direct-write case; no new observability appears necessary for this pure expression cast path.
Subagent conclusions:
optimizer-rewritereported no candidates in its initial pass and returnedNO_NEW_VALUABLE_FINDINGSin convergence round 1.tests-session-configreported no candidates in its initial pass and returnedNO_NEW_VALUABLE_FINDINGSin convergence round 1.- Main review dismissed the overflow/strict-mode, nullable early-return, and coverage concerns with code evidence in the shared ledger. No candidate became an inline comment.
Validation note: this checkout is not worktree-initialized and thirdparty/installed / thirdparty/installed/bin/protoc are absent, so I performed static review plus GitHub PR metadata/patch verification only; I did not run BE unit tests or a build.
User focus: no additional user-provided review focus was supplied.
|
run buildall |
TPC-H: Total hot run time: 29589 ms |
TPC-DS: Total hot run time: 180180 ms |
ClickBench: Total hot run time: 24.96 s |
BE Regression && UT Coverage ReportIncrement line coverage Increment coverage report
|
|
PR approved by at least one committer and no changes requested. |
|
PR approved by anyone and no changes requested. |
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:
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.
Release note
None
Check List (For Author)
Test
Behavior changed:
Does this need documentation?
Check List (For Reviewer who merge this PR)