HappenLee opened a new pull request, #71098:
URL: https://github.com/apache/doris/pull/71098
### Background
Doris stores `BOOLEAN` values in segment RLE pages. The encoder uses
repeated runs for identical values and 1-bit literals for values that vary
within the run. The scan materializes these values as 0/1 bytes in a
`ColumnUInt8`.
### What problem does this PR solve?
Issue Number: None
Related PR: None
PR Type: Performance
Problem Summary:
Sequential reads currently decode and append one boolean per iteration.
Repeated runs can fill a contiguous slice of the output column and literal runs
can reuse the existing bit unpacker. This change batches both operations when
scanning boolean values.
### Details
- **Why it was slow:** `RlePageDecoder::next_batch` calls `RleDecoder::Get`
and inserts into the column for every row. The existing
`RleDecoder::get_values` can fill a repeated run at once, but still reads
literal runs one bit at a time.
- **Optimization:** Resize the boolean output column once per batch and
decode directly into its appended range. For literal runs of at least 32
values, use `BitPacking::UnpackValues<uint8_t, 1>` after consuming the bits
before the next byte boundary. Advance by the exact number of bits consumed to
support batches ending inside a byte. Roll back the output size and return
corruption if the encoded page ends before the requested values.
- **Results:** Standalone decoder microbenchmark on an Intel Xeon Platinum
8457C, Clang 16 with `-O3 -march=native`, median of seven rounds of 450
traversals on one pinned core. Each traversal decodes 65,536 values in batches
of 4,096. Inputs use the Doris RLE encoder, and all variants write to the same
preallocated byte buffer. Timings are in µs per traversal and exclude SQL
execution, page I/O, and column allocation.
| Boolean distribution | Before (`Get` per row) | Batch output only |
Batch output and bit unpacking |
| --- | ---: | ---: | ---: |
| All zero | 128.15 | 1.62 | 1.59 |
| 65 scattered ones | 144.52 | 3.35 | 3.33 |
| Alternating 0 and 1 | 286.78 | 101.81 | 5.62 |
| Random, approximately 50% ones | 283.99 | 110.18 | 7.07 |
| Alternating runs of eight | 212.06 | 128.38 | 119.03 |
With a batch size of 127, random input went from 295.29 to 24.87 µs. A
dedicated AVX2 shuffle prototype took 5.64 µs for the random input in batches
of 4,096. The PR reuses the existing bit unpacker to keep a single
implementation.
- **Applicability and cost:** The optimized path is sequential
materialization of boolean values in native segment RLE pages. It writes
directly to the destination column and uses the existing on-disk encoding.
### Testing
- Added `RlePageTest.BooleanBatchReadAcrossRuns` to cover appending to a
nonempty boolean column, batch boundaries within literals, reaching the page
end, seeking, and interleaving row-ID reads with sequential reads.
- The standalone RLE decoder check passed under AddressSanitizer and
UndefinedBehaviorSanitizer for all six input distributions, batch sizes from 1
through 4,096, and mixed reads and skips.
- Clang-format 16 and the BE build hygiene checks passed. The relevant test
sources passed syntax checks with the BE unit test compile flags.
- `run-be-ut.sh` stopped before building the BE test binary because the
available local third-party bundle lacks `libpaimon_c.a`. The new GTest still
needs to run in a complete BE build.
### Release note
Speed up sequential reads of native `BOOLEAN` columns stored in RLE pages.
### Check List (For Author)
- Test: Standalone decoder correctness and performance checks passed. BE
GTest execution is pending.
- Behavior changed: No
- Does this need documentation: No
- Pre-submission status: Not ready. The standalone checks passed, and the BE
unit test run is pending.
### AI Disclosure
- Tool: OpenAI Codex
- Generated: Code, unit test, benchmark, and PR description.
- Human review: Pending.
--
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]