Skip to content

Fix wrong results from sumKahanIf and sumKahan over Nullable when the aggregated batch does not start at row 0 - #116990

Merged
Algunenano merged 3 commits into
ClickHouse:masterfrom
groeneai:fix-sum-kahan-conditional-row-offset
Sep 2, 2026
Merged

Algunenano merged 3 commits into
ClickHouse:masterfrom
groeneai:fix-sum-kahan-conditional-row-offset

Conversation

@groeneai

@groeneai groeneai commented Aug 29, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #116952

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed wrong results from sumKahan when the aggregated batch does not start at the first row of the block. sumKahanIf, and sumKahan over a Nullable argument, tested each row against the wrong element of the condition or null map, returning silently incorrect sums inside window frames such as ROWS BETWEEN 2 PRECEDING AND CURRENT ROW, in parallel GROUP BY, and under optimize_aggregation_in_order = 1.

Description

AggregateFunctionSumKahanData::addManyConditionalInternal advances its value pointer to the batch's first row but never advances the flag map, so row start + i is tested against flag i. Every sumKahan spelling with a per-row flag map then silently returns a wrong number when the batch does not begin at row 0. Reachable at stock defaults:

SELECT n, sumIf(x, cond) OVER w, sumKahanIf(x, cond) OVER w
FROM (SELECT number AS n, toFloat64(1) AS x, toUInt8(number < 3) AS cond FROM numbers(6))
WINDOW w AS (ORDER BY n ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) ORDER BY n;
-- rows 3,4,5: expected 2,1,0 but sumKahanIf gives 3,3,3

Three callers pass a non-zero start, two needing no setting: a window frame not beginning at the block's first row, as above; parallel GROUP BY, where the adaptive aggregator slices a threshold-crossing block so every slice after the first starts mid-block, and a slice covering one key reaches this kernel (one-key 1000000-row table returns 400 where the answer is 100; needs enable_adaptive_aggregator, default true, so 26.8 onward); and in-order GROUP BY under optimize_aggregation_in_order = 1. Decimal sumKahan is unaffected, using the generic sum data. Both maps are at least row_end long, so the read stays in bounds: wrong results, not memory unsafety.

The fix adds the one missing statement, so this copy agrees with the generic copy, which got this line in 0754ee49016bf64, a commit with no test, which is why this copy survived. The tree had no sumKahanIf test and no non-zero-start sumKahan test; the new test adds both, with a sumIf control column pinning both copies. Of the eight pointers in src/ advanced by the batch start, this was the only one not advancing its map.

Reported as an aside by @ snelheidai in #116952, whose performance defect is a separate PR. Also noticed, not raised: the make_unique<UInt8[]>(row_end) prefix-fill idiom at ten sites.


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

Version info

  • Backported to: 26.8.3.15, 26.7.7.10, 26.6.5.27, 26.3.29.10

…t row 0

AggregateFunctionSumKahanData::addManyConditionalInternal advances its value
pointer to the first row of the batch but never advances the flag map, and the
loop then walks the map relatively, so values are read from index `start` while
flags are read from index 0: row `start + i` is tested against flag `i`. Every
sumKahan spelling carrying a per-row flag map returns a silently wrong number
whenever the aggregator hands it a batch that does not begin at row 0. There is
no exception and no log line.

767acd5 changed both copies of this kernel from (ptr, map, count) to
(ptr, map, start, end) and added `ptr += start` to both, `condition_map += start`
to neither. 0754ee4 later added the missing statement to the generic
AggregateFunctionSumData copy, as a one-line commit with no test, which is why
the surviving copy went unnoticed. This adds the same statement to the Kahan
copy, so the two implementations of the interface agree again; a third
implementation written independently, AggregateFunctionSumPrometheusData in
open PR ClickHouse#114251, also writes it. Fixing the kernel rather than its call sites
repairs both entry points (addManyNotNull, addManyConditional) and all three
call sites at once, and keeps the contract for future callers. At start == 0 the
added statement is `+= 0`, so every correct caller is byte-identical.

Three callers pass a non-zero start, two of them with no setting at all.
WindowTransform's first_row is block relative, so any frame not beginning at the
block's first row reaches it, which is what makes this reachable at stock
defaults. Parallel plain GROUP BY reaches it as well: when a block can push the
local table past adaptive_aggregator_freeze_threshold,
Aggregator::executeImplUntilAdaptiveFreeze aggregates that block in slices, and
every slice after the first starts mid-block. An env-gated counter inside the
kernel saw 46 of 62 entries with start > 0 there, at the slice boundaries 16383,
16384, 32766, 32767, 49149 and 49150, and a single-key 1000000-row table returns
400 for sumKahanIf where the answer is 100. That route needs
enable_adaptive_aggregator, which defaults to true and exists from 26.8, and it
needs more than one input stream, because AggregatingStep only creates the
adaptive session for parallel aggregation; that is why single-stream fixtures
over numbers() report start == 0 and measure nothing about it. The in-order
aggregation path reaches it under optimize_aggregation_in_order = 1. Both maps
are always at least row_end long, so the misindexed read stays in bounds; this
is wrong results, not a memory safety problem.

The test has three arms, one per distinct code path: a window frame over the -If
combinator, a window frame over a Nullable argument (the null-map instantiation,
add_if_zero = true), and the in-order aggregation path. Each arm reddens a
disjoint set of reference lines on the unfixed build. One further statement
asserts that the in-order arm really gets the in-order pipeline, so the arm
cannot pass by silently falling back to hash aggregation; it holds on both
builds, and reads 0 with optimize_aggregation_in_order = 0. cond is 1 only for n < 3,
so from row 5 the correct answer is a legitimate 0 while the unfixed answer is a
non-empty 3, which keeps the oracle from being satisfiable by the empty-set
value. x is toFloat64(1), exactly representable, so sum and sumKahan agree bit
for bit and the sumIf control column is a sound equality oracle; that column
also pins the generic copy, which has had no test since 0754ee4.

Validated on a debug build: 50 of 50 runs pass with the fix and 0 of 20 without
it. Every arm still reddens the unfixed build with the old analyzer, and the
in-order arm reddens it at max_threads 1, 2 and 3, so neither is pinned. The
in-order arm does pin aggregation_in_order_max_block_bytes to its default:
clickhouse-test randomizes it over 0 to 50000000, and at the draw 0
AggregatingInOrderTransform cuts the chunk at the first key boundary, which
restarts key_begin at 0 and hides the defect. Measured on the unfixed build,
only the draw 0 does that; 1 and every larger value leave the arm reddening. Of the
five pre-existing sumKahan tests, every sumKahan statement returns
byte-identical output on both builds; none uses a window frame, in-order
aggregation, or a flag map.

Reported as an aside by @ snelheidai in ClickHouse#116952. The performance defect
described in that issue is left to a separate PR.

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-self PR origin: self-found defect (impact-bar validated) labels Aug 29, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review

An independent reviewer and a second model reviewed this change before publication. Two rounds; the second returned no findings. Anything marked fixed is in the diff.

Finding Verdict
❌ The in-order regression arm could pass on the unfixed kernel: aggregation_in_order_max_block_bytes is randomized over 0 to its default, and a low enough value makes AggregatingInOrderTransform cut the chunk after each key, so every re-consumed interval starts at row 0 where the defect is invisible. Fixed. The arm pins that setting to its default. A sweep on the unfixed build then corrected the prediction: the trigger is the single draw 0, not any small value, because the byte counter stays at 0 for a fixture this size. So the pin closes a 1-in-50000001 silent loss of coverage rather than a frequent one. max_block_size = 1 served as a positive control that the cut does reach this fixture, so the mechanism is real and narrow rather than absent.
❌ The description claimed plain GROUP BY was unaffected, and the measurement behind that claim did not support it: of the six fixtures, three could not reach a non-zero batch offset by construction and three never entered the kernel at all. Fixed, and the conclusion reversed. The blocking term was that AggregatingStep creates the adaptive aggregation session only for parallel aggregation, so every single-stream numbers() fixture missed the route entirely. With more than one stream and no SETTINGS clause at all, sumKahanIf returns 400 where the answer is 100, and an in-kernel counter saw 46 of 62 entries with a non-zero offset, at the predicted slice boundaries. The description now lists three carriers and scopes this one to 26.8 onward, where enable_adaptive_aggregator exists.
💡 The src/ grep count quoted in the description was the post-fix count, so a reader running it on master gets one fewer line. Fixed: eight on master.

