Repository navigation
Add a test (was: Re-resolve function types in buildFilterActionsDAG when argument types change during filter pushdown through JOIN) - #99278
Conversation
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
Workflow [PR], commit [e024891] Summary: ✅ AI ReviewSummaryThe current PR no longer contains the production fix described in its body; it only adds a stateless test. That test still uses PR Metadata
Findings
Tests
Final Verdict
|
| @@ -3402,12 +3402,44 @@ std::optional<ActionsDAG> ActionsDAG::buildFilterActionsDAG( | |||
| auto [arguments, all_const] = getFunctionArguments(function_children); | |||
| auto function_base = function_overload_resolver ? function_overload_resolver->build(arguments) : node->function_base; | |||
|
|
|||
| /// When input columns were replaced (e.g. equivalent USING columns pushed through JOIN), | |||
There was a problem hiding this comment.
We perform type correction while pushing filters down through JOIN in
https://github.com/ClickHouse/ClickHouse/blob/master/src/Processors/QueryPlan/Optimizations/filterPushDown.cpp#L677 , perhaps the bug is located there.
In general, we should be able to push down transformations introduced by JOIN into the filter without re-resolving functions. For example, if we have a filter a :: Nullable(Int) -> greater(a, 0), and before the JOIN a had type Int while toNullable was added by the JOIN, then we push down a :: Int -> toNullable(a) AS a -> greater(a, 0) so the greater function remains unchanged.
Is this issue reproducible only with query_plan_use_new_logical_join_step = 0? I believe we can remove this setting after the next LTS release, since it is currently supported only as a fallback in case the new logic has issues.
There was a problem hiding this comment.
Yes, it looks like it only happens with query_plan_use_new_logical_join_step = 0.
Not sure what will be the best solution if this code path is going to be removed soon. Maybe we should stop fuzzing it.
…AG.cpp` Adapted the type re-resolution fix to use master's new `addFunction(FunctionBasePtr, ...)` overload instead of the removed `addFunctionImpl` direct call. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Let's maybe rather disable |
When a JOIN uses USING on columns with different types (e.g., UInt16 vs UInt64), and the WHERE clause contains a function expression pushed into the join condition (e.g., `round(a.y, a.x) = b.y`), the server could crash with "Logical error: Unexpected return type from round". Root cause: During physical join construction, `getSubDAG` and `cloneSubdagWithInputs` extract per-side expression DAGs from the join's expression_actions. When the USING column is promoted to a common type, function nodes in the extracted DAG keep the promoted result_type and function_base. After merging with the actual stream header (which has the original non-promoted types), the function nodes have stale types that don't match their actual arguments, causing a type mismatch during header evaluation. Fix: Add `ActionsDAG::resolveFunctionTypes()` method that re-resolves function_base, result_type, and executable function for any FUNCTION node whose argument types differ from what function_base expects. Call it after DAG extraction in both `buildPhysicalJoinImpl` and `cloneSubdagWithInputs`. This is the same class of bug as PR ClickHouse#99278 (which fixes `buildFilterActionsDAG`) but in the physical join construction and runtime filter code paths. Closes ClickHouse#96101
|
Dear @vdimir, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
| -- See: https://github.com/ClickHouse/ClickHouse/issues/96101 | ||
|
|
||
| SET enable_analyzer = 1; | ||
| SET query_plan_use_new_logical_join_step = 0; |
There was a problem hiding this comment.
query_plan_use_new_logical_join_step is obsolete in the current tree (MAKE_OBSOLETE(..., true)), and the released behavior is that the logical join step is always used. So this line no longer forces the legacy JoinStep path that reproduced the Unexpected return type exception; the test can pass on the current JoinStepLogical path without proving the old failure mode. Please either remove this obsolete setting and update the comments/PR metadata to describe the active path being tested, or add a regression that still reaches a live code path for this issue.
LLVM Coverage Report
Changed lines: No C/C++ source files changed — skipping uncovered code analysis. Newly covered by added/modified tests: 334 line(s), 26 function(s) across 114 file(s) · Details Top files
|
Add a test (was: Re-resolve function types in buildFilterActionsDAG when argument types change during filter pushdown through JOIN)
Fix for "Logical error: Unexpected return type from A. Expected B. Got C. Action: (STID: 1611-3d11)"
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=99096&sha=607070210d48036cdfe476268ad0ba7fa9304144&name_0=PR&name_1=AST+fuzzer+%28amd_tsan%29
#99096
Related issues: #96101, #95678, #89802, #98337
Recent related change: Commit cdb778b ("Fix filter pushdown through legacy JoinStep with join_use_nulls", 2026-02-28) restored a type equality check in get_available_columns_for_filter for the legacy JoinStep path. However, that fix only guards the direct column availability path — it does not cover the equivalent USING column substitution path, which is where our bug occurs.
Reproduction
What happens
Fix:
In buildFilterActionsDAG's FUNCTION case, after building children from potentially-replaced nodes, compare the new argument types against the originals. If they differ, re-resolve the function via FunctionToOverloadResolverAdaptor::build to get the correct function_base and result_type.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix logical error in some cases during filter pushdown through JOIN
Documentation entry for user-facing changes
Note
Medium Risk
Touches expression DAG construction during filter pushdown, which can affect query planning/execution types across JOIN queries. Change is localized but could alter inferred result types for functions in edge cases.
Overview
Prevents
LOGICAL_ERRORtype mismatches during filter pushdown throughJOIN ... USINGby detecting when cloned function nodes inbuildFilterActionsDAGhave different argument types after input-column replacement and re-building the function to refreshfunction_base/result_type.Adds a stateless regression test covering
RIGHT JOIN+LEFT JOINwithUSINGand nullable/non-nullableidcolumns to ensureequals/filter functions remain type-consistent after pushdown.Written by Cursor Bugbot for commit c8e62f0. This will update automatically on new commits. Configure here.
Version info
26.7.1.1187(included in26.7and later)