You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by "Mryange (via GitHub)" <gi...@apache.org> on 2026/04/09 10:11:04 UTC
[PR] [opt](function) Optimize `lpad`/`rpad` string padding performance [doris]
Mryange opened a new pull request, #62291:
URL: https://github.com/apache/doris/pull/62291
### What problem does this PR solve?
Issue Number: N/A
Problem Summary:
`lpad`/`rpad` had several avoidable overheads compared to the equivalent ClickHouse implementation:
1. An intermediate `fmt::memory_buffer` was used to accumulate results and then copied into the final `ColumnString` at the end of each block — one redundant full write.
2. UTF-8 character scanning was always performed, even for pure ASCII input.
3. No output capacity pre-reservation when the target length is constant.
4. Short pad strings were memcpy'd one repetition at a time.
### Changes
- **Remove `fmt::memory_buffer` intermediary**: both ASCII and UTF-8 paths now write directly into `res_chars` using `reserve` + `resize_assume_reserved`, eliminating the extra copy.
- **Add ASCII fast path**: if the input column and pad column are both ASCII (`ColumnString::is_ascii()`), character count equals byte count — `iterate_utf8_with_limit_length` and `get_char_len` are skipped entirely.
- **Pre-reserve output capacity**: when `len` is a constant column, `res_chars` is reserved upfront (`len * rows` for ASCII, `len * 3 * rows` for UTF-8).
- **Pre-expand short pad strings**: for `pad_const` paths, pads shorter than 512 bytes are expanded to ≥ 512 bytes once before the row loop (`build_expanded_pad`), reducing the number of `memcpy` calls per row — equivalent to ClickHouse's doubling strategy in `PaddingChars::init()`.
- **Type cleanup**: local variables for offset differences use `uint32_t`/`int32_t` matching `ColumnString::Offsets` element type and `fast_repeat`'s parameter type, removing scattered `static_cast`.
### 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 -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [opt](function) Optimize `lpad`/`rpad` string padding performance [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #62291:
URL: https://github.com/apache/doris/pull/62291#issuecomment-4213336955
Thank you for your contribution to Apache Doris.
Don't know what should be done next? See [How to process your PR](https://cwiki.apache.org/confluence/display/DORIS/How+to+process+your+PR).
Please clearly describe your PR:
1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
3. What features were added. Why was this function added?
4. Which code was refactored and why was this part of the code refactored?
5. Which functions were optimized and what is the difference before and after the optimization?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [opt](function) Optimize `lpad`/`rpad` string padding performance [doris]
Posted by "Mryange (via GitHub)" <gi...@apache.org>.
Mryange closed pull request #62291: [opt](function) Optimize `lpad`/`rpad` string padding performance
URL: https://github.com/apache/doris/pull/62291
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org