Skip to content

Fix block structure mismatch in UnionStep after filter push-down with NULL constants - #104853

Merged
Avogar merged 2 commits into
masterfrom
fix-filter-push-down-const-null-union
May 20, 2026
Merged

Avogar merged 2 commits into
masterfrom
fix-filter-push-down-const-null-union

Conversation

@Avogar

@Avogar Avogar commented May 13, 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 block structure mismatch in UnionStep after filter push-down with NULL constants. Closes #104821

Version info

  • Merged into: 26.5.1.902

… NULL constants

When `splitFilter` splits an AND conjunction (e.g. `dummy AND count() + NULL`)
and pushes part of it below aggregation, the remaining expression
(`plus(count(), NULL)`) may fold to a ColumnConst because
`defaultImplementationForNulls` short-circuits when a NULL constant argument
is present. The `is_filter_const_after_push_down` flag from
`removeUnusedConjunctions` does not account for this — it is only set when
ALL conjunctions are pushed down.

As a result, the Const filter column propagates into the plan header for the
first UNION branch, while the second branch has a non-Const column from
`materialize`, causing a "Block structure mismatch in UnionStep" exception.

The fix evaluates the actual constness of the filter column after push-down
by calling `updateHeader` on the modified expression DAG. When the filter
column became Const unexpectedly, `materializeFilterColumnIfNeededAfterPushDown`
is called with the corrected flag to insert a `materialize` node, ensuring
the output column is non-Const and headers stay consistent.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented May 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [88eb1d1]

Summary: ❌

job_name test_name status info comment
Bugfix validation (functional tests) FAIL
Tests FAIL IGNORED
Stress test (amd_asan_ubsan) FAIL
Hung check failed, possible deadlock found FAIL cidb IGNORED
Cannot start clickhouse-server FAIL cidb IGNORED
Check failed FAIL cidb IGNORED

AI Review

Summary

This PR fixes a real filterPushDown invariant break: after partial push-down, the remaining predicate can still become a const column (for example via NULL short-circuit), which previously left header constness inconsistent and could trigger a Block structure mismatch exception in parents such as UnionStep. The implementation detects this post-push-down constness and materializes when needed; the added stateless regression test matches the reported scenario.

Final Verdict

✅ No blockers or major issues found in the current diff.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label May 13, 2026
@yariks5s yariks5s self-assigned this May 14, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 15, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.20% +0.10%
Functions 90.90% 90.90% +0.00%
Branches 76.60% 76.60% +0.00%

Changed lines: 100.00% (8/8) · Uncovered code

Full report · Diff report

alexey-milovidov pushed a commit to Onyx2406/ClickHouse that referenced this pull request May 19, 2026
The `Docker server image` job intermittently fails when fetching the
prebuilt `.deb` packages from `clickhouse-builds.s3.amazonaws.com`:

```
ERROR 500: Internal Server Error.
ERROR 503: Service Unavailable.
```

Three unrelated PRs hit this S3 download flake over three days
(`ClickHouse#100173` on 2026-05-15 with `500`, `ClickHouse#104694` on 2026-05-14 with `503`,
`ClickHouse#104853` on 2026-05-13 with `503`). On master in the last 14 days the
master `Docker server image` job has 1 failure of the same shape.

`docker/server/Dockerfile.alpine` already wraps `wget` with a retry
helper (added in ClickHouse#100380 to absorb the same kind of transient errors
during Alpine cross-architecture builds via QEMU). The Ubuntu and
distroless flavours still call `wget ... || exit 1` on the very first
attempt, so a single `500`/`503` from S3 kills the whole build.

This change ports the same `wget_with_retry` wrapper to
`docker/server/Dockerfile.ubuntu` and `docker/server/Dockerfile.distroless`
for the `DIRECT_DOWNLOAD_URLS` block (the path used by CI). `WGET_RETRIES`
(default `5`) and `WGET_RETRY_DELAY` (default `1s`) match the Alpine
version and remain overridable via `--build-arg`.

CI report (PR ClickHouse#100173, sha 3ceac71): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100173&sha=3ceac71a43a5fd4fc1a7859937b23e71b8fe42ae&name_0=PR&name_1=Docker%20server%20image

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@Avogar
Avogar requested a review from yariks5s May 19, 2026 19:12
@Avogar
Avogar added this pull request to the merge queue May 20, 2026
Merged via the queue into master with commit 46aa4da May 20, 2026
164 of 167 checks passed
@Avogar
Avogar deleted the fix-filter-push-down-const-null-union branch May 20, 2026 17:42
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 20, 2026
DavidHe-2008 pushed a commit to DavidHe-2008/ClickHouse that referenced this pull request Jun 1, 2026
…down-const-null-union

Fix block structure mismatch in UnionStep after filter push-down with NULL constants
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.

Logical error: Block structure mismatch in A stream: different columns: (STID: 0993-27f0)

3 participants