Skip to content

Fix filling of a missing DEFAULT column with multiple PREWHERE read steps - #111795

Merged
yariks5s merged 3 commits into
masterfrom
yarik/fix-multistep-prewhere-missing-defaults
Aug 3, 2026
Merged

yariks5s merged 3 commits into
masterfrom
yarik/fix-multistep-prewhere-missing-defaults

Conversation

@yariks5s

@yariks5s yariks5s commented Jul 24, 2026 •

Copy link
Copy Markdown
Member

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

Fix a DEFAULT column missing in a part being filled with the type default instead of the DEFAULT expression when the PREWHERE condition was split into multiple read steps. Closes #111757

Version info

  • Merged into: 26.8.1.678-master (included in 26.8 and later)

@clickhouse-gh

clickhouse-gh Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [dec47a2]

Summary: ✅


AI Review

Summary

This PR fixes evaluation of missing DEFAULT columns across multi-step PREWHERE reads by carrying projected-out dependency columns forward between read steps. The MergeTree read-path change looks consistent with the surrounding invariants, and the new stateless tests cover both the original wrong-result case and the patch-parts path. I did not find a remaining correctness issue; only a small PR-body metadata cleanup is worth making.

PR Metadata
  • Changelog category: correct (Bug Fix).
  • Changelog entry: required and directionally correct, but it mixes the changelog text with issue-closing housekeeping. Put Closes: on its own line and keep the changelog entry as a standalone user-facing sentence.
  • Exact replacement:
Closes: https://github.com/ClickHouse/ClickHouse/issues/111757

### Changelog entry (a [user-readable short description](https://github.com/ClickHouse/ClickHouse/blob/master/docs/changelog_entry_guidelines.md) of the changes that goes into CHANGELOG.md):
Fixes reads of `DEFAULT`-materialized columns from pre-`ALTER` parts when multi-step `PREWHERE` is used, so queries evaluate the `DEFAULT` expression instead of returning the type default.
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 24, 2026
@yariks5s yariks5s changed the title Yarik/fix multistep prewhere missing defaults Fix filling of a missing DEFAULT column with multiple PREWHERE read steps Jul 24, 2026
@nihalzp nihalzp self-assigned this Jul 27, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.30% 86.30% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 78.50% 78.40% -0.10%

Changed lines: Changed C/C++ lines covered: 6/6 (100.00%) · Uncovered code

Full report · Diff report

@yariks5s
yariks5s added this pull request to the merge queue Aug 3, 2026
Merged via the queue into master with commit 2251e69 Aug 3, 2026
178 checks passed
@yariks5s
yariks5s deleted the yarik/fix-multistep-prewhere-missing-defaults branch August 3, 2026 14:01
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 3, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

Hi — this looks like a backport candidate for 26.2, 26.3, 26.4, 26.5, 26.6. I ran this PR's own regression test against each branch's binary and the bug reproduces there (the fix isn't present yet).

Not needed on 26.1 — the test passes there (already not affected).

alexey-milovidov pushed a commit to ylw510/ClickHouse that referenced this pull request Nov 2, 2026
…y evaluate defaults

`ReadResult::additional_columns` holds the columns each PREWHERE step projects out. Since ClickHouse#111795 they are
carried across all later steps, so every later step filters them again in `ReadResult::applyFilter`. Their
only consumer is `MergeTreeReadersChain::evaluateMissingDefaults`, which runs only when a later reader's
`fillMissingColumns` leaves a requested column unfilled: a column with a default expression, or a subcolumn
whose parent is available.

`mayLeaveColumnToMissingDefaults`, next to `fillMissingColumns` and built from the same `hasDefault`, is a
superset of those two cases. `IMergeTreeReader::mayEvaluateMissingDefaults` applies it to the requested
columns. The chain asks every reader but the first one (it has no earlier step) when it is built, once per
read task, and the reader caches the answer because it is reused by the consecutive read tasks of a part:
without the cache the check took 1.7% of ClickBench Q3 in the reporter's profile. Only the steps before the
last reader that may evaluate defaults keep the columns. A `chassert` in `evaluateMissingDefaults` checks the
superset on every default evaluation.

`executePrewhereActionsAndFilterColumns` takes `keep_additional_columns` instead of `is_last_reader`, whose
only use there was this decision. ClickHouse#118630 introduces the same parameter for the same decision.

Found and analysed by @ snelheidai in ClickHouse#128432.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov alexey-milovidov added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Nov 9, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 9, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 9, 2026
PedroTadim added a commit that referenced this pull request Nov 9, 2026
Backport #111795 to 26.3: Fix filling of a missing DEFAULT column with multiple PREWHERE read steps
leshikus pushed a commit that referenced this pull request Nov 13, 2026
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 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.

Multi-step PREWHERE fills an ALTERed DEFAULT column with the type default when it is the only column read after the filter

7 participants