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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]