Not changed, with reasons:

Point Verdict
⚠️ Also pin max_threads, max_block_size, index granularity and the parallel-replica settings, and assert the exact EXPLAIN PIPELINE output. Disagreed on scope. The in-order arm was measured reddening the unfixed build at max_threads 1, 2 and 3. max_block_size randomizes no lower than 8000, while the counter it feeds counts keys, so a four-key fixture cannot reach it. No measurement implicates granularity or parallel replicas. Only the one setting shown to disarm the arm is pinned, and the pipeline assertion is a substring check rather than a full-output comparison.
💡 No test arm covers the parallel GROUP BY carrier. Deliberate. It reaches the same kernel call with the same non-zero offset as the in-order arm, so only the producer of the offset differs, and reverting the one fixed statement reddens all three existing arms on a disjoint set of reference lines.

@clickhouse-gh clickhouse-gh Bot closed this Aug 29, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Aug 29, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a84e396]

Summary: ❌

job_name test_name status info comment
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py FAIL IGNORED
Bugfix validation (functional tests, amd64) ERROR IGNORED
Bugfix validation (functional tests, aarch64) ERROR IGNORED

AI Review

Summary

This PR fixes the missing condition_map += start in AggregateFunctionSumKahanData::addManyConditionalInternal, which is the correct scope for the wrong-results bug, and the added 05048 regression test now covers the direct -If path, the plain Nullable path, the two Nullable flag-map carriers raised in the earlier review thread, and the in-order GROUP BY path. I did not find any remaining correctness, coverage, or PR-metadata issues in the current diff.

Final Verdict

✅ No new findings.

LLVM Coverage Report

Measured on commit a84e396.

Metric Baseline Current Δ
Lines 88.60% 88.60% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 80.90% 80.90% +0.00%

Changed lines: Changed C/C++ lines covered: 5/5 (100.00%) · 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 29, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. 100% on the first run, no randomization and no settings needed. clickhouse-test on a base-build server: 0 passed, 20 failed, the runner stopping at its own --max-failures-chain limit (20).
b Root cause explained? Yes. The prologue of AggregateFunctionSumKahanData::addManyConditionalInternal advances ptr by start but not condition_map, and the loop then walks the map relatively, so values are read from index start while flags are read from index 0: row start + i is tested against flag i.
c Fix matches root cause? Yes. It restores the function's postcondition, that both per-row pointers address row start, at the layer that is broken. No widened bound, no tag, no data reduction, no defensive guard. The sibling copy of the same interface received the identical line in 0754ee49016bf64.
d Test intent preserved / new tests added? Yes. No existing test weakened or removed. New SQL stateless test with 3 arms, one per distinct code path, each reddening its own disjoint set of reference lines. A sumIf control column pins both copies of the kernel, and a pipeline assertion proves the in-order arm is genuinely armed rather than silently falling back to hash aggregation (it reads 0 under optimize_aggregation_in_order = 0).
e Both directions demonstrated? Yes, per arm. Fix binary 50 passed / 0 failed; base binary 0 passed / 20 failed. The control column is byte-identical between the two binaries in every arm, so the oracle measures only the changed path.
f Fix is general across code paths? Yes. Fixed inside the kernel, so both entry points (addManyNotNull, addManyConditional) and all three call sites (:495, :522, :526) are repaired at once; :522, which no arm covers, was measured separately. Three greps plus a negative control show this was the only site in src/ advancing a value pointer without its map.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes. Both template instantiations are exercised (add_if_zero true in the null-map arm, false in the two -If arms). Nullable and -If are the wrappers that select an entry point and both have arms; -Array and -ForEach were measured to route through the same kernel; Decimal sumKahan was measured identical on both binaries, since it uses the generic sum data. Boundaries covered: start 0 (unchanged), 1, 2, 3, 32, 64, 96, and an empty frame.
h Backward compatible? (maintainer-approved exception only) Yes, and deliberately behaviour-changing. No setting added or re-defaulted, so no SettingsChangesHistory.cpp entry; no serialization or format change. Queries whose results silently depended on the misindexed flags do change answer, because the old answer was wrong. Gating a wrong-results fix behind an opt-in setting would not be a fix.
i Invariants and contracts preserved? Yes. The change strengthens the prologue's postcondition and touches nothing else: no allocation, ownership, lifetime, lock, error path or early return in the function. Both maps are always at least row_end long, so the pre-fix read was in bounds. That is why this is wrong results only, and why the category is Bug Fix rather than Critical Bug Fix.

Session id: cron:clickhouse-impl-self-slot-57:20260829-004700

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @alexey-milovidov @nickitat, could you review this? AggregateFunctionSumKahanData::addManyConditionalInternal advances its value pointer by the batch start but never the flag map, so sumKahanIf and sumKahan over Nullable test row start + i against flag i and return silently wrong sums. The generic copy of the same interface got this identical one-line fix in 0754ee49016bf64, and non-zero starts reach it at stock defaults from window frames and from the adaptive aggregator slicing a threshold-crossing block.

@clickhouse-gh

clickhouse-gh Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing a84e3961d with master 6f9bea0cd (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

10 translation units recompiled, 48 s compile time in total, 10 of them have a recent master baseline.

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 8b8cd0d

Every failure below has an owner.

Check / test Reason Owner / fixing PR
Integration tests (amd_asan_ubsan, db disk, old analyzer, 6/6) host memory pressure: pytest was SIGKILLed (exit code: -9) at 72% of the batch, peak RAM 99.7% of 61.78 GB with 490 s of memory stall, under --cgroupns=host. praktika could not attribute it (Unknown error (exit status: None)), so the shard published 887 rows and no failing leaf #112984 (ours, open)
Stateless tests (amd_debug, parallel) / 03008_optimize_equal_ranges CANNOT_SCHEDULE_TASK (threads=2, jobs=2) thrown by scheduleOrThrow in MergeTreeDataSelectExecutor::filterPartsByPrimaryKeyAndSkipIndexes, on the test's own system.query_log query. The duplicate run of this same commit passed this job, and the built-in diagnosis re-ran the test 138 times with 0 failures #116822 (ours, open)

Finish Workflow / Post Hooks is the praktika aggregator and carries no separate defect: its only failing hook is new_tests_check.py, reporting passed: none because all five Bugfix validation (*) jobs set_run_after the core blocking jobs, which include the amd_asan_ubsan, db disk, old analyzer shards (ci/workflows/pull_request.py). The errored 6/6 shard dropped them, so the hook had no per-arch verdict to read. Nothing here is caused by this PR's diff (src/AggregateFunctions/AggregateFunctionSum.h plus its own new test).

Two concurrent PR workflow runs exist at this commit (33227736899, 33227741684), so the set above is the union of both runs' per-run check-runs rather than the workflow rollup, which reports only one run.

Session id: cron:our-pr-ci-monitor:20260829-053000

@groeneai

Copy link
Copy Markdown
Collaborator Author

Fixing PR for the new_tests_check.py Post Hooks failure: #117038.

To be plain about what it does and does not do: it fixes the misreporting only. The hook was
asserting a cause it never measured ("the test either passes on master HEAD on every arch ... or
every arch errored out"); it now prints the per-arch state it already held, one line per job with
the status and the reason that job recorded. The merge gate itself is unchanged, so this red is
still a red - whether a validator that never ran should block a bug-fix PR at all is a policy
question put to CI owners in that PR.

@Algunenano Algunenano self-assigned this Aug 31, 2026
@Algunenano Algunenano added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Aug 31, 2026
The test pinned the direct `if` flags path and the plain null map path, but not
the two wrappers that build a flag map for a Nullable argument, so one of the
carriers named in the description stayed untested. Two arms are added over the
same window frame:

`sumKahanIf(Nullable(Float64), UInt8)` reaches AggregateFunctionIfNullUnary,
which merges the null map and the filter into a single map
(Combinators/AggregateFunctionIf.cpp:176-183) before calling
addBatchSinglePlaceNotNull, hence addManyNotNull.

`sumKahanIf(Float64, Nullable(UInt8))` has a non-Nullable first argument, so it
routes to AggregateFunctionIfNullVariadic instead, which builds its own map in
the same file (:323-347).

Both maps are sized for row_end and filled from row_begin, so the unfixed kernel
reads them from index 0 and the divergence is a wrong value rather than an
empty-frame artifact. In each arm the null map and the filter disagree on some
rows, so the merge itself is exercised.

Measured on this tree, debug build, test 05048 only: 50 OK / 0 FAIL with the fix.
Against a server built from pristine master 38a9ca2 the runner stops at
its own --max-failures-chain limit with 0 OK / 20 FAIL, and the two new arms
account for four of the differing lines (3 1 1 -> 3 1 2, 4 1 1 -> 4 1 3,
1 1 1 -> 1 1 0, 2 2 2 -> 2 2 0).
@groeneai

groeneai commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - a84e396

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Bugfix validation (functional tests, amd64) functional_tests.py:734 assert build_urls, "Could not find master builds in S3" - the master-build S3 lookup missed the new artifact prefix, so the check could not run at all #117580 (external, merged 2026-09-01T22:06:23Z), absent from this build (rule 3c)
Bugfix validation (functional tests, aarch64) same assertion, sibling arch #117580 (external, merged 2026-09-01T22:06:23Z), absent from this build (rule 3c)
Finish Workflow / new_tests_check.py downstream of the two rows above: the hook reports Bugfix validation as seen by this check: ... ERROR and fails on it #117580 (external, merged 2026-09-01T22:06:23Z), absent from this build (rule 3c)

All three rows are one cause. #117580 changes find_master_builds in
ci/jobs/scripts/bugfix_validation.py, which functional_tests.py consumes, and the post hook
fails only because it reads the two Bugfix legs' ERROR. Fix-presence probed at the failing tree
rather than inferred from timing: pre-fix 695469d13cd1 = 0, at the fix 41b739a45086 = 1, this
head a84e3961ddf7 = 0. The run was created at 18:38:46Z, before the 22:06:23Z merge.

Mergeable Check reports Failed: Workflow Post Hook, so the post hook is the only gating row,
and master already carries its fix - a master sync or a re-run should clear all three together.

I have not pushed a master merge myself: @ Algunenano is driving this branch (the master merge at
13a9d14a94e2 is his) and every push here costs him another workflow approval, so the sync is
his call rather than mine.

Session id: cron:our-pr-ci-monitor:20260902-013000

@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 2, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 2, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 2, 2026
Backport #116990 to 26.6: Fix wrong results from `sumKahanIf` and `sumKahan` over `Nullable` when the aggregated batch does not start at row 0
Algunenano added a commit that referenced this pull request Sep 2, 2026
Backport #116990 to 26.3: Fix wrong results from `sumKahanIf` and `sumKahan` over `Nullable` when the aggregated batch does not start at row 0
clickhouse-gh Bot added a commit that referenced this pull request Sep 2, 2026
Backport #116990 to 26.8: Fix wrong results from `sumKahanIf` and `sumKahan` over `Nullable` when the aggregated batch does not start at row 0
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 2, 2026
…mKahan` over `Nullable` when the aggregated batch does not start at row 0
clickhouse-gh Bot added a commit that referenced this pull request Sep 2, 2026
Backport #116990 to 26.7: Fix wrong results from `sumKahanIf` and `sumKahan` over `Nullable` when the aggregated batch does not start at row 0
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 4, 2026
…f` and `sumKahan` over `Nullable` when the aggregated batch does not start at row 0
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 4, 2026
…f` and `sumKahan` over `Nullable` when the aggregated batch does not start at row 0
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 4, 2026
…f` and `sumKahan` over `Nullable` when the aggregated batch does not start at row 0
pull Bot pushed a commit to infdahai/ClickHouse that referenced this pull request Sep 9, 2026
…egation

`AggregateFunctionSum::addBatchSinglePlaceNotNull` and
`AggregateFunctionAvg::addBatchSinglePlaceNotNull` merge the null map and the
`-If` condition into a temporary flag buffer built with
`std::make_unique<UInt8[]>(row_end)`. The array form of `std::make_unique`
value-initializes, and `row_end` is the absolute end row of the sub-range rather
than the size of the written span, so a caller that walks one block in
increasing sub-ranges zeroes about N*(g+1)/2 bytes per block of N rows cut into
g intervals, while only `[row_begin, row_end)` is ever written or read.

Two callers do that: aggregation in order, which calls the entry point once per
sorting-key interval, and window frames, whose `rows_to_add_start` is
monotonically non-decreasing inside a block and which need no setting at all to
reach this code.

Size the buffer to the written span with `std::make_unique_for_overwrite`,
rebase the destination index, and pass the value pointer offset by `row_begin`
with `start = 0`. Both kernels already do `ptr += start; condition_map += start;
count = end - start`, so the pointers and the count handed to the accumulation
loop are byte-identical and no floating-point re-association is possible. On the
`sumKahan` instantiation this holds because ClickHouse#116990 added the missing
`condition_map += start`.

Measured on a 10M row table with 8 row groups, median of 15 interleaved runs:
`sumIfOrDefault` 558 ms to 287 ms, `avgIfOrDefault` 563 ms to 295 ms, and a
window frame 82 ms to 31 ms. Six shapes that do not reach this code stay within
1.3%, and `SelectedRows`, `ReadCompressedBytes` and `ArenaAllocBytes` are
unchanged. Correctness was checked over 320 spelling, type and producer
combinations, all byte-equal, with three mutants of this change breaking 105
each.

Reachability is wider than the report states: `sumIf` with a non-nullable value
and a `Nullable` condition reaches the site through the variadic branch of
`AggregateFunctionIf::getOwnNullAdapter` with no extra combinator, while
`sumIfOrNull` does not, because both analyzers rewrite that name to
`sumOrNullIf`. On the former shape the null map itself is built by a second
block-sized buffer in `AggregateFunctionIfNullVariadic::addBatchSinglePlace`,
tracked separately by ClickHouse#117511, so this change removes one of two equal buffers
there.

Analysis and patch by @ snelheidai in ClickHouse#117947.

Co-Authored-By: Claude Opus 5 <[email protected]>
bytehalo-infra added a commit to sentioxyz/ClickHouse that referenced this pull request Sep 25, 2026
AGG: sumKahan/sumKahanIf/Nullable when a batch does not start at row 0 (window frames, parallel GROUP BY) -> wrong (silent).
Effect in the production build a394e92: wrong/failing (the upstream test fails on it and passes on official 26.8.8.8; evidence/fix_ci_20260925/upstream_repro/residual/116990.PROD263.txt).
Upstream patch unchanged, with its test(s): 05048_sum_kahan_conditional_row_offset.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors groeneai-origin-self PR origin: self-found defect (impact-bar validated) pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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.

5 participants