[opt](function) Optimize lpad/rpad string padding performance#62291
Closed
Mryange wants to merge 1 commit intoapache:masterfrom
Closed
[opt](function) Optimize lpad/rpad string padding performance#62291Mryange wants to merge 1 commit intoapache:masterfrom
lpad/rpad string padding performance#62291Mryange wants to merge 1 commit intoapache:masterfrom
Conversation
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem does this PR solve?
Problem Summary:
lpad/rpadhad several avoidable overheads compared to the equivalent ClickHouse implementation:fmt::memory_bufferwas used to accumulate results and then copied into the finalColumnStringat the end of each block — one redundant full write.Changes
fmt::memory_bufferintermediary: both ASCII and UTF-8 paths now write directly intores_charsusingreserve+resize_assume_reserved, eliminating the extra copy.ColumnString::is_ascii()), character count equals byte count —iterate_utf8_with_limit_lengthandget_char_lenare skipped entirely.lenis a constant column,res_charsis reserved upfront (len * rowsfor ASCII,len * 3 * rowsfor UTF-8).pad_constpaths, pads shorter than 512 bytes are expanded to ≥ 512 bytes once before the row loop (build_expanded_pad), reducing the number ofmemcpycalls per row — equivalent to ClickHouse's doubling strategy inPaddingChars::init().uint32_t/int32_tmatchingColumnString::Offsetselement type andfast_repeat's parameter type, removing scatteredstatic_cast.Release note
None
Check List (For Author)
Test
Behavior changed:
Does this need documentation?
Check List (For Reviewer who merge this PR)