Skip to content

Fix segfault with sparse values in NULL - #91738

Closed
yariks5s wants to merge 9 commits into
masterfrom
yarik/fix-null-segfault-logical-error
Closed

yariks5s wants to merge 9 commits into
masterfrom
yarik/fix-null-segfault-logical-error

Conversation

@yariks5s

@yariks5s yariks5s commented Dec 8, 2025 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

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

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

Fixes a segfault in case of count distinct nullable sparse columns.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

@clickhouse-gh

clickhouse-gh Bot commented Dec 8, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d0e103b]

Summary: ❌

job_name test_name status info comment
Fast test error
Build (amd_debug) dropped
Build (amd_asan) dropped
Build (amd_tsan) dropped
Build (amd_msan) dropped
Build (amd_ubsan) dropped
Build (amd_binary) dropped
Build (arm_asan) dropped
Build (arm_binary) dropped
Build (arm_tsan) dropped

@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 Dec 8, 2025
@yariks5s

yariks5s commented Dec 8, 2025 •

Copy link
Copy Markdown
Member Author

A crash occurs in AggregateFunctionNull when working with sparse columns of the Nullable type.

When the type of the column is Nullable, the code was relying on the idea that all columns will be wrapped with ColumnNullable.

But this is not always true. When we work with sparse columns, if ALL non-default values (that we store separately) are not NULL, then we may not get columns wrapped in ColumnNullable.

So, in the test,

  • CTE creates key2 with Nullable(String) type through CASE WHEN, it was read as sparse due to the setting
  • During LEFT JOIN we pass that sparse column, but we don't have any NULL values
  • count(distinct cte.key2) calls the Null function in the code
  • In Null function we expected columns to be wrapped in ColumnNullable

@yariks5s
yariks5s marked this pull request as draft December 8, 2025 19:21
@yariks5s
yariks5s marked this pull request as ready for review December 9, 2025 12:55
@Algunenano

Copy link
Copy Markdown
Member

Note that a) this feature was introduced in the current development and not released so no need to backport and b) I'm reverting it in #88999

@yariks5s yariks5s removed the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Dec 11, 2025
@pamarcos

Copy link
Copy Markdown
Member

@yariks5s is this still needed even after #91932 is merged?

@yariks5s

Copy link
Copy Markdown
Member Author

@yariks5s is this still needed even after #91932 is merged?

I will download the latest master and check if the bug is fixed

@yariks5s

Copy link
Copy Markdown
Member Author

@pamarcos still fails for me :(, I will merge with master to re-trigger the CI and to double-validate with bugfix check.

@Algunenano

Copy link
Copy Markdown
Member

@amosbird Here's another bug related to sparse nullable columns

@Algunenano Algunenano added pr-not-for-changelog This PR should not be mentioned in the changelog and removed pr-critical-bugfix labels Dec 12, 2025
@amosbird

Copy link
Copy Markdown
Collaborator

Yeah, this looks like another valid fix. Thanks!

@yariks5s

Copy link
Copy Markdown
Member Author

FYI this bug is not related to #88999 because it was found in 25.8

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! and removed pr-not-for-changelog This PR should not be mentioned in the changelog labels Dec 12, 2025
OPTIMIZE TABLE t2 FINAL;

WITH cte AS (
SELECT id, max(CASE WHEN value != '' THEN value END) as b

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So these create Nullable column, right? And later we do not add Nullable wrapper for b from some table? But, shouldn't we have have implicit CAST for these? I think we should, then why it is not enough?

@azat azat self-assigned this Dec 29, 2025
@@ -0,0 +1,46 @@
-- There were crashes in AggregateFunctionNullUnary when column type is Nullable
-- but actual column is not wrapped in ColumnNullable (e.g. sparse column values)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's also include your explanation for the test - #91738 (comment)

-- There were crashes in AggregateFunctionNullUnary when column type is Nullable
-- but actual column is not wrapped in ColumnNullable (e.g. sparse column values)

SET enable_analyzer=1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't it fail w/o analyzer as well?

@yariks5s
yariks5s requested a review from vdimir January 22, 2026 18:34
@yariks5s

yariks5s commented Feb 5, 2026

Copy link
Copy Markdown
Member Author

Already fixed in #95157.

@yariks5s yariks5s closed this Feb 5, 2026
@yariks5s
yariks5s deleted the yarik/fix-null-segfault-logical-error branch February 5, 2026 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants