Skip to content

Avoid truncating dictionary fill codes - #10745

Open
connortsui20 wants to merge 1 commit into
developfrom
ct/dict-fill-code
Open

connortsui20 wants to merge 1 commit into
developfrom
ct/dict-fill-code

Conversation

@connortsui20

Copy link
Copy Markdown
Member

Summary

Fixes #10623.

Dict::fill_null converted the index of the matching dictionary value into the codes type with an unchecked as cast. A dictionary can hold more values than its codes type can index, so an unreferenced fill value could truncate to the wrong code (with u8 codes, filling with value 300 returned value 44) or panic for signed codes.

Changes

The kernel now checks the index against the range of the codes type. When the index does not fit, the kernel declines and the generic fill_null path fills the decoded array, which is slower but correct. Non-nullable codes need no fill code, so they keep the fast path. The new tests cover u8 and i8 codes at and past their maximum, and non-nullable codes over nullable values. The three cases past the maximum fail without the fix.

The Narrow work (#10733) depends on this fix, because a rule there makes narrow dictionary codes common.

🤖 Generated with Claude Code

The dictionary fill_null kernel converted the index of the fill value into the codes type with an unchecked cast. A dictionary can hold more values than its codes type can index, so an unreferenced fill value could truncate to the wrong code, or panic for signed codes. The kernel now checks the index against the range of the codes and declines when it does not fit, so the generic path fills the decoded array. Non-nullable codes need no fill code, so they keep the fast path.

Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
@connortsui20 connortsui20 added the changelog/fix A bug fix label Oct 23, 2026
@codspeed

codspeed Bot commented Oct 23, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 4.18%

4 warnings, 1 note

⚠️ 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

⚠️ Unable to measure the execution of 2 benchmarks

These benchmarks measured no execution time, so their results are not comparable and count as unchanged. This usually happens when the compiler removes the code under test.

Prevent compiler optimizations

See affected benchmarks

⚠️ 22 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ Base and head ran on different runner types

Some benchmarks with significant performance changes were compared across different runner types, so the changes might not come from the code. Run base and head on the same runner type, or use CodSpeed Macro Runners for more stable results.

Learn more about Macro Runners

Open the report in CodSpeed to investigate

ℹ️ 40 benchmarks have no flamegraph

The flamegraph wasn't generated: the symbols of the profiling trace could not be resolved, because no information about the language frames was collected.

See affected benchmarks

⚡ 3 improved benchmarks
❌ 11 regressed benchmarks
✅ 2394 untouched benchmarks
⏩ 12 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ CPU Simulation test_scan_filter_to_arrow_array[int_float] 3.5 ms 4.1 ms -13.59%
❌ CPU Simulation filter_powerlaw_by_mostly_false[250000] 138.6 µs 159.1 µs -12.88%
❌ Walltime bitpack_blocked_compress_avx2 6.7 µs 7.6 µs -11.75%
❌ CPU Simulation filter_random_by_mostly_false[250000] 163.2 µs 183.5 µs -11.08%
❌ CPU Simulation test_repeated_scan_filter[int_float] 3.4 ms 3.9 ms -10.87%
❌ CPU Simulation density_sweep_dense_runs[0.001] 53.6 µs 59.9 µs -10.59%
❌ CPU Simulation filter_powerlaw_by_power_law[250000] 166.1 µs 185.2 µs -10.35%
❌ CPU Simulation test_repeated_scan_filter[int] 2.4 ms 2.7 ms -10.33%
❌ CPU Simulation test_scan_filter_to_arrow_array[int] 2.5 ms 2.8 ms -10.26%
❌ CPU Simulation filter_random_by_power_law[250000] 166.1 µs 185.1 µs -10.26%
❌ CPU Simulation filter_powerlaw_by_random[250000] 153.7 µs 170.9 µs -10.07%
⚡ CPU Simulation bench_compare_primitive[(10000, 32)] 97 µs 71.8 µs +35.22%
⚡ CPU Simulation chunked_dict_primitive_canonical_into[f64, (1000, 1000, 10)] 191.7 µs 151.5 µs +26.55%
⚡ Walltime starts_with_avx2[8, VarBin] 46.9 µs 40 µs +17.3%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing ct/dict-fill-code (5602cd0) with develop (3974ee0)

Open in CodSpeed

Footnotes

  1. 12 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. ↩

@connortsui20
connortsui20 marked this pull request as ready for review October 23, 2026 20:34
Comment on lines +63 to +65
if fill_index > codes_dtype.as_ptype().max_value_as_u64() {
return Ok(None);
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

should we widen instead of just giving up here?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dict fill_null can truncate indices of unreferenced dictionary values

1 participant