HappenLee opened a new pull request, #69897:
URL: https://github.com/apache/doris/pull/69897
### What problem does this PR solve?
`next_day` and `previous_day` copy and uppercase the weekday string and
search an `unordered_map` for every input row. Constant weekday arguments
repeat the same work for the entire block.
Use a C++20 compile-time perfect hash for the 21 supported weekday aliases,
with a compile-time check for unique placement. Compare case-folded words with
bounded loads and validate the complete string after hashing. Parse a constant
weekday once per block, while keeping NULL propagation ahead of invalid-weekday
errors. Accepted aliases, return types and error behavior stay the same; no new
dependency is required.
Add unit and regression coverage, registered-function benchmarks, and a
fixed-seed parser benchmark comparing `std::unordered_map`,
`phmap::flat_hash_map` and the production parser. A benchmark-only header
selector permits focused builds.
#### Performance
Measured on an x86_64 Intel Xeon Platinum 8457C with Clang 21.1.8, C++20,
RELEASE/AVX2. The initial comparison uses one BE, one bucket, one pipeline and
10 million materialized rows. Both variants use the same FE, input data and
settings, with SQL/query caches disabled. Each query has two warmups and seven
measured runs; values below are medians.
| Query | Baseline (ms) | Optimized (ms) | Speedup |
|---|---:|---:|---:|
| `next_day`, varying weekday | 528.7 | 285.1 | 1.85x |
| `previous_day`, varying weekday | 524.1 | 279.7 | 1.87x |
| `next_day`, constant weekday | 664.7 | 256.5 | 2.59x |
| `previous_day`, constant weekday | 649.6 | 254.4 | 2.55x |
| `next_day`, nullable date | 441.6 | 256.2 | 1.72x |
| `previous_day`, nullable date | 435.1 | 258.6 | 1.68x |
All six SQL result checksums match. Complete registered-function benchmarks,
including allocation and date computation, improve by 1.89–2.85x. Pure
successful weekday parsing improves from 40.51 to 2.66 ns per lookup.
A separate follow-up comparison isolates container replacement from constant
parsing hoisting: replacing only the container gives modest SQL changes
(roughly 0–9%, some within measured variation). Hoisting makes the constant
cases comparable, while the perfect-hash implementation retains a substantial
benefit for varying weekday columns by also removing copying, per-character
normalization and general-purpose string hashing. These are local synthetic
workloads; ARM performance was not measured.
### Release note
Improve `next_day` and `previous_day` throughput while preserving SQL
results and error behavior.
### Check List (For Author)
- Test
- [x] Regression test: `test_next_day`, `test_previous_day`, and
`test_relative_day_weekday_lookup`. The new output was generated with the
regression runner on the baseline and compared normally on the optimized BE.
- [x] Unit Test: six related ASan unit tests, covering aliases/case
variants, exact-length inputs, NULL/error precedence and TIMESTAMP_NS. An
additional ASan/UBSan parser harness checked 123188 inputs.
- [x] Manual test: RELEASE BE and focused benchmark builds;
registered-function and isolated-cluster SQL comparisons; clang-format 16,
clang-tidy and build hygiene.
- ASan unit tests disable `GLIBC_COMPATIBILITY` to avoid duplicate
toolchain compatibility symbols; production performance measurements keep it
enabled.
- The tests and performance measurements above were completed on the
original feature branch. This PR cherry-picks the two task commits onto master
`45d1598da2f`; both patch IDs match. Format, whitespace and build-hygiene
checks pass on this PR branch. Full builds, unit tests and SQL measurements
were not rerun after the cherry-pick.
- Behavior changed:
- [x] No.
- Does this need documentation?
- [x] No.
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label
--
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]