Skip to content

Sample mostly-null arrays in integer and float Sparse selectors - #12300

Closed
lwwmanning wants to merge 6 commits into
developfrom
wm/sample-mostly-null-sparse
Closed

lwwmanning wants to merge 6 commits into
developfrom
wm/sample-mostly-null-sparse

Conversation

@lwwmanning

@lwwmanning lwwmanning commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

This changes how the BtrBlocks compressor prices and encodes Sparse for mostly-null integer and float columns (integer::SparseScheme and float::NullDominatedSparseScheme). Other schemes and the file format stay the same. Two compact golden snapshots change, and the PR adds one public method and changes the behavior of the public Sparse::encode.

On develop, both schemes score an array that is more than 90% null with a fixed ratio, len / value_count. That ratio ignores how well the patch values and indices compress, and it ignores the validity bitmap that Sparse drops. Since #12266, Pco scores itself on the compression sample, a few slices of the array that each candidate compresses. So Pco can win on these columns even when Sparse is smaller. With this PR, both schemes also compress the sample, through the new CascadingCompressor::estimate_with_sampling. If the sample holds only nulls, they fall back to len / value_count.

The sample can be 90% null or less when the full array is not. So that the estimate and the full encode use the same layout, both schemes now pass a null fill to Sparse::encode. Sparse::encode now uses the null-fill layout for any explicit null fill if the array has at least one null. Before, it used that layout only above 90% null. integer::SparseScheme now also picks a null fill whenever nulls outnumber its most frequent value, and its estimate matches that choice.

On the compact golden data, float_mostly_null (f64?) moves from Pco at 7,837 B to Sparse at 7,545 B. int_mostly_null (i32?) moves from 3,086 B to 1,661 B.

Related to #12266. Overlaps #12263, which keeps a fixed estimate for the patch indices and still selects Pco on float_mostly_null.

Assisted by AI.

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-28T22:01:28.660336Z cd2c774 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@devin-ai-integration devin-ai-integration Bot added quick-review Small, self-contained change that is quick to review changelog/fix A bug fix labels Nov 28, 2026
@vortex-roborev-bot

vortex-roborev-bot Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

roborev: Combined Review (c50bb4e)

Verdict: Changes require fixes for 1 finding.

Low

  • vortex-test/compat-gen/src/fixtures/arrays/synthetic/encodings/sparse.rs:112-116: The mixed_null_and_values compat column no longer produces a null-fill Sparse array whose patches contain nulls. It is about 6% null and passes an explicit null fill. Sparse::encode now sends it down the null-fill path, which writes only the valid rows with u32 indices. Before, every row was written as a patch, nulls included, with u64 indices. The column now behaves almost like sparse_i64, so readers of the old layout lose compat coverage.

    Fix: Build this column directly with Sparse::try_new, using u64 indices for every row, nullable patch values and a null fill, then check that the generated patches contain nulls. If that layout no longer needs coverage, rename or drop the column.


Reviewers: claude-code | Synthesis: claude-code, 9s, ~$0.04 | Total: 43s, ~$0.32

@vortex-roborev-bot vortex-roborev-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line comments for the roborev review of cd2c774. The roborev PR comment has the full review.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cd2c774fae

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>

@lwwmanning lwwmanning left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted by Claude Opus 5.5 on Will's behalf.

I reviewed f28d6bb. The ZeroBytes fallback in null_dominated_sparse_estimate fixes the all-null sample. The new null-fill rule in Sparse::encode opens a panic, though.

Sparse::encode now takes the null-dominated branch whenever the fill is null (encodings/sparse/src/lib.rs:507). That branch still assumes the input has a null, and calls unreachable! when mask.indices() is AllOr::All (line 521). Before this commit, a null fill on an array with no nulls went to the general path instead.

NullDominatedSparseScheme::encode now passes a null fill on every call, and the sampler calls it on the sample as well as on the full array. The full array must be over 90% null, but the sample can still be all valid.

The stratified sampler takes 16 runs of 64 rows at fixed, seeded positions. A 16,384-row f64? column whose 1,024 valid rows sit at exactly those runs is about 94% null, and its sample has no nulls. Long arrays sample whole 1,024-row FastLanes chunks, so a column with clustered validity can hit the same case. The panic then fails the whole write, not just the estimate. I have not run this case.

