Skip to content

Fix SIGSEGV in view filter propagation due to type mismatch - #102085

Merged
mstetsyuk merged 2 commits into
masterfrom
mstetsyuk/fix-view-filter-type-mismatch-crash
Apr 9, 2026
Merged

mstetsyuk merged 2 commits into
masterfrom
mstetsyuk/fix-view-filter-type-mismatch-crash

Conversation

@mstetsyuk

@mstetsyuk mstetsyuk commented Apr 8, 2026 •

Copy link
Copy Markdown
Member

Linked issues

Changelog category (leave one):

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

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix crash (SIGSEGV) when querying a view with a WHERE clause and the inner query produces columns with different types than the view metadata (e.g. Nullable from LEFT JOIN with join_use_nulls).

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.4.1.711
  • Backported to: 26.3.6.9, 26.2.10.5, 26.1.8.29

When an outer WHERE filter is propagated through StorageView into
collectFiltersForAnalysis, the filter DAG's pre-compiled function
objects expect the view's metadata column types.  However, the inner
query plan may produce different actual types (e.g. Nullable wrappers
from LEFT JOIN with join_use_nulls, or integer type promotion).

The existing check at Planner.cpp only verifies column names are
present in the inner plan header — it does not verify type
compatibility.  When types diverge, ActionsDAG::updateHeader maps the
wrong-typed columns to the filter's function nodes by name, and
IExecutableFunction::executeImpl performs assert_cast (which is a bare
static_cast in release builds) on the mismatched column data,
producing a wild-pointer dereference (SIGSEGV).

Add a type equality check: skip filter injection when any input
column's type in the inner plan header differs from what the filter
DAG expects.  The query still returns correct results — it just
forgoes the predicate-pushdown optimisation for that view.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@mstetsyuk
mstetsyuk force-pushed the mstetsyuk/fix-view-filter-type-mismatch-crash branch from c6bc0ad to 75c0974 Compare April 8, 2026 15:45
@clickhouse-gh

clickhouse-gh Bot commented Apr 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a705031]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_asan_ubsan, flaky check) failure
00084_external_aggregation FAIL cidb
00084_external_aggregation FAIL cidb
Stateless tests (amd_asan_ubsan, flaky check) failure
02428_parameterized_view FAIL cidb
02428_parameterized_view FAIL cidb
00084_external_aggregation FAIL cidb
Stateless tests (amd_tsan, flaky check) failure
00084_external_aggregation FAIL cidb
Stress test (arm_msan) failure
Test script failed FAIL cidb

AI Review

Summary

This PR fixes a SIGSEGV in view filter propagation by preventing reuse of post_filter inputs when the current plan header has the same names but different types. The added guard in collectFiltersForAnalysis is a safe, targeted fix: it preserves filter pushdown when types match and skips unsafe filter injection when they do not. The new regression test reproduces the nullable/non-nullable mismatch scenario (join_use_nulls flip) and validates the fix.

Missing context
  • ⚠️ Full CI results and runtime logs are not yet available in this review context (several checks are still pending), so this review is based on code + test diff analysis.
ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Apr 8, 2026
@mstetsyuk
mstetsyuk force-pushed the mstetsyuk/fix-view-filter-type-mismatch-crash branch from 75c0974 to bb78616 Compare April 8, 2026 17:12
… check

Create the view with join_use_nulls=1 (metadata has Nullable) and query
with join_use_nulls=0 (inner plan produces non-Nullable). This bypasses
the one-way nullability check at StorageView.cpp:209 while still
exercising the type mismatch in collectFiltersForAnalysis.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@mstetsyuk
mstetsyuk force-pushed the mstetsyuk/fix-view-filter-type-mismatch-crash branch from bb78616 to a705031 Compare April 8, 2026 17:31
@clickhouse-gh

clickhouse-gh Bot commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.00% 84.00% +0.00%
Functions 90.90% 90.90% +0.00%
Branches 76.50% 76.50% +0.00%

Changed lines: 70.00% (7/10) · Uncovered code

Full report · Diff report

@KochetovNicolai KochetovNicolai left a comment

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.

Overall fine, but maybe can make it better - prepend CAST to inputs if the type is different.
Good to merge anyway.

@KochetovNicolai KochetovNicolai self-assigned this Apr 9, 2026
@mstetsyuk
mstetsyuk added this pull request to the merge queue Apr 9, 2026
Merged via the queue into master with commit 8c5c62a Apr 9, 2026
159 of 164 checks passed
@mstetsyuk
mstetsyuk deleted the mstetsyuk/fix-view-filter-type-mismatch-crash branch April 9, 2026 12:38
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 9, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Apr 9, 2026
robot-clickhouse added a commit that referenced this pull request Apr 9, 2026
robot-clickhouse added a commit that referenced this pull request Apr 9, 2026
robot-clickhouse added a commit that referenced this pull request Apr 9, 2026
clickhouse-gh Bot added a commit that referenced this pull request Apr 9, 2026
Backport #102085 to 26.2: Fix SIGSEGV in view filter propagation due to type mismatch
mstetsyuk added a commit that referenced this pull request Apr 10, 2026
Backport #102085 to 26.1: Fix SIGSEGV in view filter propagation due to type mismatch
mstetsyuk added a commit that referenced this pull request Apr 10, 2026
Backport #102085 to 26.3: Fix SIGSEGV in view filter propagation due to type mismatch
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Apr 10, 2026
@mstetsyuk mstetsyuk removed the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Apr 11, 2026
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Apr 11, 2026
@watson-ch watson-ch Bot added v26.4-must-backport and removed pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR labels Jul 6, 2026
@watson-ch

watson-ch Bot commented Jul 6, 2026

Copy link
Copy Markdown

Backport labels have been automatically added based on https://github.com/clickhouse/clickhouse-core-incidents/issues/1590

Labels added:

  • v26.4-must-backport

These labels ensure backport PRs are properly created for each affected release version. The release automation will create backport PRs as needed based on these labels.

@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 Jul 6, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jul 6, 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-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 v26.4-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants