matanper opened a new issue, #71120:
URL: https://github.com/apache/doris/issues/71120

   ### Search before asking
   
   - [X] I had searched in the 
[issues](https://github.com/apache/doris/issues?q=is%3Aissue) and found no 
similar issues.
   
   ### Description
   
   Numeric segment pages use one fixed encoding per type: PLAIN + LZ4F for 
signed ints and floats in V3, and BIT_SHUFFLE + LZ4 in V2 (and for 
dates/decimals in V3). Decode is bounded by LZ4 at roughly 1.5-6 GB/s, and 
reading a single value means decompressing a whole 64 KB page (~15-18 us 
uncached).
   
   Formats like Vortex instead use "lightweight" encodings that decode without 
a general-purpose compression pass and allow reading single values directly: 
FastLanes frame-of-reference + bit-packing, delta and RLE; ALP for doubles; 
DateTimeParts for timestamps.
   
   I measured them codec-only:
   
   - **Pages:** Doris-sized 64 KB pages, every codec verified bit-exact against 
the input.
   - **Data:** 33 columns, 1,075 MB raw, from ClickBench `hits`, TPC-H SF1 
`lineitem` and synthetic distributions.
   - **Machines:** Apple M4 Pro and AWS c7i (AVX-512).
   - **Baselines:** Doris' current page settings reproduced. FastLanes 
delta/RLE come from the reference `fastlanes` crate that Vortex uses.
   
   | strategy | size | decode | median single-value read |
   |---|---|---|---|
   | Doris V3 defaults | 409.7 MB | 0.300 s | 15.4 us |
   | Doris V2 defaults | 354.4 MB | 0.309 s | 15.9 us |
   | **per-page chooser over lightweight encodings** | **272.9 MB (-33%)** | 
**0.242 s** | **0.47 us** |
   
   (M4 Pro shown; c7i: 411.0 -> 284.0 MB, 0.397 -> 0.265 s, 18.5 -> 0.41 us.)
   
   Findings:
   
   1. **Numeric columns** are 38% smaller than V3 defaults (21% smaller than 
V2) with **3x faster decode**.
   2. **Doubles: ALP is a clear win.** `l_discount` 15.4x vs 3.0x with 4-9x 
faster decode; `l_extendedprice` 2.6x vs 1.5x.
   3. **Integers: no single encoding wins, so selection must be per page.** 
Sorted/repetitive data needs run encodings (ClickBench `UserID` 11.9x vs 9.8x 
with LZ4F, `OS` 36.9x vs 15.3x). Random-looking keys need FoR (TPC-H 
`l_partkey` 3.5x vs 1.9x, 6x faster decode). Choosing from two sampled 
1024-value vectors per page lands within 1% of the best possible per-page 
choice, and an LZ4 fallback gains under 1%.
   4. **The V3 PLAIN default for signed ints compresses noticeably worse than 
V2's bitshuffle** on non-repetitive data (`l_partkey` 1.9x vs 3.5x, `l_suppkey` 
1.2x vs 2.3x).
   5. **DATETIMEV2's bitfield layout bit-packs poorly.** Splitting into days / 
seconds / sub-seconds reaches 90% of bitshuffle's size with 1.6x faster decode 
and ~90x faster single-value reads.
   
   ### Use case
   
   - Scan-heavy analytics: lower decode CPU per scanned value.
   - Point lookups and late materialization: single values without 
decompressing a page.
   - Storage cost: about a third smaller on the measured data.
   
   ### Related issues
   
   - #71119: replace the fixed 256 KB string dictionary limit with a size-aware 
rule (the string-side counterpart, which needs no new encoding).
   - #63622, #62649: current V2/V3 default encodings.
   
   Proposed direction, phased:
   
   1. Register new page encodings in `EncodingInfo` as read-only first, so no 
BE ever meets a page it cannot decode; then enable writing behind a 
version/config gate.
   2. Add one adaptive encoding whose pages carry a 1-byte scheme header (FoR, 
FastLanes delta, FastLanes RLE, run-end, ALP, DateTimeParts), chosen by 
sampling aligned 1024-value vectors. No proto change is needed.
   3. Each segment's `ColumnMetaPB` already records its encoding, so old and 
new segments mix within a tablet and compaction converts data over time; no 
rewrite is needed.
   4. Library choices to discuss: CWI's ALP (C++) or a port, and FastLanes 
kernels (C++ generated code, or a port of the reference crate).
   
   Limitations so far: codec-level only (no null maps, no `IColumn` 
materialization, no page cache or I/O); the per-page selection has not been 
tested inside Doris yet. A natural next step is a prototype page 
builder/decoder in `be/src/storage/segment/`, starting with ALP for DOUBLE. I 
can share the benchmark harness and raw results.
   
   ### Are you willing to submit PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
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]

Reply via email to