Repository navigation
Description
Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment.
Retrospective finding from a historical scan of PR #84145 (merged 2025-07-25). Confirmed on current codebase — close with a note if already fixed.
Describe what's wrong
When a WHERE clause has multiple AND-ed equalities and at least one has matching types (pushed into JOIN) while another has mismatched types, the mismatched-type equality is silently dropped from the filter, producing wrong results (extra rows).
Root cause: mergeFilterIntoJoinCondition.cpp:181-182: continue skips both the push-down AND the rejected_conjuncts.push_back(conjunct) at line 196. When other conjuncts ARE pushed, the filter predicate is reconstructed from rejected_conjuncts only, losing the type-mismatched one.
Why we believe this is a bug: extractActionsForJoinCondition (mergeFilterIntoJoinCondition.cpp:172-197) → type mismatch at line 181 triggers continue → conjunct not added to rejected_conjuncts → trivial_filter=true at line 199 → FilterStep removed entirely at line 312-317
Affected locations:
src/Processors/QueryPlan/Optimizations/mergeFilterIntoJoinCondition.cpp:182— continue after type mismatch skips rejected_conjuncts collection
Impact: Silent wrong results: queries with JOIN and WHERE containing both type-matched and type-mismatched equalities return extra rows that should be filtered out. Default-enabled optimization (query_plan_merge_filter_into_join_condition=true).
Does it reproduce on most recent release?
Yes — confirmed on current master (commit 64b0a83ca8c9).
How to reproduce
-- Test: type-mismatched equality conjunct dropped when another conjunct pushed into JOIN
SET enable_analyzer = 1;
SET enable_parallel_replicas = 0;
SET query_plan_merge_filter_into_join_condition = 1;
-- t1.a (UInt8) = t2.c (UInt8): types match, pushed into JOIN
-- t1.b (UInt8) = t2.d (Int64): types DON'T match, should stay in filter
-- If the type-mismatched conjunct is dropped, we get a row; correct is 0 rows.
SELECT *
FROM (SELECT 1 AS a, 1 AS b) AS t1
JOIN (SELECT 1 AS c, toInt64(0) AS d) AS t2
ON true
WHERE t1.a = t2.c AND t1.b = t2.d
ORDER BY ALL;Expected behavior
(empty - no rows, since 1 != 0)
Error message and/or stacktrace
1 1 1 0
Additional context
Open risks:
- Any other
continuepaths inside the is_equality block that skip rejected_conjuncts would have the same issue, but currently only the type-mismatch path does this
Suggested fix: Change continue to fall through to rejected_conjuncts.push_back(conjunct). Either remove the continue or add rejected_conjuncts.push_back(conjunct); continue; before/at line 182.
Analysis details: Confidence HIGH | Severity P0 | Testability: STATELESS_SQL
Found during automated review of PR #84145.
ClickGapAI · Confidence: HIGH · Severity: P0 · Finding: h_pr84145_001
Version info
- Resolved by: Fix incorrect JOIN results caused by silently dropped WHERE filters #101652
- Merged into:
26.5.1.239
Activity