Skip to content

Revert "Revert "Convert OUTER join to INNER join by null-rejecting join conditions" again" - #120130

Closed
alexey-milovidov wants to merge 1 commit into
masterfrom
revert-120119-revert-119305-convert-outer-to-inner-by-join-condition
Closed

alexey-milovidov wants to merge 1 commit into
masterfrom
revert-120119-revert-119305-convert-outer-to-inner-by-join-condition

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

Reverts #120119


Workflow [PR]
Sync PR [sync-upstream/pr/120130]

@clickhouse-gh

clickhouse-gh Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f1c1543]

Summary: ❌

job_name test_name status info comment
Stress test (arm_release) FAIL
Logical error: GroupingAggregatedTransform pushed bucket A twice (STID: 3994-4c1d) FAIL cidb

AI Review

Summary

This revert re-enables deriving planner-only IS NOT NULL filters from null-rejecting join predicates, using them to convert more OUTER joins to INNER joins and optionally execute selective filters. The overall direction looks reasonable, but the new derivation pass still has one correctness issue: it keys candidate inputs only by column name, which is ambiguous on join sides that legitimately carry duplicate names.

Findings

❌ Blockers

  • [src/Processors/QueryPlan/Optimizations/deriveNotNullFiltersFromJoin.cpp:19-20,64-80,158-180] The new pass records nullable join inputs in a NameSet and then adds isNotNull to every child-header input with that result_name. Query-plan headers can already contain duplicate names on one join side with different values; the surrounding planner code explicitly guards similar name-based rewrites in JoinStepLogical::canRemoveUnusedColumns (src/Processors/QueryPlan/JoinStepLogical.cpp:384-437), joinRuntimeFilter.cpp (src/Processors/QueryPlan/Optimizations/joinRuntimeFilter.cpp:348-357), and pushDownVolumeReducingFunctions.cpp (src/Processors/QueryPlan/Optimizations/pushDownVolumeReducingFunctions.cpp:460-462) for that reason. In this pass, a predicate that proves only one specific input non-NULL can therefore filter an unrelated duplicate column instead, changing row survival and making the later OUTER-to-INNER rewrite incorrect. Suggested fix: track derived columns by actual input identity/position end-to-end instead of String, or conservatively skip derivation on any side whose header duplicates one of the candidate names.
Final Verdict

Status: ⚠️ Request changes

Minimum required actions:

  1. Make deriveNotNullFiltersFromJoin unambiguous in the presence of duplicate input names on a join side.

LLVM Coverage Report

Measured on commit f1c1543.

Metric Baseline Current Δ
Lines 89.10% 89.10% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.50% 81.50% +0.00%

Changed lines: Changed C/C++ lines covered: 318/337 (94.36%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Sep 15, 2026
Comment on lines +74 to +80
for (const auto * input : dag.getInputs())
{
if (!columns.contains(input->result_name))
continue;

const auto & is_not_null_node = dag.addFunction(is_not_null, {input}, {});
conjuncts.push_back(&dag.addFunction(derived_filter_marker, {&is_not_null_node}, {}));

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.

This derivation is keyed only by result_name: collectColumnsThroughNullPropagatingFunctions stores candidate inputs in a NameSet, and this loop then adds isNotNull to every child-header input with the matching name.

That is not safe here. Query-plan headers can legitimately carry duplicate names on one side of a join, and nearby optimizations in this subsystem already treat name-based rewrites as ambiguous for that reason (JoinStepLogical::canRemoveUnusedColumns, joinRuntimeFilter.cpp, pushDownVolumeReducingFunctions.cpp). If the null-rejecting predicate only proves one specific nullable input non-NULL, this code will also filter any unrelated duplicate column with the same name, which can drop rows and make the later OUTER -> INNER conversion incorrect.

Please key the derived filters by input identity/position end-to-end, or conservatively bail out when the child header duplicates one of the candidate names.

@clickhouse-gh clickhouse-gh Bot added the comp-query-optimizer Query plan optimization: physical plan steps, plan-level rewrites and optimizations (QueryPlan pa... label Sep 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing f1c15437f with master 4f217e751 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 120c7491c; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

922 object files changed (+475.62 KiB total), 3 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Functions/FunctionPlannerOnlyFilter.cpp.o new 99.09 KiB +99.09 KiB
src/CMakeFiles/dbms.dir/Processors/QueryPlan/Optimizations/resolvePlannerOnlyFilters.cpp.o new 94.52 KiB +94.52 KiB
src/CMakeFiles/dbms.dir/Processors/QueryPlan/Optimizations/deriveNotNullFiltersFromJoin.cpp.o new 53.03 KiB +53.03 KiB

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline.

Job report

@m-selmi

m-selmi commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

@alexey-milovidov I re-implemented the same improvement with a completely different approach that will be less error prone #120253 (no more derived filter floating around that can affect other plan steps). So I will close this one for now.

@m-selmi m-selmi closed this Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-query-optimizer Query plan optimization: physical plan steps, plan-level rewrites and optimizations (QueryPlan pa... pr-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants