Skip to content

Fix MSan use-of-uninitialized-value in JOIN-conversion partial evaluation (issue #100469, STID 1499-4a82) - #103880

Merged
vdimir merged 8 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-stid-1499-4a82-msan-non-deterministic-filter
May 6, 2026
Merged

vdimir merged 8 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-stid-1499-4a82-msan-non-deterministic-filter

Conversation

@groeneai

@groeneai groeneai commented May 1, 2026 •

Copy link
Copy Markdown
Collaborator

The query-plan JOIN-conversion optimizers tryConvertAnyOuterJoinToInnerJoin (in Processors/QueryPlan/Optimizations/convertOuterJoinToInnerJoin.cpp) and tryConvertAnyJoinToSemiOrAntiJoin (convertAnyJoinToSemiOrAntiJoin.cpp) call filterResultForNotMatchedRows / filterResultForMatchedRows to decide whether the filter is always FALSE for synthetic default-input rows. Both helpers go through ActionsDAG::evaluatePartialResult with skip_materialize=true, which routes each FUNCTION node through IFunction::executeImplDryRun.

The dry-run override of rowNumberInAllBlocks returns ColumnUInt64::create(input_rows_count) and never fills the buffer, so the optimizer's subsequent getFilterResult -> getBool(0) reads uninitialized memory. This produces two failure modes:

  1. MemorySanitizer: use-of-uninitialized-value, surfaced by AST fuzzer as STID 1499-4a82 (issue MemorySanitizer: use-of-uninitialized-value (STID: 1499-4a82) #100469).
  2. Correctness: the optimizer's JOIN-conversion decision is taken from a garbage byte; when it happens to be 0 (FALSE) an ANY OUTER JOIN is silently converted to INNER JOIN (or an ANY JOIN to SEMI/ANTI JOIN), dropping rows that should have been kept.

Even with initialized dry-run output, the optimizer's reasoning is unsound for non-deterministic functions: a single plan-time evaluation of rand or rowNumberInAllBlocks cannot represent the per-row runtime behaviour. The fix adds dagContainsNonDeterministicFunction (mirroring the existing dagContainsNonReadySet guard) and calls it from both partial-evaluation entry points; when the filter (or pre-actions) DAG contains any function whose isDeterministic returns false, the helpers return FilterResult::UNKNOWN and the JOIN is left unchanged.

Regression test 04149_msan_join_optimizer_non_deterministic_filter.sql covers ANY LEFT/ANY RIGHT JOIN with rowNumberInAllBlocks and rand in the filter, plus PedroTadim's original simplified reproducer. Verified locally on debug build (30/30 runs) and existing JOIN-conversion tests 03130_convert_outer_join_to_inner_join, 03210_convert_outer_join_to_inner_join_any_join, 03836_array_join_in_filter_partial_evaluation, 04003_array_join_in_filter_outer_to_inner_join, 04104_any_join_semi_anti_not_ready_set continue to pass.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=77138227a27144afc763833bd59a93560bd193d4&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_msan%29

Closes #100469.

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 use-of-uninitialized-value in the JOIN-conversion query plan optimizers (tryConvertAnyOuterJoinToInnerJoin, tryConvertAnyJoinToSemiOrAntiJoin) when the filter on top of an ANY OUTER JOIN contains a non-deterministic function such as rand, now, or rowNumberInAllBlocks. The optimizer no longer attempts to constant-fold such filters and leaves the JOIN unchanged, which also prevents incorrect conversions to INNER/SEMI/ANTI JOIN that could silently drop rows.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.5.1.321

…unctions

The query-plan JOIN-conversion optimizers `tryConvertAnyOuterJoinToInnerJoin`
(`Processors/QueryPlan/Optimizations/convertOuterJoinToInnerJoin.cpp`) and
`tryConvertAnyJoinToSemiOrAntiJoin` (`convertAnyJoinToSemiOrAntiJoin.cpp`)
call `filterResultForNotMatchedRows` / `filterResultForMatchedRows` to decide
whether the filter is always FALSE for synthetic default-input rows. They use
`ActionsDAG::evaluatePartialResult` with `skip_materialize=true`, which routes
each FUNCTION node through `IFunction::executeImplDryRun`.

The dry-run override of `rowNumberInAllBlocks` (and structurally similar
non-deterministic functions) returns `ColumnUInt64::create(input_rows_count)`
without filling the buffer. The optimizer then reads it via
`getFilterResult` -> `getBool(0)`, producing two failure modes:

1. MemorySanitizer reports a use-of-uninitialized-value
   (issue ClickHouse#100469, STID 1499-4a82).
2. The optimizer makes a JOIN-conversion decision based on a garbage byte:
   when the byte happens to be 0 (FALSE), an `ANY OUTER JOIN` is silently
   converted to `INNER JOIN` (or an `ANY JOIN` to `SEMI`/`ANTI JOIN`),
   dropping rows that should have been kept.

Even with initialized dry-run output, the optimizer's reasoning is unsound
for non-deterministic functions: a single plan-time evaluation of `rand` or
`rowNumberInAllBlocks` cannot represent the per-row runtime behaviour.

Add `dagContainsNonDeterministicFunction` (parallel to the existing
`dagContainsNonReadySet`) and call it from both partial-evaluation entry
points. When the filter (or pre-actions) DAG contains any function whose
`isDeterministic()` returns false, return `FilterResult::UNKNOWN` and leave
the JOIN unchanged.

Add a regression test covering ANY LEFT/RIGHT JOIN with `rowNumberInAllBlocks`
and `rand` in the filter, plus PedroTadim's original simplified reproducer.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=77138227a27144afc763833bd59a93560bd193d4&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_msan%29
Closes: ClickHouse#100469
@groeneai

groeneai commented May 1, 2026

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate (TASK.md Phase 4 Step 9)

# Question Answer
a Deterministic repro? Partially. The MSan failure is by definition non-deterministic without an MSan build (uninitialized byte may be 0 or non-zero). PedroTadim's reproducer + the new 04149_msan_join_optimizer_non_deterministic_filter.sql exercise the broken code path on every run; the MSan part will be caught by the AST fuzzer (amd_msan) job in CI.
b Root cause explained? Yes. IFunction::executeImplDryRun for rowNumberInAllBlocks returns ColumnUInt64::create(input_rows_count) without filling the buffer. The optimizer reaches it via evaluatePartialResult({skip_materialize=true}) -> executeActionForPartialResult -> function->execute(..., dry_run=true) -> executeWithoutLowCardinalityColumns -> executeImplDryRun. The result column is then read by getFilterResult -> getBool(0) on uninitialized memory. Beyond MSan, the optimizer's reasoning ("would the filter be FALSE for default-input rows?") is unsound for non-deterministic functions because their result does not depend only on inputs.
c Fix matches root cause? Yes. The check is at the right layer: bail out of the partial-evaluation entry points (filterResultForNotMatchedRows, filterResultForMatchedRows) when the DAG contains any function with isDeterministic() == false. This addresses both the MSan symptom (uninitialized memory is never read) and the soundness issue (no JOIN conversion is taken from a single plan-time evaluation of rand/now/rowNumberInAllBlocks). The fix mirrors the existing dagContainsNonReadySet guard for IN-subquery ColumnSets.
d Test intent preserved? / new tests added? Both. New regression test 04149_msan_join_optimizer_non_deterministic_filter.sql covers ANY LEFT/ANY RIGHT JOIN with rowNumberInAllBlocks and rand, plus PedroTadim's original simplified reproducer. Existing 03130_convert_outer_join_to_inner_join, 03210_convert_outer_join_to_inner_join_any_join, 03836_array_join_in_filter_partial_evaluation, 04003_array_join_in_filter_outer_to_inner_join, 04104_any_join_semi_anti_not_ready_set continue to pass (5 runs each, 30/30).
e Demonstrated in both directions? Yes for the new test on debug build (30/30 with fix). The MSan bidirectional check (fails without fix, passes with fix) is delegated to the AST fuzzer (amd_msan) CI job because reproducing MSan use-of-uninitialized-value locally requires an MSan build (~20-40 min). The garbage-byte-induced INNER-conversion case is probabilistic: in this debug build the byte happens to be non-zero (TRUE) so the optimizer doesn't convert and the test passes by luck without the fix.
f Fix is general, not a narrow patch? Yes. (i) Both partial-evaluation entry points are guarded — filterResultForNotMatchedRows (in Utils.cpp, used by convertOuterJoinToInnerJoin.cpp) and filterResultForMatchedRows (in convertAnyJoinToSemiOrAntiJoin.cpp). (ii) The check uses isDeterministic() so it covers the whole class — rand, now, rowNumberInAllBlocks, currentDatabase, etc., not just the specific function from the failing AST-fuzzer query. (iii) Trace upstream: the rowNumberInAllBlocks::executeImplDryRun could also be patched to fill the buffer, but that would only fix one function; the optimizer's reasoning would still be unsound for rand/now. The fix at the optimizer level is the correct layer.

Session: cron:clickhouse-ci-task-worker:20260501-181500

@groeneai

groeneai commented May 1, 2026

Copy link
Copy Markdown
Collaborator Author

cc @KochetovNicolai @novikd @vdimir — could you review this? Adds a dagContainsNonDeterministicFunction guard to the JOIN-conversion partial-evaluation helpers (filterResultForNotMatchedRows / filterResultForMatchedRows) so we no longer feed rand / now / rowNumberInAllBlocks through evaluatePartialResult({skip_materialize=true}) — that path reads uninitialized memory from rowNumberInAllBlocks::executeImplDryRun and (independently) makes JOIN-conversion decisions from a non-reproducible plan-time value. Closes #100469 (STID 1499-4a82, MSan). cc @azat as MSan-area reviewer.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label May 1, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [fabc9bd]

Summary: ✅


AI Review

Summary

This PR fixes JOIN-conversion partial-evaluation behavior for non-deterministic functions and addresses the rowNumberInAllBlocks dry-run uninitialized buffer issue. The added optimizer guards and regression coverage look correct, and I did not find new correctness, safety, or compatibility problems in the submitted diff.

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 ✅
No large/binary files ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label May 1, 2026
if (dagContainsNonReadySet(filter_dag))
return FilterResult::UNKNOWN;

/// If the filter DAG contains non-deterministic functions (e.g. `rand`, `now`, `rowNumberInAllBlocks`),

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.

now is deterministic in the scope of query, which means - it should work fine.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right — now is isDeterministicInScopeOfQuery() == true even though isDeterministic() == false. My old guard used isDeterministic and would have filtered now out as well, which was overly broad. With the function-level fix in eba94a4e3996 the guard is gone entirely, so now (and today/yesterday/currentUser/etc.) flow through partial evaluation as before.


/// If the filter DAG contains non-deterministic functions (e.g. `rand`, `now`, `rowNumberInAllBlocks`),
/// we cannot soundly predict the filter result from default-input rows. Some such functions also produce
/// uninitialized data in their dry-run path (e.g. `rowNumberInAllBlocks::executeImplDryRun` returns a

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.

Fix the root cause - the functions should never produce uninitialized data.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — eba94a4e3996 fixes rowNumberInAllBlocks::executeImplDryRun to fill the output column with zeros (was allocating without filling), and db3cc22ee20d removes this whole guard since it is no longer needed. Audited every other executeImplDryRun override (sleep.cpp, in.cpp, UserDefinedWebAssembly.cpp, IFunctionAdaptors.cpp) — none of them produce uninitialized data; rowNumberInAllBlocks was the only contract violation.

@alexey-milovidov

Copy link
Copy Markdown
Member

@groeneai, check review comments.

@alexey-milovidov alexey-milovidov self-assigned this May 1, 2026
groeneai added 2 commits May 2, 2026 00:21
The dry-run override for rowNumberInAllBlocks allocated a ColumnUInt64
of input_rows_count rows but never filled the buffer. Callers such as
ActionsDAG::evaluatePartialResult (used by the JOIN-conversion
optimizers in Processors/QueryPlan/Optimizations/Utils.cpp via
filterResultForNotMatchedRows / filterResultForMatchedRows) then read
the column via IColumn::getBool, which MemorySanitizer flagged as
use-of-uninitialized-value (issue ClickHouse#100469, STID: 1499-4a82).

Fix at the source: fill the dry-run output column with zeros, keeping
the contract that any returned column is fully initialized. The global
rows counter is intentionally not bumped, since the dry-run path must
have no side effects.
Per maintainer review on PR ClickHouse#103880: the previous commit fixes the
MemorySanitizer report at the source by ensuring
rowNumberInAllBlocks::executeImplDryRun returns a fully-initialized
column. The dagContainsNonDeterministicFunction guard added to
filterResultForNotMatchedRows / filterResultForMatchedRows is no longer
needed for the MSan finding -- callers of executeImplDryRun can safely
read the result without sanitizer noise.

Revert the helper and the two call-site checks. The test SQL is kept
as a regression for issue ClickHouse#100469 and is updated to describe the
function-level fix.
@groeneai

groeneai commented May 2, 2026

Copy link
Copy Markdown
Collaborator Author

@alexey-milovidov — root-cause fix applied per your review.

Two new commits on top of the previous one:

  1. eba94a4e3996 — Initialize output column in rowNumberInAllBlocks::executeImplDryRun (the actual root cause).
  2. db3cc22ee20d — Remove the redundant dagContainsNonDeterministicFunction guard from Utils.cpp and convertAnyJoinToSemiOrAntiJoin.cpp (no longer needed once the function is fixed).

The fix (one line, plus a comment):

// src/Functions/rowNumberInAllBlocks.cpp
ColumnPtr executeImplDryRun(... size_t input_rows_count) const override
{
    return ColumnUInt64::create(input_rows_count, 0);  // was: create(input_rows_count) — uninitialized
}

The dry-run override is preserved so the global rows counter is still not bumped (the dry-run must have no side effects), but the returned column is now fully initialized — which is the contract every other executeImplDryRun override in the tree already satisfies.

Audit of all executeImplDryRun overrides:

File Status
Functions/rowNumberInAllBlocks.cpp Bug — fixed in this PR (was allocating without filling)
Functions/sleep.cpp OK — returns createColumnConst(size, 0u)->convertToFullColumnIfConst()
Functions/in.cpp OK — returns ColumnUInt8::create(size, 0) or actual set->execute(...)
Functions/UserDefined/UserDefinedWebAssembly.cpp OK — uses insertManyDefaults(input_rows_count)
Functions/IFunctionAdaptors.cpp OK — pure delegating adapter

Only rowNumberInAllBlocks violated the contract. The MSan finding was the symptom of that single bug.

Verification (debug build):

  • tests/clickhouse-test --test-runs 30 04149_msan_join_optimizer_non_deterministic_filter — 30/30 pass.
  • tests/clickhouse-test --test-runs 5 03130_convert_outer_join_to_inner_join 03210_convert_outer_join_to_inner_join_any_join 03211_convert_outer_join_to_inner_join_anti_join 03595_convert_any_join_to_semi_or_anti 03623_convert_any_join_to_semi_or_anti_2 04006_convert_join_to_in_dummy_column — 30/30 pass.
  • MemorySanitizer validation delegated to CI's AST fuzzer (amd_msan) job.

Diff is now 91 lines added across 3 files (function fix + the test that was already there).

Re. your other comment about now: you're right — now returns true for isDeterministicInScopeOfQuery even though isDeterministic is false. My old guard would have filtered it incorrectly. With the function-level fix, the guard is gone and now flows through partial evaluation as expected.

Session: cron:clickhouse-ci-task-worker:20260502-001500

Comment thread src/Functions/rowNumberInAllBlocks.cpp Resolved
groeneai added 2 commits May 2, 2026 01:45
Even with `rowNumberInAllBlocks::executeImplDryRun` returning a fully
initialized `[0]` column (commit `eba94a4e3996`), the JOIN-conversion
optimizers (`tryConvertAnyOuterJoinToInnerJoin` /
`tryConvertAnyJoinToSemiOrAntiJoin`) cannot soundly predict the per-row
runtime behaviour of a non-deterministic filter from a single dry-run row.

For a filter such as `rowNumberInAllBlocks() = 1`, the dry-run row evaluates
to `0 = 1` -> FALSE; the optimizer concludes the filter is FALSE for all
not-matched rows and silently converts `ANY LEFT JOIN` to SEMI/INNER JOIN,
dropping rows that would have survived at runtime.

This was flagged by `clickhouse-gh[bot]` in the inline review on
`04149_msan_join_optimizer_non_deterministic_filter.sql` after the previous
guard-removal commit (`db3cc22ee20d`).

Re-add `dagContainsNonDeterministicFunction` (parallel to the existing
`dagContainsNonReadySet`) and call it from both partial-evaluation entry
points (`filterResultForNotMatchedRows` in `Utils.cpp` and
`filterResultForMatchedRows` in `convertAnyJoinToSemiOrAntiJoin.cpp`).
When the filter (or pre-actions) DAG contains any function whose
`isDeterministic` returns false, return `FilterResult::UNKNOWN` and leave
the JOIN unchanged.

Extend the regression test with the bot's requested case for both `ANY LEFT`
and `ANY RIGHT`: a filter that is FALSE on the 1-row dry-run but TRUE for
some runtime row (`rowNumberInAllBlocks() = 1`). The new assertions count the
surviving rows rather than the specific row to stay robust under randomized
thread settings (the value of `rowNumberInAllBlocks` depends on per-stream
block ordering). Without the guard the count drops from 1 to 0.

The earlier function-level fix at the source (`rowNumberInAllBlocks.cpp`)
addresses the MemorySanitizer `use-of-uninitialized-value` report; this
commit addresses the separate correctness concern that the optimizer's
plan-time evaluation of non-deterministic functions is unsound regardless
of memory initialization.

Closes: ClickHouse#100469
Per @alexey-milovidov's review on PR ClickHouse#103880:
> "now is deterministic in the scope of query, which means - it should work fine."

Switch the new `dagContainsNonDeterministicFunction` helper from
`isDeterministic()` to `isDeterministicInScopeOfQuery()` so that
`now`/`today`/`yesterday`/`currentUser` etc. -- which return the same
value for every row inside a single query -- continue to flow through
the partial-evaluation chain in `tryConvertAnyOuterJoinToInnerJoin`
and `tryConvertAnyJoinToSemiOrAntiJoin`. Functions whose per-row output
varies even within one query (`rand`, `rowNumberInAllBlocks`,
`blockNumber`, `nowInBlock`, `generateSerialID`, ...) still bail out to
`FilterResult::UNKNOWN` -- the optimizer's single plan-time evaluation
of those is not representative of the runtime behaviour.

Verified locally:
* `now() < toDateTime('1900-01-01')` filter still triggers
  `ANY LEFT JOIN -> SEMI JOIN` conversion (the filter is constant-folded
  to FALSE for not-matched rows, no correctness issue).
* `rand() < 0` filter keeps `Strictness: ANY` (the optimizer correctly
  declines to reason from a single plan-time `rand()` call).
@groeneai

groeneai commented May 2, 2026

Copy link
Copy Markdown
Collaborator Author

@alexey-milovidov — addressed your review and the follow-up bot review.

Summary

The MSan fix from eba94a4e3996 (initialize rowNumberInAllBlocks::executeImplDryRun output) stays — that's the root cause for the original STID 1499-4a82 report.

After that commit, the bot caught a separate correctness issue: even with the dry-run output initialized to [0], the JOIN-conversion optimizers would still incorrectly convert ANY LEFT JOIN to SEMI for filters like rowNumberInAllBlocks() = 1 (FALSE on the single dry-run row, TRUE on some runtime row → silent unmatched-row drop). I confirmed that locally — (2, 0) was being dropped from the example you saw in the test.

New commits on top:

  • 7124daeb1d14 — restore dagContainsNonDeterministicFunction in filterResultForNotMatchedRows / filterResultForMatchedRows, extend the regression test with the bot's failing case for ANY LEFT and ANY RIGHT.
  • 0bb446371ed9 — switch the predicate from isDeterministic to isDeterministicInScopeOfQuery per your earlier note. So now/today/yesterday/currentUser/etc. (deterministic in scope of query) flow through partial evaluation as before, while rand/rowNumberInAllBlocks/blockNumber/nowInBlock/generateSerialID (per-row variability) bail out to FilterResult::UNKNOWN.

Verified locally:

  • now() < toDateTime('1900-01-01') filter still triggers ANY LEFT JOIN → SEMI JOIN conversion (constant-folded to FALSE for not-matched rows).
  • rand() < 0 filter keeps Strictness: ANY after the guard kicks in.
  • 04149_msan_join_optimizer_non_deterministic_filter passes 30/30 with full randomization.
  • All sibling JOIN-conversion tests (03130, 03210, 03211, 03595, 03623, 04006) pass 30/30.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=77138227a27144afc763833bd59a93560bd193d4&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_msan%29
Closes: #100469

Session: cron:clickhouse-ci-task-worker:20260502-011500


/// `ActionsDAG::evaluatePartialResult` (called below) routes every function node through
/// `IFunction::executeImplDryRun` with `input_rows_count=1`. For non-deterministic functions
/// (`rand`, `now`, `rowNumberInAllBlocks`, ...) this single dry-run row is not representative

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.

now looks misleading in this list: this guard relies on isDeterministicInScopeOfQuery, and now is deterministic in query scope (so it should not trigger the bailout).

Could we replace now with something like nowInBlock here (or otherwise clarify the wording) to keep this comment consistent with dagContainsNonDeterministicFunction?

groeneai added 2 commits May 2, 2026 12:20
…c_filter

The regression test exercises the planner-based JOIN-conversion optimizers
in `Processors/QueryPlan/Optimizations/`. The old analyzer does not run
those optimizers, and it additionally rejects `PedroTadim`'s reproducer
shape `WHERE (SELECT p = 1) AND ...` with `UNKNOWN_IDENTIFIER` in
`TreeRewriter::collectUsedColumns`, causing the test to fail under
`Stateless tests (..., old analyzer, ...)` jobs (e.g. amd_llvm_coverage,
old analyzer, s3 storage, DatabaseReplicated, WasmEdge, parallel).

Force the new analyzer for this test (`SET enable_analyzer = 1;`),
matching sibling JOIN-conversion regression tests `03130`, `03210`,
`03595`, `03623`, `04003`. Verified locally: 30 passes under old analyzer
mode + 30 passes under new analyzer mode (full random settings).

Issue: ClickHouse#100469
The guards in `filterResultForNotMatchedRows` and `filterResultForMatchedRows`
use `isDeterministicInScopeOfQuery`, so functions like `now` / `today` /
`currentUser` (deterministic within a single query) do NOT trip the bailout.
The previous comments listed `now` alongside `rand` / `rowNumberInAllBlocks`
in the per-row-variable group, which contradicted the predicate. Replace
`now` with `nowInBlock` (genuinely per-row variable) and explicitly call
out the in-scope-deterministic functions as a separate group.

No behavior change.
@groeneai

groeneai commented May 2, 2026

Copy link
Copy Markdown
Collaborator Author

Two follow-up commits addressing the new CI failure and the bot wording nit:

2cfba1fa — Force enable_analyzer=1 in 04149_msan_join_optimizer_non_deterministic_filter

The PR-monitor cron flagged a 3/3-rerun failure of 04149_msan_join_optimizer_non_deterministic_filter in Stateless tests (amd_llvm_coverage, old analyzer, s3 storage, DatabaseReplicated, WasmEdge, parallel):

Code: 47. UNKNOWN_IDENTIFIER. Missing columns 'p' while processing
'SELECT p = 1'. While processing ((SELECT p = 1) AS _subquery306) AND
(rowNumberInAllBlocks() = 1).
... TreeRewriter::collectUsedColumns

The MSan/soundness fix lives entirely in the planner-based path (Processors/QueryPlan/Optimizations/); the old analyzer does not run those JOIN-conversion optimizers. It additionally rejects @PedroTadim's scalar-subquery reproducer shape WHERE (SELECT p = 1) AND ... in TreeRewriter::collectUsedColumns. So I forced the new analyzer for this whole test (SET enable_analyzer = 1; at the top), which matches every sibling JOIN-conversion regression test (03130, 03210, 03595, 03623, 04003).

Verification (local debug build):

  • 30/30 passes under --client-option=enable_analyzer=0 (old analyzer mode) with full random settings.
  • 30/30 passes under default (new analyzer mode) with full random settings.
  • Confirmed the failure in both directions: without the fix the test FAILS under old analyzer (the exact UNKNOWN_IDENTIFIER from CI); with the fix it passes.

CIDB cross-PR check confirmed the failure was isolated to PR #103880 — i.e. caused by our new regression test file under old analyzer.

513bb57e — Clarify non-deterministic-function comments in JOIN-conversion guards

Pure comment fix in Utils.cpp and convertAnyJoinToSemiOrAntiJoin.cpp per the bot review wording nit. The guard predicate is isDeterministicInScopeOfQuery, so now / today / currentUser (deterministic within a query) flow through and do NOT trip the bailout. The previous comments listed now alongside rand / rowNumberInAllBlocks in the per-row-variable group, which was misleading. Replaced with nowInBlock (genuinely per-row variable) and explicitly called out the in-scope-deterministic group.

No behavior change.

Branch tip: 513bb57e31d3. CI re-running.

@vdimir vdimir self-assigned this May 5, 2026

@alexey-milovidov alexey-milovidov 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.

Now it's LGTM.

@alexey-milovidov

Copy link
Copy Markdown
Member

@groeneai, update the branch to fix tests that were temporarily broken on master.

…filter

Pick up CI test fixes that were temporarily broken on master, per
@alexey-milovidov directive on PR ClickHouse#103880.

Issue: ClickHouse#100469
@groeneai

groeneai commented May 5, 2026

Copy link
Copy Markdown
Collaborator Author

@alexey-milovidov — branch updated with current master at 1c611db to pick up the CI test fixes. New PR HEAD: fabc9bd. CI is running on the merged HEAD now.

Session: cron:clickhouse-ci-task-worker:20260505-184500

@clickhouse-gh

clickhouse-gh Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 91.10% 91.10% +0.00%
Branches 76.60% 76.60% +0.00%

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

Full report · Diff report

@vdimir
vdimir added this pull request to the merge queue May 6, 2026
Merged via the queue into ClickHouse:master with commit bc601b5 May 6, 2026
325 of 326 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label May 6, 2026
ianton-ru pushed a commit to Altinity/ClickHouse that referenced this pull request Jul 13, 2026
…1499-4a82-msan-non-deterministic-filter

Fix MSan use-of-uninitialized-value in JOIN-conversion partial evaluation (issue ClickHouse#100469, STID 1499-4a82)
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.

MemorySanitizer: use-of-uninitialized-value (STID: 1499-4a82)

4 participants