Skip to content

Fix ColumnConst not materialized before squashing - #97019

Merged
alexey-milovidov merged 5 commits into
ClickHouse:masterfrom
hasyimibhar:fix-95537
Feb 23, 2026
Merged

alexey-milovidov merged 5 commits into
ClickHouse:masterfrom
hasyimibhar:fix-95537

Conversation

@hasyimibhar

@hasyimibhar hasyimibhar commented Feb 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #95537. ColumnConst should be materialized before squashing, otherwise ColumnConst('a', 100) and ColumnConst('b', 90) get squashed to ColumnConst('a', 190). This is what was done before the regression.

Changelog category (leave one):

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

Changelog entry (a [user-readable short description]

Fix ColumnConst not materialized before squashing

Version info

  • Merged into: 26.2.1.1084
  • Backported to: 26.1.4.17, 25.12.7.18, 25.11.10.19

Comment thread src/Interpreters/Squashing.cpp Resolved
Comment thread src/Interpreters/Squashing.cpp Resolved
Comment thread src/Interpreters/Squashing.cpp Outdated
/// since `IColumn::isSparse` is not recursive but sparse column can be inside a tuple, for example.
have_same_serialization[j] &= columns[j]->structureEquals(*mutable_columns[j]);

/// ColumnConst can have different values, only squash if different value

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.

Not squashing is not the right solution. The right solution is materializing constants.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok I updated to just materializing ColumnConst.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looks like before this, the materialize happens outside of squashing, and removing the materialize introduce this bug: 3acbbe7

@alexey-milovidov alexey-milovidov added the close in a month if not active This will be closed in case of no information label Feb 15, 2026
@hasyimibhar hasyimibhar changed the title Fix ColumnConst with different values squashed Fix ColumnConst not materialized when squashing Feb 15, 2026
@hasyimibhar hasyimibhar changed the title Fix ColumnConst not materialized when squashing Fix ColumnConst not materialized before squashing Feb 15, 2026
@alexey-milovidov alexey-milovidov removed the close in a month if not active This will be closed in case of no information label Feb 15, 2026
Comment thread src/Interpreters/Squashing.cpp Outdated
/// ignores the source value and just increments the row count
if (isColumnConst(*mutable_columns[i]))
{
mutable_columns[i] = mutable_columns[i]->convertToFullColumnIfConst()->assumeMutable();

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.

assumeMutable() is error-prone, use std::move(...->mutate()) - see examples in the code.

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 mutable_columns be already materialized here?

@hasyimibhar hasyimibhar Feb 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

assumeMutable() is error-prone, use std::move(...->mutate()) - see examples in the code.

I changed it to IColumn::mutate similar to this (I also changed the line below, I was following it):

result_columns.push_back(IColumn::mutate(castColumnAccurate(col, out_sample_col.type)));

Shouldn't mutable_columns be already materialized here?

No, if I remove this line, the test fails.

@Fgrtue Fgrtue self-assigned this Feb 19, 2026
@Fgrtue Fgrtue added can be tested Allows running workflows for external contributors labels Feb 19, 2026
@clickhouse-gh

clickhouse-gh Bot commented Feb 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f7ea608]

Summary: ✅

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Feb 19, 2026
Comment thread src/Interpreters/Squashing.cpp Outdated
for (auto & column : source_columns_list[i])
column = column->convertToFullColumnIfConst();
}
else if (!have_same_serialization[i])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wanted to suggest to change else if to a separate if. Since logically, the conditions isColumnConst and !have_same_serialization do not exclude each other.

Comment on lines +24 to +30
SELECT s, x FROM a LEFT JOIN numbers(30) num1 ON a.x = num1.number
UNION ALL
SELECT s, x FROM b LEFT JOIN numbers(10) num2 ON b.x = num2.number
UNION ALL
SELECT s, x FROM c LEFT JOIN numbers(20) num3 ON c.x = num3.number
UNION ALL
SELECT s, x FROM d LEFT JOIN numbers(15) num4 ON d.x = num4.number;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's change LEFT JOIN to JOIN here, so that we also test a different semantic.

@hasyimibhar

Copy link
Copy Markdown
Contributor Author

Are these failures related to my change?

@Fgrtue

Fgrtue commented Feb 19, 2026

Copy link
Copy Markdown
Contributor

I don't think so. They used to fail a few days ago, but were fixed recently. Please try merging with master so that the most recent updates are added to your branch.

Comment thread src/Interpreters/Squashing.cpp Resolved
@hasyimibhar
hasyimibhar requested review from Fgrtue and azat February 22, 2026 09:55
@clickhouse-gh clickhouse-gh Bot removed the pr-bugfix Pull request with bugfix, not backported by default label Feb 22, 2026
@clickhouse-gh clickhouse-gh Bot added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Feb 22, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

We need help from @Fgrtue to understand why we can have constants with different values, why the materialization outside of squashing no longer works, and to fix the root cause.

@Fgrtue

Fgrtue commented Feb 23, 2026

Copy link
Copy Markdown
Contributor

Right, in order restate the roots of the issue, here is the summary:

  1. The issue appears first in 25.6 https://fiddle.clickhouse.com/e7292795-f3fc-4af9-9275-e605fecf263c
  2. It is likely that the key changes, that influenced the error happened when we tuned the way that we deal with constants in squashing Fix "Too large size passed to allocator" UB in JOIN due to mixed const and non-const blocks #87231
  3. This pull request materializes the constants inside squashing in a different way than it was done before, so it should fix the issue

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Feb 23, 2026
Merged via the queue into ClickHouse:master with commit bda22f8 Feb 23, 2026
144 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Feb 23, 2026
@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Feb 23, 2026
clickhouse-gh Bot added a commit that referenced this pull request Feb 23, 2026
Backport #97019 to 26.1: Fix ColumnConst not materialized before squashing
clickhouse-gh Bot added a commit that referenced this pull request Feb 23, 2026
Backport #97019 to 25.11: Fix ColumnConst not materialized before squashing
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Feb 24, 2026
clickhouse-gh Bot added a commit that referenced this pull request Feb 24, 2026
Backport #97019 to 25.12: Fix ColumnConst not materialized before squashing
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 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.

INSERT SELECT with UNION ALL and JOIN writes incorrect String values in MergeTree

6 participants