Skip to content

Make ColumnAggregateFunction::expand exception-safe - #131733

Merged
alexey-milovidov merged 2 commits into
masterfrom
fix-column-aggregate-function-expand-exception-safety
Nov 17, 2026
Merged

alexey-milovidov merged 2 commits into
masterfrom
fix-column-aggregate-function-expand-exception-safety

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

expand (used by the short-circuit evaluation of functions like if) resized data first and then created the states of the new rows one by one. If creating a state threw (for example, on a memory limit), the column held pointers to states that were never created, and its destructor destroyed them, which crashed the server. Build the expanded array aside, destroy the states created so far on exception, and publish it only when it is complete.

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

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

Fix a possible crash when an exception (for example, a memory limit) is thrown during the short-circuit evaluation of a function returning an AggregateFunction state.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.2517-master (included in 26.11 and later)
  • Backported to: 26.10.5.48, 26.9.31.13, 26.8.39.12, 26.3.66.9

`expand` (used by the short-circuit evaluation of functions like `if`) resized `data` first and then created the states of the new rows one by one. If creating a state threw (for example, on a memory limit), the column held pointers to states that were never created, and its destructor destroyed them, which crashed the server. Build the expanded array aside, destroy the states created so far on exception, and publish it only when it is complete.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov alexey-milovidov self-assigned this Nov 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d459ebb]

Summary: ✅


AI Review

Summary

ColumnAggregateFunction::expand now validates mask cardinality before expanding, preserves existing states until the replacement array is complete, and destroys successfully created padding states on exception. The deterministic failpoint test addresses the previous regression-coverage finding. Review of PR head d459ebb236b77aadc2de9f91c7e90f9639a83aa0 found no remaining actionable issues.

Final Verdict

✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Nov 15, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-data-types Type system & core datatypes used across query planning/execution. label Nov 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing d459ebb23 with master f0ee6ba9f (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

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

Job report

The previous test relied on `memory_tracker_fault_probability` hitting the
`Arena` growth inside the state-creation loop, which almost never happens for
`groupArray` states, so it passed on unfixed builds too. Add the
`column_aggregate_function_expand_exception` failpoint that throws right after
`expand` creates a missing state, and use it in the test to assert the
expected exception and that the server stays alive.

Address review: #131733 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@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 Nov 16, 2026
Merged via the queue into master with commit 5836204 Nov 17, 2026
192 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-column-aggregate-function-expand-exception-safety branch November 17, 2026 02:57
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 17, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 17, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 17, 2026
Backport #131733 to 26.10: Make `ColumnAggregateFunction::expand` exception-safe
clickhouse-gh Bot added a commit that referenced this pull request Nov 17, 2026
Backport #131733 to 26.9: Make `ColumnAggregateFunction::expand` exception-safe
clickhouse-gh Bot added a commit that referenced this pull request Nov 17, 2026
Backport #131733 to 26.8: Make `ColumnAggregateFunction::expand` exception-safe
alexey-milovidov added a commit that referenced this pull request Nov 17, 2026
Resolve the conflict in `src/Common/FailPoint.cpp`: keep only the
`column_aggregate_function_expand_exception` failpoint added by #131733;
the other failpoints from the master side do not exist on 26.3.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robot-ch-test-poll3 added a commit that referenced this pull request Nov 17, 2026
Cherry pick #131733 to 26.3: Make `ColumnAggregateFunction::expand` exception-safe
robot-clickhouse added a commit that referenced this pull request Nov 17, 2026
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 17, 2026
PedroTadim added a commit that referenced this pull request Nov 17, 2026
Backport #131733 to 26.3: Make `ColumnAggregateFunction::expand` exception-safe
mkmkme pushed a commit to Altinity/ClickHouse that referenced this pull request Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-data-types Type system & core datatypes used across query planning/execution. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix 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.

4 participants