Repository navigation
Adaptive codec selection for structural substreams - #117348
Conversation
|
Workflow [PR], commit [3cbd827] Summary: ✅
AI ReviewSummaryThis PR extends Missing context / blind spots
Findings
Tests
Final Verdict❌ Changes requested. LLVM Coverage ReportMeasured on commit 3cbd827.
Changed lines: Changed C/C++ lines covered: 71/73 (97.26%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units83 translation units recompiled, 802 s compile time in total, 83 of them have a recent master baseline. |
|
|
||
| const auto & substream_type = substream_path.back().data.type; | ||
| /// Adaptive could pick an unencrypted codec for some blocks and drop the encryption. Thus skip adaptivity for an encrypting default. | ||
| if (settings.apply_adaptive_codec && column_uses_default_codec && substream_type && !resolved_codec->isEncryption()) |
There was a problem hiding this comment.
Shared Nested offsets make column_uses_default_codec too local here. With share_nested_offsets = 1, n.size0 is one physical stream, but addStreams in both writers creates it on the first sibling and later siblings just return on column_streams.contains / compressed_streams.contains. That means a table like (`n.a` Array(UInt64), `n.b` Array(UInt64) CODEC(ZSTD)) lets the first default-coded sibling wrap n.size0 in CompressionCodecAdaptive, and the explicit-coded sibling silently reuses that adaptive stream. The resulting codec depends on declaration order and violates the contract that only default-coded columns go adaptive. Please either keep shared Nested offsets non-adaptive or compute eligibility across all siblings that own the shared n.size0 stream, and add a focused regression test for that case.
There was a problem hiding this comment.
True, but the same complaint belongs to master. My change didn't create that, and fixing it properly is a separate, pre-existing question.
| /// A structural substream goes adaptive if its serialized bytes = declared type and a candidate wins on size without losing read speed. | ||
| /// Excluded: null maps (adaptive wins size but reads slower), `SparseOffsets` (`UInt64` in memory, varint on disk). | ||
| const auto kind = substream_path.back().type; | ||
| const bool is_size_substream = kind == ISerialization::Substream::ArraySizes || kind == ISerialization::Substream::StringSizes; |
There was a problem hiding this comment.
This looks hacky, can't we take into account deserialization time when choosing codecs?
There was a problem hiding this comment.
CI is green, but I agree. I will make rules structural and instead of an allowlist before merging
Previously we gated null maps. T64 alone does not compress them well. But we plan to add {codec + default} as a candidate, and T64 + LZ4 and T64 + ZSTD are better than LZ4 and ZSTD alone. The other one was SparseOffsets, which stored varint pretending to be UInt64. We will guard these off by a non-hacky rule instead (see next commits)
rienath
left a comment
There was a problem hiding this comment.
Thanks for pushing me to improve the design. Now adaptivity applies to all substreams. Substreams without a type would get {default, None}. Substreams with a type would get the codecs based on the type.
There were two problematic cases previously:
- Null map almost always compressed worse with
T64as values of a map are binary. I benchmarked it with chainT64+ Default and saw a good improvement. Since adding chains is a follow-up, we can keep null maps adaptive. - Sparse serialization offsets were
VarUInton disk, but we wroteUInt64as the type inSerializationSparse.cpp. Thus it never compressed well. Instead of a hack to avoid it, I will make a follow-up PR that removes the type info from serialization. Then it will faithfully never receiveT64again
|
|
||
| /// Adaptive could pick an unencrypted codec for some blocks and drop the encryption. Thus skip adaptivity for an encrypting codec. | ||
| if (settings.apply_adaptive_codec && column_uses_default_codec && !codec->isEncryption()) | ||
| return std::make_shared<CompressionCodecAdaptive>(substream_type, codec); |
There was a problem hiding this comment.
substream_type is not a reliable proxy for "the bytes in this stream match a regular typed column". SerializationSparse::enumerateStreams still tags SparseOffsets as UInt64, but serializeOffsets writes VarUInt group sizes with an end-of-granule flag. After this change, that stream now goes through the regular adaptive pool and can benchmark or pick T64 even though the on-disk payload is not a fixed-width UInt64 stream.
Please keep SparseOffsets out of adaptive selection until the serialization stops advertising it as UInt64, or land that SerializationSparse change in this PR. Otherwise sparse-column compression and read trade-offs depend on misleading metadata rather than the actual byte layout.
There was a problem hiding this comment.
It is, what you describe is a bug I've fixed in #118048
Adaptive codec selection now covers every substream of a column that uses the default codec, not only the main data stream. A substream with a type gets a codec from the regular pool. For example,
UInt64Array/Stringsize streams andUInt8null maps are priced againstT64. A substream without a type is priced againstNONEand the default codec, so incompressible bytes are stored raw.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Adaptive codec selection (
enable_adaptive_codec_selection) now applies to every substream of a column, such asArrayandStringsizes and null maps, instead of the main data stream only.Workflow [PR]
Sync PR [sync-upstream/pr/117348]
Version info
26.9.1.772(included in26.9and later)