Skip to content

Make ReadFromMergeTree unused column removal position based - #106438

Merged
antaljanosbenjamin merged 11 commits into
masterfrom
make-rfmt-unused-column-removal-position-based
Jul 8, 2026
Merged

antaljanosbenjamin merged 11 commits into
masterfrom
make-rfmt-unused-column-removal-position-based

Conversation

@antaljanosbenjamin

@antaljanosbenjamin antaljanosbenjamin commented Jun 4, 2026 •

Copy link
Copy Markdown
Member

A better version of #106104, fixes #106099.

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):

Fixes LOGICAL_ERROR about duplicate column names in row policy actions.

Version info

  • Merged into: 26.7.1.663 (included in 26.7 and later)
  • Backported to: 26.6.2.51

It is necessary because in some cases the row policy can contain duplicated column names.
@antaljanosbenjamin antaljanosbenjamin changed the title Make rfmt unused column removal position based Make ReadFromMergeTree unused column removal position based Jun 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5de6947]

Summary: ❌

job_name test_name status info comment
AST fuzzer (amd_debug, targeted) FAIL
Logical error: Block structure mismatch in A stream: different columns: (STID: 0993-27f0) FAIL cidb, issue ISSUE EXISTS
Stress test (amd_tsan) FAIL
Hung check failed, possible deadlock found FAIL cidb, issue ISSUE EXISTS
Stress test (arm_tsan) FAIL
Hung check failed, possible deadlock found FAIL cidb, issue ISSUE EXISTS

AI Review

Summary

This PR makes ReadFromMergeTree unused-column pruning position-based for filter DAG outputs, shares that pruning logic with FilterStep, and updates projection/filter tests for bare-column row policies and additional_table_filters. I reviewed the current PR patch at 5de69475, the relevant surrounding code, CI report, and prior review threads; I did not find a new correctness issue that needs an inline comment.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jun 4, 2026
It is technically not correct, but it is hard to fix it so let's separate this from the fix in remove unused column
node->result_type->getName(), name);

if (!isUInt8(removeNullable(removeLowCardinality(node->result_type))))
return nullptr;

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.

We relax the check above to canBeUsedInBooleanContext() but continue to only rewrite those that yield UInt8? Is it a programming error if the exception in line 131 is hit?

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.

There was a rewrite of columns to a constant 1, which caused issues in a lot of cases. I didn't want to change the behavior, because it would have made an already existing bug worse. As that was fixed in the meantime, I removed this check.


-- Same producer-side dedup also runs for `additional_table_filters`. Without
-- the fix at `InterpreterSelectQuery.cpp` the override would force
-- `FilterTransform` to erase the only `c0` output, breaking `SELECT c0`.

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 found code handling additional_table_filters in InterpreterSelectQuery.cpp but it does only seem to inject those filters by invoking parseQuery. Why would the dedup erase c0 (and which the projected c0 or the c0 in the additional_table_filter)?

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.

The idea is to construct the kind of same query tree as with the row policy, technically all the different ways we can inject c0 as a filter into the query. I think the test slipped through from a previous attempt, where AI wanted to "fix everything once and for all". The comment is probably not correct, but I opted to keep the tests to ensure no unexpected things happen.

@antaljanosbenjamin
antaljanosbenjamin requested a review from cv4g June 24, 2026 09:32
@clickhouse-gh

clickhouse-gh Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.50% 85.50% +0.00%
Functions 92.70% 92.70% +0.00%
Branches 77.80% 77.70% -0.10%

Changed lines: Changed C/C++ lines covered: 143/159 (89.94%) · Uncovered code

Full report · Diff report

@antaljanosbenjamin
antaljanosbenjamin added this pull request to the merge queue Jul 8, 2026
@antaljanosbenjamin antaljanosbenjamin added pr-bugfix Pull request with bugfix, not backported by default v26.6-must-backport and removed pr-not-for-changelog This PR should not be mentioned in the changelog labels Jul 8, 2026
Merged via the queue into master with commit 0a0f162 Jul 8, 2026
170 of 174 checks passed
@antaljanosbenjamin
antaljanosbenjamin deleted the make-rfmt-unused-column-removal-position-based branch July 8, 2026 13:32
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jul 8, 2026
@robot-clickhouse robot-clickhouse added 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 labels Jul 8, 2026
clickhouse-gh Bot added a commit that referenced this pull request Jul 8, 2026
Backport #106438 to 26.6: Make ReadFromMergeTree unused column removal position based
@clickgapai

Copy link
Copy Markdown
Contributor

Hi @antaljanosbenjamin @cv4g — while reviewing this PR I found the following:

Could you review the test PR and add the can be tested label if it looks good?
Happy to discuss — close anything that's wrong or already addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default 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 v26.6-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Row policy with a bare-column USING expression: LOGICAL_ERROR "Duplicate column name ... in row policy actions output" (26.x regression)

6 participants