A small fix is to require a null in the mask too, for example fill_value.as_ref().is_some_and(Scalar::is_null) && !mask.all_true(). With no nulls, the general path then stores every row as a patch under the null fill. A test that builds the array from sample_slices positions would pin it down. Sparse::encode is public, so this also keeps the old behavior for other callers.

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

Good catch — fixed in 08eae23ec by guarding the null-fill fast path with !mask.all_true() and adding unit tests in encodings/sparse/src/lib.rs for Sparse::encode with an explicit null fill on both all-valid and below-90%-null inputs.

@codspeed

codspeed Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

Warning

vortex-data has exceeded the Hobby plan limit of 5 active contributors. Upgrade your plan or apply to the open source program by December 8, 2026 to keep using CodSpeed.

1 warning

⚠️ Walltime results may be unreliable

Some benchmarks used the Walltime instrument outside CodSpeed Macro Runners, which can make the results inconsistent.

Learn more about Macro Runners

See affected benchmarks

✅ 2177 untouched benchmarks
⏩ 164 skipped benchmarks1


Comparing wm/sample-mostly-null-sparse (c50bb4e) with develop (4525dfa)

Open in CodSpeed

Footnotes

  1. 164 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
@devin-ai-integration

devin-ai-integration Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Devin Review

🟢 Devin Review found nothing to fix · View findings · Follow Devin's work

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@robert3005 robert3005 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a regression in the public Sparse::encode path for explicit null fills. This PR also conflicts with #12263 in the integer and float selectors. When those changes are combined, the shared sample should price the same compressed float patch children that the full encoder writes.

— Codex (OpenAI)

Comment thread encodings/sparse/src/lib.rs Resolved
Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
…fills

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

Regarding roborev's Low note on vortex-test/compat-gen/.../sparse.rs (mixed_null_and_values): the previous Sparse::encode(..., Some(null)) output storing every row (including nulls) as a patch with u64 indices was an accidental consequence of compare(null, NotEq).fill_null(true) returning AllTrue, not an intentional layout to preserve in Sparse::encode. Leaving compat-gen untouched here so mixed_null_and_values continues to exercise Sparse::encode with an explicit null fill; readers of null-valued patches under a null fill remain covered by existing unit tests (validity_mask_includes_null_values_when_fill_is_null) and frozen compat files.

@lwwmanning lwwmanning left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by Gemini 4 Carbon on behalf of @lwwmanning.

Sampling > 90% null arrays on the shared sample (CascadingCompressor::estimate_with_sampling) and honoring an explicit null fill_value in SparseData::encode is the right mechanism to compete fairly with Pco (#12266), but this PR conflicts directly with #12263 on vortex-btrblocks/src/schemes/float/sparse.rs and vortex-btrblocks/src/schemes/integer/sparse.rs and has four gaps if landed without #12263:

  1. Float patch_values is left uncompressed (vortex-btrblocks/src/schemes/float/sparse.rs): Without #12263's child-0 values cascade, float::NullDominatedSparseScheme keeps patch_values uncompressed (7,545 B on golden__compact__float_mostly_null.snap, which is 1,116 B larger than dense Pco once #12258 lands, vs ~6,427 B when cascading both values and indices).
  2. Sample-vs-full fill-branch mismatch (vortex-btrblocks/src/schemes/integer/sparse.rs:154): When null_dominated_sparse_estimate runs SparseScheme::encode on sample.data, stats.null_count() > most_frequent_count is re-checked on the sample's stats and can flip to a non-null fill when valid values cluster in a sampled slice.
  3. Count-based ratio (len / patch_count) in <= 90% null integer::SparseScheme and ZeroBytes fallback: integer/sparse.rs:131-136 and schemes/mod.rs:528 ignore elem_bytes, narrowed idx_width, and patch_validity (fixed by #12263's byte-accurate calculation).
  4. Sample index-width under-pricing when len > 65,536: sample.data (~1,024 rows) narrows patch_indices to u16 (2 B) even when full_len > 65,536 requires u32 (4 B).

Remediation Plan

Please fold #12300 (encodings/sparse/src/lib.rs + vortex-compressor/src/compressor/mod.rs + sample-based null_dominated_sparse_estimate) into #12263 following the unified remediation plan posted on #12263, and close #12300.

@lwwmanning

Copy link
Copy Markdown
Contributor Author

Folded into #12263.

@lwwmanning lwwmanning closed this Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/fix A bug fix quick-review Small, self-contained change that is quick to review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants