Skip to content

Fix projection rewrite collapsing groups when WHERE and GROUP BY share a column - #106590

Merged
KochetovNicolai merged 5 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-issue-106573-projection-filter-column-data-corruption
Jun 17, 2026
Merged

KochetovNicolai merged 5 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-issue-106573-projection-filter-column-data-corruption

Conversation

@groeneai

@groeneai groeneai commented Jun 5, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #106573

A SELECT c, count() FROM t WHERE c GROUP BY c query against a MergeTree table with the implicit _minmax_count_projection, an explicit aggregate projection, or a normal projection returned wrong results: every group collapsed into a single row whose key was a constant and whose count() was the total number of matching rows.

QueryDAG::findInOutputs in projectionsCommon.cpp replaced a filter column output with a ColumnConst of value 1 when the filter column survived FilterStep (remove_filter_column == false). The substitution assumes that, post-filter, every surviving row of the filter expression equals 1, which holds when the filter expression is a derived boolean like c > 5 but is wrong when the filter expression is the column itself. In WHERE c GROUP BY c the filter expression IS the column, so the constant substitution destroyed the data column that GROUP BY and the SELECT list reference under the same result_name. Projection rewrite then folded the GROUP BY key into a ColumnConst, and AggregatingStep collapsed every group into one.

Drop the constant substitution. The original boolean filter expression is still returned by findInOutputs and QueryDAG::build wraps it as a separate _projection_filter alias prepended to the dag outputs, so the filter remains correctly attached. The bug affects all three projection rewrite paths (row-level filter, prewhere, regular filter); the regression test exercises _minmax_count_projection, an explicit aggregate projection, and a normal projection.

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 for SELECT c, count() FROM t WHERE c GROUP BY c against tables with the implicit _minmax_count_projection, an explicit aggregate projection, or a normal projection: every group used to collapse into one row with a constant key and the total row count.

Documentation entry for user-facing changes

  • Documentation is unnecessary -- this is a correctness fix, no user-facing API change.

Version info

  • Merged into: 26.6.1.927

…e a column

Closes: ClickHouse#106573

A `SELECT c, count() FROM t WHERE c GROUP BY c` query against a `MergeTree`
table that has the implicit `_minmax_count_projection`, an explicit aggregate
projection, or a normal projection returned wrong results: every group
collapsed into a single row whose key was a constant and whose `count()` was
the total number of matching rows.

`QueryDAG::findInOutputs` in `projectionsCommon.cpp` replaces a filter
column output with a `ColumnConst` of value `1` when the filter column
survives `FilterStep` (`remove_filter_column == false`). The substitution
assumes that, post-filter, every surviving row of the filter expression
equals `1` -- which is true when the filter expression is a derived boolean
like `c > 5`, but wrong when the filter expression is the column itself.
In `WHERE c GROUP BY c` the filter expression IS the column `c`; post-filter
it still carries the actual data values (`1`, `2`, ...) and is also the
data column referenced by `GROUP BY` and the `SELECT` list under the same
`result_name` (`__table1.c`).

With the substitution, projection rewrite later folded the `GROUP BY` key
into a `ColumnConst(UInt8)` -- visible in `EXPLAIN actions=1` as
`COLUMN Const(UInt8) -> __table1.c UInt8` inside the `FilterStep` actions --
so `AggregatingStep` saw all input rows under one constant key value and
produced one collapsed row per query.

Drop the constant substitution. The original boolean filter expression is
still returned by `findInOutputs`, and `QueryDAG::build` already wraps it
as a separate `_projection_filter` alias prepended to the dag outputs, so
the filter remains correctly attached to the rewritten plan. Skipping the
substitution leaves the output as the data column it actually represents.
The cost is at most a recomputation of the boolean expression in
`optimizeUseNormalProjection`, which is cheap; correctness wins.

The bug affects all three projection-rewrite paths in `projectionsCommon.cpp`
(row-level filter, prewhere, regular filter) and reproduces with
`_minmax_count_projection`, an explicit aggregate projection, and a normal
projection. The regression test exercises all three.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

groeneai commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

# Question Answer
a Deterministic repro? Yes. On master HEAD 10c4c792b0fe the minimal reproducer (CREATE TABLE t (c0 UInt8) ENGINE = MergeTree ORDER BY tuple() PARTITION BY c0; INSERT INTO t VALUES (1),(2); SELECT c0, count() FROM t WHERE c0 GROUP BY c0 ORDER BY c0;) returns 1\t2 (one row) every time, instead of 1\t1 and 2\t1. The 5-INSERT case returns 1\t5 instead of 5 rows.
b Root cause explained? Yes. QueryDAG::findInOutputs in src/Processors/QueryPlan/Optimizations/projectionsCommon.cpp replaces a filter column output with a ColumnConst(UInt8, 1) when FilterStep::removesFilterColumn() == false. The substitution assumes that, post-filter, every surviving row of the filter expression equals 1. That holds when the filter expression is a derived boolean (c > 5); it is wrong when the filter expression is the column itself, because the column's actual values (1, 2, ...) are not literally 1 and the same result_name (__table1.c0) is used downstream as the data column. With the substitution, analyzeAggregateProjection produces a projection-rewritten DAG where the GROUP BY key resolves to a ColumnConst, visible in EXPLAIN actions=1 as COLUMN Const(UInt8) -> __table1.c0 UInt8 inside the rewritten FilterStep. AggregatingStep then sees every input row under one constant key and produces one collapsed row.
c Fix matches root cause? Yes. The fix removes the unsound substitution at the source where the corruption is introduced (projectionsCommon.cpp:140-144). It is not a band-aid: we did not disable the projection optimization, did not skip the rewrite for any query shape, and did not widen any assertion. The original boolean filter expression is still returned by findInOutputs and QueryDAG::build already wraps it as a separate _projection_filter alias prepended to the dag outputs (projectionsCommon.cpp:244-248), so the filter stays attached to the rewritten plan.
d Test intent preserved / new tests added? New regression test added: tests/queries/0_stateless/04319_106573_minmax_count_projection_partition_key_group_by.sql. It covers all three projection types affected by the bug (_minmax_count_projection, an explicit aggregate projection, a normal projection) with the WHERE c GROUP BY c shape, plus a baseline cross-check (optimize_use_implicit_projections = 0). The test fails on master without the fix and passes with it. No existing test was relaxed or removed.
e Both directions demonstrated? Yes. Without fix on master HEAD 10c4c792b0fe: 2-partition case returns 1\t2 (collapsed); 5-partition case returns 1\t5; explicit aggregate projection collapses to 1\t2; normal projection returns 1\t100, 1\t200 instead of 1\t100, 2\t200. With fix: every case returns the correct per-group rows, matching the optimize_use_implicit_projections = 0 baseline. The _minmax_count_projection is still selected by the optimizer (verified via EXPLAIN) -- the fix corrects the data, not the plan choice.
f Fix is general, not a narrow patch? Yes. findInOutputs is the shared utility called from all three projection-rewrite filter paths in the same file (row-level filter at line 161, prewhere at line 170, regular filter at line 201), so all three inherit the fix uniformly. The bug class (constant substitution corrupting downstream-used columns under a shared result_name) was confirmed in _minmax_count_projection, an explicit aggregate projection, and a normal projection -- all three are exercised by the regression test. The fix targets the root cause at the substitution site, not a guard at the rewriter call sites.

Session id: cron:clickhouse-ci-task-worker:20260605-163800

@groeneai

groeneai commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator Author

cc @KochetovNicolai @novikd could you review this? It removes an unsound ColumnConst substitution in QueryDAG::findInOutputs that was destroying downstream-used data columns when a filter and a GROUP BY share a column name (WHERE c GROUP BY c), causing all groups to collapse under _minmax_count_projection, explicit aggregate projections, and normal projections.

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Jun 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [82d826c]

Summary: ✅


AI Review

Summary

This PR removes the unsound ColumnConst replacement from QueryDAG::findInOutputs when a filter column survives the FilterStep, preserving the original data column for downstream consumers such as GROUP BY while still adding the separate _projection_filter output used by projection filtering. The fix matches the reported wrong-results contract for _minmax_count_projection and explicit projection rewrites, and the added regression coverage exercises the original collapse plus the surviving non-deterministic filter value. I found no unresolved findings.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 5, 2026
@fm4v

fm4v commented Jun 5, 2026

Copy link
Copy Markdown
Member

@groeneai build check failed

@groeneai

groeneai commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator Author

@fm4v thanks for flagging.

