Skip to content

Fix LOGICAL_ERROR in case of Sparse column in INSERT block pushed to non-MT MV#81161

Merged
azat merged 1 commit intoClickHouse:masterfrom
azat:fix-sparse-columns-for-mv
Jun 3, 2025
Merged

Fix LOGICAL_ERROR in case of Sparse column in INSERT block pushed to non-MT MV#81161
azat merged 1 commit intoClickHouse:masterfrom
azat:fix-sparse-columns-for-mv

Conversation

@azat
Copy link
Copy Markdown
Member

@azat azat commented Jun 2, 2025

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 to CHANGELOG.md):

Fix LOGICAL_ERROR in case of Sparse column in INSERT block pushed to non-MT MV

Previously the following:

create table sparse (key String) engine=MergeTree order by () settings ratio_of_defaults_for_sparse_serialization=0.01;
insert into sparse select ''::String from numbers(100);
create table intermediate (key String) engine=MergeTree order by ();
create table log (key String) engine=Log;
create table log_remote as remote('127.1', currentDatabase(), log);
create materialized view mv_log to log as select * from intermediate;
insert into intermediate select * from sparse;

Lead to:

Code: 49. DB::Exception: Received from localhost:9000. DB::Exception: Bad cast from type DB::ColumnSparse to DB::ColumnString: while pushing to view test_y52fdreq.mv_log. (LOGICAL_ERROR)

The reason is that supportsSparseSerialization() is done only for the destination INSERT table, but not to all the tables that are pushed to via materialized views.

Introduce separate transform that will only remove sparseness, and apply it for each table, including tables that are pushed via MVs.

@azat azat requested review from CheSema and CurtizJ June 2, 2025 14:09
@clickhouse-gh
Copy link
Copy Markdown
Contributor

clickhouse-gh bot commented Jun 2, 2025

Workflow [PR], commit [1356f23]

@clickhouse-gh clickhouse-gh bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 2, 2025
@azat azat force-pushed the fix-sparse-columns-for-mv branch 2 times, most recently from 2fd63a5 to 9710b47 Compare June 2, 2025 21:20
…non-MT MV

Previosly the following:

    create table sparse (key String) engine=MergeTree order by () settings ratio_of_defaults_for_sparse_serialization=0.01;
    insert into sparse select ''::String from numbers(100);
    create table intermediate (key String) engine=MergeTree order by ();
    create table log (key String) engine=Log;
    create table log_remote as remote('127.1', currentDatabase(), log);
    create materialized view mv_log to log as select * from intermediate;
    insert into intermediate select * from sparse;

Lead to:

    Code: 49. DB::Exception: Received from localhost:9000. DB::Exception: Bad cast from type DB::ColumnSparse to DB::ColumnString: while pushing to view test_y52fdreq.mv_log. (LOGICAL_ERROR)

The reason is that supportsSparseSerialization() is done only for
the destination INSERT table, but not to all the tables that are pushed
to via materialized views.

Introduce separate transform that will only remove sparseness, and apply
it for each table, including tables that are pushed via MVs.
@azat azat force-pushed the fix-sparse-columns-for-mv branch from 9710b47 to 1356f23 Compare June 3, 2025 05:28
@azat azat requested a review from CheSema June 3, 2025 09:33
@azat azat enabled auto-merge June 3, 2025 10:24
@azat azat added this pull request to the merge queue Jun 3, 2025
Merged via the queue into ClickHouse:master with commit 16be046 Jun 3, 2025
120 checks passed
@azat azat deleted the fix-sparse-columns-for-mv branch June 3, 2025 10:39
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 3, 2025
azat added a commit to azat/ClickHouse that referenced this pull request Aug 26, 2025
Squashing cannot work with different const and non-const blocks, but ClickHouse#81161
removed `MaterializingTransform` before squashing, and so it may lead to
crash or "Too large size (18446462643291305296) passed to allocator. It
indicates an error." error.
azat added a commit to azat/ClickHouse that referenced this pull request Aug 26, 2025
Squashing cannot work with different const and non-const blocks, but ClickHouse#81161
removed `MaterializingTransform` before squashing, and so it may lead to
crash or "Too large size (18446462643291305296) passed to allocator. It
indicates an error." error.
azat added a commit to azat/ClickHouse that referenced this pull request Aug 26, 2025
Squashing cannot work with different const and non-const blocks, but ClickHouse#81161
removed `MaterializingTransform` before squashing, and so it may lead to
crash or "Too large size (18446462643291305296) passed to allocator. It
indicates an error." error.
azat added a commit to azat/ClickHouse that referenced this pull request Aug 26, 2025
Squashing cannot work with different const and non-const blocks, but ClickHouse#81161
removed `MaterializingTransform` before squashing, and so it may lead to
crash or "Too large size (18446462643291305296) passed to allocator. It
indicates an error." error.
azat added a commit to azat/ClickHouse that referenced this pull request Aug 27, 2025
Squashing cannot work with different const and non-const blocks, but ClickHouse#81161
removed `MaterializingTransform` before squashing, and so it may lead to
crash or "Too large size (18446462643291305296) passed to allocator. It
indicates an error." error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default 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.

3 participants