Baymine opened a new pull request, #71258:
URL: https://github.com/apache/doris/pull/71258
### Background
Native segment pages store NULL flags in an RLE bitmap and keep non-NULL
values in a separate sequence. Reading a set of row IDs requires the reader to
keep the bitmap position and the physical value decoder in sync.
### What problem does this PR solve?
Issue Number: None
Related PR: #67800 (earlier implementation), #71050 (RLE read error handling)
PR Type: Performance
Problem Summary:
When a filter or TopN selects sparsely spaced rows, the segment reader
traverses NULL runs between requested row IDs and repeatedly seeks the value
decoder. In a unit test with seven requested rows in one page, the baseline
asks the data decoder to seek 100 times. Skipping those intervals reduces the
number to 10.
### Details
- **Why it was slow:** The reader used `GetNextRun` through unrequested
regions. Alternating NULL flags turn those regions into one-row runs. Seeking
directly with the former `Skip` also counted one-bit literals one at a time.
- **Optimization:** Reuse the page seek helper for a forward gap and move
the value decoder by the gap length minus the skipped NULL count. Count up to
64 one-bit literals per read with popcount, and return corruption if an
incomplete bitmap prevents the skip. A request beyond the current page
continues through the outer page-seek loop.
- **Results:** RELEASE builds on a single Intel Xeon Platinum 8338C host.
For the native SQL measurements, a two-million-row duplicate-key table had four
nullable INT payload columns and one bucket. The two BE revisions alternated on
the same FE and dataset, with 30 warm samples per version and query. Result
digests matched across versions.
| SQL measurement | master P50 / P95 | This PR P50 / P95 |
| --- | ---: | ---: |
| Sparse filter, BE `LazyReadTime` | 76.65 / 134.46 ms | 7.37 / 11.17 ms |
| Sparse filter, server query time | 93 / 163 ms | 22.5 / 28 ms |
| TopN LIMIT 4096, second-phase `MaxRpcTime` | 68.78 / 86.97 ms | 7.53 /
19.37 ms |
| TopN LIMIT 4096, server query time | 103 / 132 ms | 34 / 62 ms |
| Clustered filter, BE `LazyReadTime` | 172.11 / 264.73 ms | 89.61 /
169.29 ms |
| Dense range, server query time | 15.5 / 31 ms | 13 / 16 ms |
Standalone `benchmark_test` called the native column reader for 64 row IDs
on a single 16,384-row PLAIN/LZ4F page with warm data. Each variant ran on one
pinned CPU, with 18 Google Benchmark repetitions per scenario. The table
reports median thread CPU time per batch.
| NULL distribution and row IDs | master | 64-bit Skip only | This PR |
| --- | ---: | ---: | ---: |
| Alternating NULLs, stride 257 | 231.40 µs | 231.25 µs | 4.29 µs |
| 32-row NULL/non-NULL runs, stride 257 | 21.01 µs | 21.76 µs | 11.07 µs |
| About 10% NULLs, stride 257 | 53.60 µs | 55.56 µs | 21.08 µs |
| Alternating NULLs, dense batch at row 12,191 | 24.59 µs | 3.22 µs | 3.20
µs |
| Alternating NULLs, dense batch from page start | 2.26 µs | 2.31 µs |
2.28 µs |
| 32-row NULL/non-NULL runs, stride 3 | 0.492 µs | 0.515 µs | 0.553 µs |
| 32-row NULL/non-NULL runs, dense batch at row 12,191 | 5.99 µs | 6.56 µs
| 6.70 µs |
- **Applicability and cost:** The gap optimization applies to value reads
with forward gaps on native pages containing NULLs. It uses the existing
decoder positions and requires no extra per-page memory or setting. The long
repeated-run controls showed a 0.06 µs increase for stride 3 and a 0.71 µs
increase when starting late in the page.
### Testing
- Built Apache Doris master and the candidate with `./build.sh` on Linux in
RELEASE mode. All 125 targeted BE tests passed. The new seek-count test fails
on master with 100 seeks and passes with 10 seeks. New tests verify NULL and
value alignment across page boundaries, unaligned one-bit skips, and incomplete
RLE input.
- The existing `global_rowid_nullable` regression suite passed. The SQL A/B
used a sparse filter on a value column, a clustered filter, a dense key range,
and TopN with deferred value columns. The TopN profile reported a
materialization operator and 4,096 second-phase rows.
### Release note
Reduce the CPU cost of sparse RowID reads from nullable native segment
columns.
### Check List (For Author)
- Behavior changed: No for valid segment pages.
- Does this need documentation: No
- Pre-submission status: Ready
### AI Disclosure
- Tool: OpenAI Codex
- Generated: implementation, tests, benchmark fixture, and 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]