The Build (arm_tidy) failure on this PR is a pre-existing master regression, not caused by #106590.

Evidence

Check Detail
Failing file src/Storages/ObjectStorage/DataLakes/Iceberg/Mutations.cpp:731,733
Error variable 'last_version' is not initialized and variable 'compression_method' is not initialized (cppcoreguidelines-init-variables, -warnings-as-errors)
Files this PR touches src/Processors/QueryPlan/Optimizations/projectionsCommon.cpp and a test under tests/queries/0_stateless/ (the test does not invoke clang-tidy)
Our file in the same build log [14734/16954] Building CXX object src/CMakeFiles/dbms.dir/Processors/QueryPlan/Optimizations/projectionsCommon.cpp.o -> succeeded (cached digest hit)

Source of the regression

PR #106102 (scanhex12/fix_alter_catalog, merged today 2026-06-05 17:43 UTC) refactored Iceberg::alter() and introduced two locally-declared variables that are initialized only inside an if/else body, so clang-tidy cppcoreguidelines-init-variables flags them.

int last_version;                      // line 731
String metadata_path;
CompressionMethod compression_method;  // line 733
if (!catalog) { ... last_version = ...; compression_method = ...; }
else          { ... last_version = ...; compression_method = ...; }

CIDB (last 2 days, Build (arm_tidy) failures): 30+ unrelated PRs hit the same error after PR #106102 merged. Sample:

pull_request_number   head_ref                              cnt
89360                 feature-6476                           5
106404                cursor/fix-distributed-duplicate...    3
103540                totals-by-order-by-combinators         3
106386                untracked-memory-race                  3
106522                native-arrow-ipc-format                2
106120                icolumn-shuffle-primitives             2
105102                groeneai/fix-99495-limit-with-ties...  2
106590                groeneai/fix-issue-106573-...          1

Action

I am filing a separate one-line fix PR against master (initialize last_version = 0 and compression_method = CompressionMethod::None) so this clears for all affected PRs. Once that lands, this PR's arm_tidy will go green on the next rerun.

projectionsCommon.cpp and the regression test are clean. The minmax_count_projection fix itself is unaffected.

Session: cron:clickhouse-ci-task-worker:20260605-222000

alexey-milovidov pushed a commit to evillique/ClickHouse that referenced this pull request Jun 6, 2026
…rg::alter

PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to
declare last_version and compression_method outside an if/else that
assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables
flags the bare declarations and Build (arm_tidy) is built with
-warnings-as-errors, so the build fails for every PR whose CI ran on
master after this commit.

CIDB shows 30+ unrelated PRs hitting this in the last 2 days
(e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102,
ClickHouse#106590).

Initialize both variables to safe defaults at declaration. They are
unconditionally overwritten in both if and else branches before use,
so behavior is unchanged. The new defaults are only relevant if a
future code path skips both assignments, in which case last_version=0
and compression_method=CompressionMethod::None are sane no-op values
(the same defaults the old structured-binding form would produce
through default-construction of the destructured aggregate).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
(cherry picked from commit d72cac5)
alexey-milovidov pushed a commit to jh0x/ClickHouse that referenced this pull request Jun 6, 2026
…rg::alter

PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to
declare last_version and compression_method outside an if/else that
assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables
flags the bare declarations and Build (arm_tidy) is built with
-warnings-as-errors, so the build fails for every PR whose CI ran on
master after this commit.

CIDB shows 30+ unrelated PRs hitting this in the last 2 days
(e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102,
ClickHouse#106590).

Initialize both variables to safe defaults at declaration. They are
unconditionally overwritten in both if and else branches before use,
so behavior is unchanged. The new defaults are only relevant if a
future code path skips both assignments, in which case last_version=0
and compression_method=CompressionMethod::None are sane no-op values
(the same defaults the old structured-binding form would produce
through default-construction of the destructured aggregate).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
(cherry picked from commit d72cac5)
alexey-milovidov pushed a commit to adityachopra29/ClickHouse that referenced this pull request Jun 6, 2026
…rg::alter

PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to
declare last_version and compression_method outside an if/else that
assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables
flags the bare declarations and Build (arm_tidy) is built with
-warnings-as-errors, so the build fails for every PR whose CI ran on
master after this commit.

CIDB shows 30+ unrelated PRs hitting this in the last 2 days
(e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102,
ClickHouse#106590).

Initialize both variables to safe defaults at declaration. They are
unconditionally overwritten in both if and else branches before use,
so behavior is unchanged. The new defaults are only relevant if a
future code path skips both assignments, in which case last_version=0
and compression_method=CompressionMethod::None are sane no-op values
(the same defaults the old structured-binding form would produce
through default-construction of the destructured aggregate).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
(cherry picked from commit d72cac5)
alexey-milovidov pushed a commit to abonander/ClickHouse that referenced this pull request Jun 6, 2026
…rg::alter

PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to
declare last_version and compression_method outside an if/else that
assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables
flags the bare declarations and Build (arm_tidy) is built with
-warnings-as-errors, so the build fails for every PR whose CI ran on
master after this commit.

CIDB shows 30+ unrelated PRs hitting this in the last 2 days
(e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102,
ClickHouse#106590).

Initialize both variables to safe defaults at declaration. They are
unconditionally overwritten in both if and else branches before use,
so behavior is unchanged. The new defaults are only relevant if a
future code path skips both assignments, in which case last_version=0
and compression_method=CompressionMethod::None are sane no-op values
(the same defaults the old structured-binding form would produce
through default-construction of the destructured aggregate).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
(cherry picked from commit d72cac5)
alexey-milovidov pushed a commit to melvynator/ClickHouse that referenced this pull request Jun 6, 2026
…rg::alter

PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to
declare last_version and compression_method outside an if/else that
assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables
flags the bare declarations and Build (arm_tidy) is built with
-warnings-as-errors, so the build fails for every PR whose CI ran on
master after this commit.

CIDB shows 30+ unrelated PRs hitting this in the last 2 days
(e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102,
ClickHouse#106590).

Initialize both variables to safe defaults at declaration. They are
unconditionally overwritten in both if and else branches before use,
so behavior is unchanged. The new defaults are only relevant if a
future code path skips both assignments, in which case last_version=0
and compression_method=CompressionMethod::None are sane no-op values
(the same defaults the old structured-binding form would produce
through default-construction of the destructured aggregate).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
(cherry picked from commit d72cac5)
alexey-milovidov pushed a commit to Onyx2406/ClickHouse that referenced this pull request Jun 6, 2026
…rg::alter

PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to
declare last_version and compression_method outside an if/else that
assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables
flags the bare declarations and Build (arm_tidy) is built with
-warnings-as-errors, so the build fails for every PR whose CI ran on
master after this commit.

CIDB shows 30+ unrelated PRs hitting this in the last 2 days
(e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102,
ClickHouse#106590).

Initialize both variables to safe defaults at declaration. They are
unconditionally overwritten in both if and else branches before use,
so behavior is unchanged. The new defaults are only relevant if a
future code path skips both assignments, in which case last_version=0
and compression_method=CompressionMethod::None are sane no-op values
(the same defaults the old structured-binding form would produce
through default-construction of the destructured aggregate).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
(cherry picked from commit d72cac5)
alexey-milovidov pushed a commit to Onyx2406/ClickHouse that referenced this pull request Jun 6, 2026
…rg::alter

PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to
declare last_version and compression_method outside an if/else that
assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables
flags the bare declarations and Build (arm_tidy) is built with
-warnings-as-errors, so the build fails for every PR whose CI ran on
master after this commit.

CIDB shows 30+ unrelated PRs hitting this in the last 2 days
(e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102,
ClickHouse#106590).

Initialize both variables to safe defaults at declaration. They are
unconditionally overwritten in both if and else branches before use,
so behavior is unchanged. The new defaults are only relevant if a
future code path skips both assignments, in which case last_version=0
and compression_method=CompressionMethod::None are sane no-op values
(the same defaults the old structured-binding form would produce
through default-construction of the destructured aggregate).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
(cherry picked from commit d72cac5)
alexey-milovidov pushed a commit to RinChanNOWWW/ClickHouse that referenced this pull request Jun 6, 2026
…rg::alter

PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to
declare last_version and compression_method outside an if/else that
assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables
flags the bare declarations and Build (arm_tidy) is built with
-warnings-as-errors, so the build fails for every PR whose CI ran on
master after this commit.

CIDB shows 30+ unrelated PRs hitting this in the last 2 days
(e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102,
ClickHouse#106590).

Initialize both variables to safe defaults at declaration. They are
unconditionally overwritten in both if and else branches before use,
so behavior is unchanged. The new defaults are only relevant if a
future code path skips both assignments, in which case last_version=0
and compression_method=CompressionMethod::None are sane no-op values
(the same defaults the old structured-binding form would produce
through default-construction of the destructured aggregate).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
(cherry picked from commit d72cac5)
alexey-milovidov pushed a commit to yurifedoseev/ClickHouse that referenced this pull request Jun 6, 2026
…rg::alter

PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to
declare last_version and compression_method outside an if/else that
assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables
flags the bare declarations and Build (arm_tidy) is built with
-warnings-as-errors, so the build fails for every PR whose CI ran on
master after this commit.

CIDB shows 30+ unrelated PRs hitting this in the last 2 days
(e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102,
ClickHouse#106590).

Initialize both variables to safe defaults at declaration. They are
unconditionally overwritten in both if and else branches before use,
so behavior is unchanged. The new defaults are only relevant if a
future code path skips both assignments, in which case last_version=0
and compression_method=CompressionMethod::None are sane no-op values
(the same defaults the old structured-binding form would produce
through default-construction of the destructured aggregate).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
(cherry picked from commit d72cac5)
alexey-milovidov pushed a commit that referenced this pull request Jun 6, 2026
…rg::alter

PR #106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to
declare last_version and compression_method outside an if/else that
assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables
flags the bare declarations and Build (arm_tidy) is built with
-warnings-as-errors, so the build fails for every PR whose CI ran on
master after this commit.

CIDB shows 30+ unrelated PRs hitting this in the last 2 days
(e.g. #89360, #103540, #106120, #106386, #106404, #106522, #105102,
#106590).

Initialize both variables to safe defaults at declaration. They are
unconditionally overwritten in both if and else branches before use,
so behavior is unchanged. The new defaults are only relevant if a
future code path skips both assignments, in which case last_version=0
and compression_method=CompressionMethod::None are sane no-op values
(the same defaults the old structured-binding form would produce
through default-construction of the destructured aggregate).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
(cherry picked from commit d72cac5)
alexey-milovidov pushed a commit to gregakinman/ClickHouse that referenced this pull request Jun 6, 2026
…rg::alter

PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to
declare last_version and compression_method outside an if/else that
assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables
flags the bare declarations and Build (arm_tidy) is built with
-warnings-as-errors, so the build fails for every PR whose CI ran on
master after this commit.

CIDB shows 30+ unrelated PRs hitting this in the last 2 days
(e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102,
ClickHouse#106590).

Initialize both variables to safe defaults at declaration. They are
unconditionally overwritten in both if and else branches before use,
so behavior is unchanged. The new defaults are only relevant if a
future code path skips both assignments, in which case last_version=0
and compression_method=CompressionMethod::None are sane no-op values
(the same defaults the old structured-binding form would produce
through default-construction of the destructured aggregate).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
(cherry picked from commit d72cac5)
alexey-milovidov pushed a commit to niyue/ClickHouse that referenced this pull request Jun 6, 2026
…rg::alter

PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to
declare last_version and compression_method outside an if/else that
assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables
flags the bare declarations and Build (arm_tidy) is built with
-warnings-as-errors, so the build fails for every PR whose CI ran on
master after this commit.

CIDB shows 30+ unrelated PRs hitting this in the last 2 days
(e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102,
ClickHouse#106590).

Initialize both variables to safe defaults at declaration. They are
unconditionally overwritten in both if and else branches before use,
so behavior is unchanged. The new defaults are only relevant if a
future code path skips both assignments, in which case last_version=0
and compression_method=CompressionMethod::None are sane no-op values
(the same defaults the old structured-binding form would produce
through default-construction of the destructured aggregate).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
(cherry picked from commit d72cac5)
alexey-milovidov pushed a commit that referenced this pull request Jun 6, 2026
…rg::alter

PR #106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to
declare last_version and compression_method outside an if/else that
assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables
flags the bare declarations and Build (arm_tidy) is built with
-warnings-as-errors, so the build fails for every PR whose CI ran on
master after this commit.

CIDB shows 30+ unrelated PRs hitting this in the last 2 days
(e.g. #89360, #103540, #106120, #106386, #106404, #106522, #105102,
#106590).

Initialize both variables to safe defaults at declaration. They are
unconditionally overwritten in both if and else branches before use,
so behavior is unchanged. The new defaults are only relevant if a
future code path skips both assignments, in which case last_version=0
and compression_method=CompressionMethod::None are sane no-op values
(the same defaults the old structured-binding form would produce
through default-construction of the destructured aggregate).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
(cherry picked from commit d72cac5)
alexey-milovidov pushed a commit that referenced this pull request Jun 6, 2026
…rg::alter

PR #106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to
declare last_version and compression_method outside an if/else that
assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables
flags the bare declarations and Build (arm_tidy) is built with
-warnings-as-errors, so the build fails for every PR whose CI ran on
master after this commit.

CIDB shows 30+ unrelated PRs hitting this in the last 2 days
(e.g. #89360, #103540, #106120, #106386, #106404, #106522, #105102,
#106590).

Initialize both variables to safe defaults at declaration. They are
unconditionally overwritten in both if and else branches before use,
so behavior is unchanged. The new defaults are only relevant if a
future code path skips both assignments, in which case last_version=0
and compression_method=CompressionMethod::None are sane no-op values
(the same defaults the old structured-binding form would produce
through default-construction of the destructured aggregate).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
(cherry picked from commit d72cac5)
alexey-milovidov pushed a commit to JTCunning/ClickHouse that referenced this pull request Jun 6, 2026
…rg::alter

PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to
declare last_version and compression_method outside an if/else that
assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables
flags the bare declarations and Build (arm_tidy) is built with
-warnings-as-errors, so the build fails for every PR whose CI ran on
master after this commit.

CIDB shows 30+ unrelated PRs hitting this in the last 2 days
(e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102,
ClickHouse#106590).

Initialize both variables to safe defaults at declaration. They are
unconditionally overwritten in both if and else branches before use,
so behavior is unchanged. The new defaults are only relevant if a
future code path skips both assignments, in which case last_version=0
and compression_method=CompressionMethod::None are sane no-op values
(the same defaults the old structured-binding form would produce
through default-construction of the destructured aggregate).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
(cherry picked from commit d72cac5)
alexey-milovidov pushed a commit that referenced this pull request Jun 6, 2026
…rg::alter

PR #106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to
declare last_version and compression_method outside an if/else that
assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables
flags the bare declarations and Build (arm_tidy) is built with
-warnings-as-errors, so the build fails for every PR whose CI ran on
master after this commit.

CIDB shows 30+ unrelated PRs hitting this in the last 2 days
(e.g. #89360, #103540, #106120, #106386, #106404, #106522, #105102,
#106590).

Initialize both variables to safe defaults at declaration. They are
unconditionally overwritten in both if and else branches before use,
so behavior is unchanged. The new defaults are only relevant if a
future code path skips both assignments, in which case last_version=0
and compression_method=CompressionMethod::None are sane no-op values
(the same defaults the old structured-binding form would produce
through default-construction of the destructured aggregate).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
(cherry picked from commit d72cac5)
@fm4v

fm4v commented Jun 6, 2026

Copy link
Copy Markdown
Member

@groenai push empty commit to restart ci.

@groeneai

groeneai commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator Author

@fm4v done — empty commit pushed, CI is restarting on 22542a73f79366db7162fa6885d177e91d0555cc.

Note: master fix PR #106615 (the arm_tidy fix for PR #106102's uninitialized variables in Mutations.cpp) is approved by @alexey-milovidov but not merged yet, so this rerun may still hit Build (arm_tidy) until #106615 lands. Everything else should pass.

@groeneai

groeneai commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator Author

CI Ledger — covered SHA: 22542a73f79366db7162fa6885d177e91d0555cc

CI fully finished (Finish Workflow ✅, last test completion 2026-06-06T17:43:56Z, ≥20min CIDB ingestion buffer met).

Failure Classification Disposition
Stateless tests (amd_debug, parallel) (CheckRun: CANCELLED) infra (job cancelled before reporting any per-test results) Zero per-test FAIL/ERROR rows in CIDB for this SHA across all checks. The praktika runner cancelled this single amd_debug, parallel job (likely runner-pressure / scheduling, not a test outcome). 64 sibling Stateless test jobs and 17 build variants ran clean (0 failures). arm_tidy SUCCESS. Bugfix validation, Fast test, Style check, Code Review, AST fuzzer, all Integration tests, all Unit tests: SUCCESS.
Mergeable Check / PR (StatusContexts) aggregator Aggregator FAILURE because of the cancelled CheckRun. Tracked together.

PR-caused failure check: none. PR diff is unchanged (this commit is the empty Restart CI per @ fm4v's directive); previously verified projection-rewrite edit in src/Processors/QueryPlan/Optimizations/projectionsCommon.cpp plus the new test file. Zero per-test failures across the entire run; the only red CheckRun is one cancelled amd_debug, parallel slot with no test rows reported. Not actionable on this PR.

Moving to on_review.

@fm4v

fm4v commented Jun 9, 2026

Copy link
Copy Markdown
Member

@groeneai fix CI errors in this PR

…106573-projection-filter-column-data-corruption
@groeneai

Copy link
Copy Markdown
Collaborator Author

@fm4v The only red check was Stateless tests (amd_debug, parallel), and it was an infra hang, not a real failure:

  • The job ran exactly 6h0m14s (11:43:08Z to 17:43:22Z) and was then cancelled by the praktika 6-hour hard wall-clock limit. It uploaded zero per-test results to the CI database, which is the signature of a wedged runner/harness rather than a failing test.
  • The commit it ran on (22542a73) was the empty "Restart CI" commit, byte-identical to the code commit ad61b736, so nothing in it could have caused a hang.
  • The regression test 04319_106573_... passed 50/50 (about 2s each) in the amd_tsan, flaky check on that same SHA.
  • Mergeable Check and PR were only red because they aggregate that one cancelled job.

The branch was also ~1238 commits behind master, including the period when Build (arm_tidy) was broken trunk-wide by the Iceberg Mutations.cpp uninitialized-variable regression (now fixed on master by 1c0b3c1b407 "Fix arm_tidy build").

I have refreshed the branch onto current master and pushed. New HEAD: 554fc7af22b. The diff vs master is still exactly the three files of this PR (the projectionsCommon.cpp fix plus the new test). A fresh CI cycle on current infra should clear both the hung-runner job and arm_tidy.

…ion rewrite

The projection-rewrite fix in ad61b73 (drop the const-1 substitution for a
surviving filter column) raised a review question: when the filter expression is
non-deterministic, could the post-read expression that rebuilds the surviving
column re-evaluate it and disagree with the value that passed the filter?

It cannot. optimizeUseNormalProjection turns the filter into projection PREWHERE
via splitAndFillPrewhereInfo, which keeps the computed filter expression as a
PREWHERE output; the post-read ExpressionStep consumes that value as an input
(alias only) rather than recomputing it. EXPLAIN confirms a single rand() node in
the whole plan, and WHERE rand()-derived predicates never output a row that
failed the filter. The aggregate and minmax projection paths additionally reject
non-deterministic filters up front via isDeterministicInScopeOfQuery.

This adds a regression case asserting that a non-deterministic surviving filter
served from a normal projection keeps the value that passed the filter
(min(r) = 1), locking the contract in.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finished on HEAD ee8cc36b1456. The only failure is infrastructure noise, not PR-caused. Moving to review.

Check Failure Disposition
Stateless (arm_asan_ubsan, azure, sequential) "Server died" during 01915_create_or_replace_dictionary + "OOM in dmesg" Infra — the 2026-06-10/11 azure ASan secondary-allocator OOM outage (sanitizer_allocator_secondary.h) that hit many unrelated PRs and master in the same window. Unrelated to this projection-rewrite change.

Fast test, Style check, and Bugfix validation are green on this HEAD.

@clickhouse-gh

clickhouse-gh Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.20% 85.20% +0.00%
Functions 92.30% 92.30% +0.00%
Branches 77.40% 77.40% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 2/2 (100.00%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@KochetovNicolai
KochetovNicolai added this pull request to the merge queue Jun 17, 2026
Merged via the queue into ClickHouse:master with commit 4fd81e2 Jun 17, 2026
166 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 Jun 17, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Jul 21, 2026
…rojection key)

The projection reproducer in ClickHouse#110795 filters on a column not stored in the
projection (WHERE a over a projection on b). The previous revision used the
projection key as the filter column, which exercises the separate ClickHouse#106590
rewrite instead. Add the exact issue shape back: WHERE a GROUP BY b over a
projection on b, with result-parity against the projections-off path as the
regression lock (force_optimize_projection confirms the projection is not
chosen for this shape).

enable_analyzer = 1 stays scoped to the two plan-shape EXPLAIN assertions;
the result-comparison queries run under both analyzers.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
pull Bot pushed a commit to AnotherGenZ/ClickHouse that referenced this pull request Jul 21, 2026
…allel-replicas read paths

A bare non-UInt8 column in WHERE (implicit `col != 0`) is coerced by the
normal read path but was rejected with ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER on
the projection and parallel-replicas read paths (issue ClickHouse#110795). The defect no
longer reproduces on master (fixed via the WHERE-field-condition work in
ClickHouse#89603 and the projection filter fix in ClickHouse#106590), but there was no test
covering the non-UInt8 case across both alternative read paths. This adds one.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…rg::alter

PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to
declare last_version and compression_method outside an if/else that
assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables
flags the bare declarations and Build (arm_tidy) is built with
-warnings-as-errors, so the build fails for every PR whose CI ran on
master after this commit.

CIDB shows 30+ unrelated PRs hitting this in the last 2 days
(e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102,
ClickHouse#106590).

Initialize both variables to safe defaults at declaration. They are
unconditionally overwritten in both if and else branches before use,
so behavior is unchanged. The new defaults are only relevant if a
future code path skips both assignments, in which case last_version=0
and compression_method=CompressionMethod::None are sane no-op values
(the same defaults the old structured-binding form would produce
through default-construction of the destructured aggregate).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
(cherry picked from commit d72cac5)
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…rg::alter

PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to
declare last_version and compression_method outside an if/else that
assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables
flags the bare declarations and Build (arm_tidy) is built with
-warnings-as-errors, so the build fails for every PR whose CI ran on
master after this commit.

CIDB shows 30+ unrelated PRs hitting this in the last 2 days
(e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102,
ClickHouse#106590).

Initialize both variables to safe defaults at declaration. They are
unconditionally overwritten in both if and else branches before use,
so behavior is unchanged. The new defaults are only relevant if a
future code path skips both assignments, in which case last_version=0
and compression_method=CompressionMethod::None are sane no-op values
(the same defaults the old structured-binding form would produce
through default-construction of the destructured aggregate).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
(cherry picked from commit d72cac5)
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…rg::alter

PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to
declare last_version and compression_method outside an if/else that
assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables
flags the bare declarations and Build (arm_tidy) is built with
-warnings-as-errors, so the build fails for every PR whose CI ran on
master after this commit.

CIDB shows 30+ unrelated PRs hitting this in the last 2 days
(e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102,
ClickHouse#106590).

Initialize both variables to safe defaults at declaration. They are
unconditionally overwritten in both if and else branches before use,
so behavior is unchanged. The new defaults are only relevant if a
future code path skips both assignments, in which case last_version=0
and compression_method=CompressionMethod::None are sane no-op values
(the same defaults the old structured-binding form would produce
through default-construction of the destructured aggregate).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
(cherry picked from commit d72cac5)
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…allel-replicas read paths

A bare non-UInt8 column in WHERE (implicit `col != 0`) is coerced by the
normal read path but was rejected with ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER on
the projection and parallel-replicas read paths (issue ClickHouse#110795). The defect no
longer reproduces on master (fixed via the WHERE-field-condition work in
ClickHouse#89603 and the projection filter fix in ClickHouse#106590), but there was no test
covering the non-UInt8 case across both alternative read paths. This adds one.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…rojection key)

The projection reproducer in ClickHouse#110795 filters on a column not stored in the
projection (WHERE a over a projection on b). The previous revision used the
projection key as the filter column, which exercises the separate ClickHouse#106590
rewrite instead. Add the exact issue shape back: WHERE a GROUP BY b over a
projection on b, with result-parity against the projections-off path as the
regression lock (force_optimize_projection confirms the projection is not
chosen for this shape).

enable_analyzer = 1 stays scoped to the two plan-shape EXPLAIN assertions;
the result-comparison queries run under both analyzers.

Co-Authored-By: Claude Opus 4.8 <[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 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.

Wrong results: GROUP BY on the partition key with a WHERE filter is served from _minmax_count_projection and collapses all groups into one

5 participants