Skip to content

Fix kqlRangeCount reporting an empty range for the Int256 minimum span with step -1 - #117212

Merged
alexey-milovidov merged 8 commits into
masterfrom
fix-kql-range-count-int256-min
Sep 20, 2026
Merged

alexey-milovidov merged 8 commits into
masterfrom
fix-kql-range-count-int256-min

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 31, 2026 •

Copy link
Copy Markdown
Member

Closes: #117103
Related: #112932

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Description

flooredCount guarded the span subtraction with common::subOverflow but left the division
span / step unguarded. The quotient of the minimum and -1 is not representable: the wide integer
wraps back to the minimum, steps comes out negative, and the empty-range branch returned 0 for a
range of 2^255 + 1 elements. Every neighbouring input, one closer to zero, correctly throws
The 'range' has too many rows to count.

The overflowing pair is now rejected with that same exception before the division.

The regression was introduced by #112932 and only
exists in the unreleased KQL rewrite on master, so it is not a released bug and has no changelog
entry.

Test 05059_kql_range_count_int256_min.


Workflow [PR]
Sync PR [sync-upstream/pr/117212]

Version info

  • Merged into: 26.10.1.296-master (included in 26.10 and later)

… span with step -1

`flooredCount` guarded the span subtraction against overflow but not the division. For a
span of exactly `Int256::min()` and a step of -1 the quotient is not representable, the
wide integer wraps back to the minimum, and the negative step count took the empty-range
branch - so the function returned 0 for a range of 2^255 + 1 elements, where every
neighbouring input correctly throws `The 'range' has too many rows to count`.

Closes: #117103
@clickhouse-gh

clickhouse-gh Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e1146ea]

Summary: ❌

job_name test_name status info comment
Build profile diff ERROR

AI Review

Summary

This PR fixes the kqlRangeCount signed-division overflow for the Int256 minimum span with step -1 by rejecting the only non-representable quotient before span / step. The guard sits in the shared flooredCount helper, preserves the existing overflow/empty-range behavior for neighboring inputs, and the new stateless test covers the regression together with nearby non-overflow cases. I did not find any remaining correctness, compatibility, or coverage issue in the current diff.

Final Verdict

✅ No new findings.

LLVM Coverage Report

Measured on commit e1146ea.

Metric Baseline Current Δ
Lines 88.40% 88.50% +0.10%
Functions 91.80% 91.80% +0.00%
Branches 80.60% 80.70% +0.10%

Changed lines: Changed C/C++ lines covered: 6/7 (85.71%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 31, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing commit e1146ea6b2d834b7fb3855e8ea9b7a141586a8ef with master failed: RuntimeError: CI logs cluster query failed: SELECT file, quantileExactWeightedInterpolated(0.5)(pr_….

See the job log for details.

alexey-milovidov and others added 2 commits September 2, 2026 17:02
Master now has `05056_map_combinator_state_stranded_on_throw`, so the new
test takes the next free number.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog comp-regular-function Regular scalar functions: string processing, data conversion, arithmetic, math, comparison, condi... and removed pr-bugfix Pull request with bugfix, not backported by default labels Sep 2, 2026

@alexey-milovidov alexey-milovidov left a comment

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.

Ok.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 20, 2026
@alexey-milovidov alexey-milovidov self-assigned this Sep 20, 2026
Merged via the queue into master with commit ea2e4fa Sep 20, 2026
175 of 177 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-kql-range-count-int256-min branch September 20, 2026 20:26
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-regular-function Regular scalar functions: string processing, data conversion, arithmetic, math, comparison, condi... pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kqlRangeCount returns 0 instead of throwing when the range span is exactly the Int256 minimum with step -1

2 participants