Repository navigation
Sample mostly-null arrays and price indices in sparse scheme selectors - #12263
lwwmanning wants to merge 2 commits into
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
roborev: Combined Review (
|
robert3005
left a comment
There was a problem hiding this comment.
I checked this head against #12300. Git reports conflicts in both integer/sparse.rs and float/sparse.rs. When combining them, please preserve the float patch-values child at slot 0 and the index exclusions at slot 1 from this PR, and keep #12300’s shared-sample comparison and all-null-sample fallback. The patch-values compression test here and the all-null-sample selection tests there cover different ways the combined selector could regress.
— Codex (OpenAI)
robert3005
left a comment
There was a problem hiding this comment.
I also checked the compact snapshots across #12258, #12262, this PR and #12300. The float fixture has pairwise conflicts involving all four branches, and #12258 and #12300 also conflict on the integer fixture. Once the selector changes are combined, please regenerate the affected snapshots from the combined encoder. Each checked-in size reflects a different set of candidates.
— Codex (OpenAI)
lwwmanning
left a comment
There was a problem hiding this comment.
Review by Gemini 4 Carbon on behalf of @lwwmanning.
The string::NullDominatedSparseScheme fixes (len.saturating_sub(1) index width, with_sampling(), FSST/OnPair fixed-table amortization), the child-0 patch_values + child-1 patch_indices cascade in float::NullDominatedSparseScheme, and the byte-accurate elem_bytes + idx_width + patch_validity pricing for <= 90% null integer::SparseScheme are all the right changes.
However, this PR conflicts directly with #12300 on vortex-btrblocks/src/schemes/float/sparse.rs and vortex-btrblocks/src/schemes/integer/sparse.rs, and neither PR works cleanly on its own:
- In
#12263alone,> 90%null integer and float arrays are scored with the un-cascaded closed-form ratiouncompressed_bytes / (value_count * (elem_bytes + idx_width)). BecausePco(#12266) estimates on compressed samples, un-cascadedSparseunderestimates its ratio whenever patch values or indices compress well—losing to densePcoongolden__compact__float_mostly_null(7,837 B) and leavinggolden__compact__int_mostly_nullat3,086 Binstead of1,661 B. - Conversely,
#12300alone samples> 90%null arrays viaestimate_with_sampling, but lacks#12263's child-0patch_valuescascade on floats (leavingpatch_valuesuncompressed at7,545 B, which is1,116 Bworse than densePcoonce#12258lands) and lacks#12263's byte-accurate pricing on<= 90%null integers andZeroBytessamples.
Please fold #12300 into #12263 (and close #12300) so the sparse selector changes land as one coherent unit.
Remediation Plan
- Bring
#12300's sample estimation + explicit null-fillSparse::encodeinto#12263:- Cherry-pick
#12300's changes toencodings/sparse/src/lib.rs(SparseData::encoderespecting explicitSome(Scalar::null(..))+collect_null_fill_indices) andvortex-compressor/src/compressor/mod.rs(CascadingCompressor::estimate_with_sampling). - Keep
#12263'svortex-btrblocks/src/schemes/string/sparse.rsand#12263's 2-child (values=0, indices=1) cascade +descendant_exclusionsinvortex-btrblocks/src/schemes/float/sparse.rs, passingSome(Scalar::null(data.array().dtype().clone()))toSparse::encodeinfloat::NullDominatedSparseScheme::encode.
- Cherry-pick
- Unify
null_dominated_sparse_estimateand byte-accurate closed-form pricing invortex-btrblocks/src/schemes/mod.rsandinteger/sparse.rs:- Extract a shared helper
sparse_byte_ratio(len: usize, elem_bytes: usize, has_nulls: bool, patch_count: usize, patch_has_validity: bool) -> EstimateVerdictinvortex-btrblocks/src/schemes/mod.rsthat computesuncompressed_bytes / compressed_bytesusingidx_width = PType::min_unsigned_ptype_for_value(len.saturating_sub(1) as u64).byte_width()and returnsEstimateVerdict::Skipwhencompressed_bytes == 0 || compressed_bytes >= uncompressed_bytes. - In
null_dominated_sparse_estimate(vortex-btrblocks/src/schemes/mod.rs), useEstimateScore::ZeroBytes => Ok(sparse_byte_ratio(len, elem_bytes, true, value_count, false))instead oflen / value_countwhen all valid rows miss the sample. - Account for full-array index narrowing on
> 65,536-row arrays during sample estimation:sample.datahas~1,024rows soencodenarrows sampledpatch_indicestou16(2 B) even whenfull_len > 65,536narrows fullpatch_indicestou32(4 B). Adjust the sampled estimate for(full_idx_width - sample_idx_width) * sample_patch_count(or pricepatch_indicesatfull_len's indexPTypewhencompress_ctx.is_sample()) sotest_float_sparse_prices_indices_against_uncompressed_bytes(100,000f32rows) still prefersFloatDict/ALPoverSparse. - Fix the sample-vs-full fill-value invariant in
vortex-btrblocks/src/schemes/integer/sparse.rs: whennull_dominated_sparse_estimatesamples a> 90%null integer array whose sampled slice happens to havesample_null_count <= sample_most_frequent_count, ensure sample estimation still encodes withScalar::nullfill so it prices the same layout that full compression writes. - In
integer::SparseScheme::expected_compression_ratio(<= 90%null branch), combine#12300'sstats.null_count() > most_frequent_countnull-fill check (patch_count = value_count,patch_has_validity = false) withsparse_byte_ratio(instead of#12300'slen / patch_count).
- Extract a shared helper
- Regenerate golden snapshots & keep total added tests
<= 20:- Regenerate
golden__compact__int_mostly_null.snap(~1,661 B) andgolden__compact__float_mostly_null.snap(~6,427 Bwith cascadedpatch_values+patch_indices), and keep combined added test cases acrossencodings/sparseandvortex-btrblocks<= 20.
- Regenerate
Price <= 90% null integer estimates and all-null sample fallbacks by exact element, narrowed index, and validity bytes, sample > 90% null integer and float arrays on the shared compression sample while preserving null-fill layout and full-array index widths, cascade float patch values with child exclusions, honor explicit null fills in SparseData::encode, and fix string sparse index width, sampling context, and fixed-table amortization. Co-Authored-By: Antigravity <noreply@google.com> Signed-off-by: Will Manning <will@willmanning.io>
7924d1d to
027498b
Compare
lwwmanning
left a comment
There was a problem hiding this comment.
Posted by Claude Opus 5.5 on Will's behalf.
I checked 027498b against #12300's last head. The fold is complete. The null-fill Sparse::encode with the !mask.all_true() guard and u64 indices is here. So are the sampled estimate with the ZeroBytes fallback and all of #12300's tests, and the snapshots match the description.
test_integer_sparse_prices_index_bytes_so_bitpacking_wins_on_u8usescrate::schemes::integer::BITPACKING_V1, which #11905 deletes. The files do not overlap, so Git shows no conflict, and whichever PR lands second will not compile. UsingBitPackingSchemeonce #11905 lands avoids that.NullDominatedSparseSampleScheme::encodecopiesfloat::NullDominatedSparseScheme::encodeexcept for the index cast. A shared helper that takes a minimum indexPTypewould remove the copy. The wrapper'sexpected_compression_ratioandcompressareunimplemented!, so please keep it private and say in its doc comment that it must never be registered. The forced null fill matters only for the integer scheme, because the floatencodealready always uses one.Sparse::encodeis public, and it now uses the null-fill layout for an explicit null fill at any null fraction. Please name this as a behaviour change in the description, as #12300 did. It changes, for example, the layout that the compat fixturemixed_null_and_valueswrites.
…eme in test Signed-off-by: Will Manning <will@spiraldb.com> Co-Authored-By: Will Manning <will@spiraldb.com>
|
Addressed all three points in
|
robert3005
left a comment
There was a problem hiding this comment.
I checked the combined Sparse and Pco selection changes after #12300 closed. The sample and full encode both use an explicit null fill, float patch values cascade at child 0 and indices at child 1, and the explicit-null path retains the u64 boundary fix. The compressed-patch-values and all-null-sample regression fixtures are both present. This addresses my earlier integration comment.
— Codex (OpenAI)
Sparse scheme selectors on
developcount values rather than bytes for<= 90%null integers (ignoring narrowed patch-index and validity costs), skip cascading float patch values, size 65,536-row string indices asu32without a sampling context or fixed-table amortization, and score> 90%null integer and float arrays without child compression so densePcobeatsSparseeven whenSparseis much smaller.This change prices
<= 90%null integer estimates and all-null sample fallbacks using exact element, narrowed index, and validity bytes (sparse_byte_ratio), samples> 90%null integer and float arrays on the shared compression sample while preserving the null-fill branch and full-array index width, cascades both patch values and indices on floatNullDominatedSparseSchemewith child exclusions, honors explicit null fills inSparse::encode, and fixes stringNullDominatedSparseSchemeindex sizing, sampling context, and fixed-table amortization.Behaviour change:
Sparse::encodenow uses the null-fill layout for an explicitSome(Scalar::null(..))fill whenever the array contains at least one null, rather than only above 90% null (for example, changing the layout written by the compat fixturemixed_null_and_values).On the golden snapshots,
compact__float_mostly_nullshrinks from 7,837 B to 6,427 B,compact__int_mostly_nullshrinks from 3,086 B to 1,661 B,regular__float_mostly_nullshrinks from 8,609 B to 8,504 B, andstring_fsst_structuredshrinks by 1,106 B in both regular and OnPair modes.Related to #12266. Folds #12300.
Authored with AI assistance.