yraivo opened a new pull request, #71050:
URL: https://github.com/apache/doris/pull/71050
### What problem does this PR solve?
Issue Number: close #66365
Related PR: #63436 (deduplicates per-segment row IDs in `rowid_fetcher`, but
leaves the storage-layer bugs intact)
PR Type: Bugfix
Problem Summary:
Reading RLE-encoded columns via `read_by_rowids` (e.g., TopN lazy
materialization on `BOOLEAN` columns) can hang BE scan threads at 100% CPU or
return misaligned rows on subsequent same-page seeks. Most of the diff is
regression unit tests; the production changes are across three files:
1. **`be/src/util/rle_encoding.h`**: `RleDecoder::Skip` previously called
`ReadHeader()` and `GetValue()` but only checked their return values with
`DCHECK`. In Release (`-DNDEBUG`) builds, EOF left both run counters at `0` and
spun forever, zero-length headers (`0x00`/`0x01`) were accepted, and truncated
literal reads were ignored. Kept the 1-arg `size_t Skip(size_t)` contract
unchanged (`0` remains valid for all-zero runs), added `bool Skip(size_t,
size_t*)` to surface premature EOF, and guarded zero-length/truncated runs in
`ReadHeader`, `Get`, `GetNextRun`, and `get_values` (with a division-free
`uint64_t` capacity check before the literal loop).
2. **`be/src/storage/segment/rle_page.h`**: `RlePageDecoder::read_by_rowids`
previously underflowed `ord - _cur_index` on backward seeks and returned `*n =
0` with `Status::OK()` at the page tail (`_cur_index == _num_elements`),
spinning the outer loop even in Debug/ASAN builds. Now checks bounds first,
rewinds when `ord < _cur_index`, allows re-reading the page tail, and returns
`Status::Corruption` when `Skip` or `Get` fails.
3. **`be/src/storage/segment/column_reader.cpp`**:
`FileColumnIterator::read_by_rowids` did not update `_page.offset_in_page` on
non-null pages, so a later seek back to the old offset skipped resetting
`RlePageDecoder`. Now syncs `_page.offset_in_page` from
`data_decoder->current_index()` (leaving `PlainPageDecoder` and
`BitShufflePageDecoder` unchanged), rejects out-of-range row IDs and seek
offsets before seeking, and returns `Status::Corruption` if `null_decoder` hits
EOF across both normal and `NULL_MAP_ONLY` `read_by_rowids` / `next_batch`
paths.
### Testing
- SQL repro on official `4.1.3` and `4.1.5` containers: confirmed the
`VMaterializeNode` query timeout and stuck `rs_normal` thread.
- BE unit tests on `master` (verified locally in both `RELEASE` `-O3
-DNDEBUG` and `ASAN` builds):
```bash
doris_be_test
--gtest_filter='TestRle.*:RlePageTest.*:ColumnReaderTest.*-TestRle.Benchmark*'
```
- Before the fix: 6 new regression tests fail or time out in each build.
- After the fix: `109/109` passed in both `RELEASE` and `ASAN`, covering
1-arg/2-arg `Skip` (including non-byte-aligned 1-bit literal truncation),
duplicate/backward and page-tail `read_by_rowids`, same-page re-seek +
`next_batch` across `RLE` / `PLAIN_ENCODING` / `BIT_SHUFFLE`, out-of-range row
IDs, truncated RLE pages in `RlePageDecoder`, and truncated null bitmaps in
normal / `NULL_MAP_ONLY` iterators.
### Release note
Fix a BE CPU hang and page cursor desync when reading RLE-encoded columns by
row ID.
### Check List (For Author)
- Behavior changed: Yes — valid duplicate/backward/page-tail RLE reads now
return correct values instead of hanging or misaligning; truncated RLE streams
and out-of-range row IDs now return `Status::Corruption`.
- Does this need documentation: No
- Pre-submission status: Ready
### AI Disclosure
- Tool: Antigravity and Codex
- Generated: Assisted with root-cause tracing, initial patch/test drafts,
and review checks
- Human review: I manually reviewed all diffs and verified the test results
locally
--
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]