Skip to content

fix(query): avoid panic on UInt64 full-range scan stats (#19555)#19631

Closed
sundy-li wants to merge 3 commits intodatabendlabs:mainfrom
sundy-li:fix/issue-19555-planner-u64-overflow-20260329
Closed

fix(query): avoid panic on UInt64 full-range scan stats (#19555)#19631
sundy-li wants to merge 3 commits intodatabendlabs:mainfrom
sundy-li:fix/issue-19555-planner-u64-overflow-20260329

Conversation

@sundy-li
Copy link
Copy Markdown
Member

@sundy-li sundy-li commented Mar 29, 2026

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

  • avoid the UInt64 full-range overflow when Scan::derive_stats reduces NDV from min/max column statistics
  • keep the planner on the saturating path for [0, u64::MAX] stats instead of panicking during scan stats derivation
  • add a sqllogictest regression for the full-range UInt64 table case

Fixes #19555

Implementation

  1. Extract the integer-range NDV reduction into a helper in scan.rs
  2. Use saturating arithmetic for unsigned spans so max - min + 1 does not overflow on the full UInt64 range
  3. Add a unit test for the helper and a sqllogictest regression covering the reported table shape

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Pair with the reviewer to explain why

Validation run locally:

  • CARGO_HOME=/workspace/databend/.worktrees/pr-fix-19555/.cargo-home CARGO_TARGET_DIR=/workspace/databend/.worktrees/pr-fix-19555/.cargo-target cargo test -p databend-common-sql test_reduce_ndv_by_uint_full_range_saturates
  • CARGO_HOME=/workspace/databend/.worktrees/pr-fix-19555/.cargo-home CARGO_TARGET_DIR=/workspace/databend/.worktrees/pr-fix-19555/.cargo-target cargo clippy -p databend-common-sql --tests -- -D warnings

Added but not executed locally:

  • tests/sqllogictests/suites/base/issues/issue_19555.test

Type of change

  • Bug fix (non-breaking change which fixes an issue)

This change is Reviewable

@github-actions github-actions bot added the pr-bugfix this PR patches a bug in codebase label Mar 29, 2026
@sundy-li sundy-li added agent-reviewable Ready for agent review agent-approved Approved by agent and removed agent-reviewable Ready for agent review labels Mar 29, 2026
@sundy-li
Copy link
Copy Markdown
Member Author

sundy-li commented Apr 1, 2026

Closing this PR because the same fix was already merged via #19632 on 2026-03-30. As a result, this branch now has no net diff against main.

@sundy-li sundy-li closed this Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-approved Approved by agent pr-bugfix this PR patches a bug in codebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: planner panic on UInt64 full-range column stats: attempt to add with overflow in Scan::derive_stats

1 participant