Repository navigation
Conversation
collectFiltersForAnalysis replaces every table expression with StorageDummy, builds a plan, optimizes it, reads the pushed-down filters off its ReadFromDummy nodes and discards it. Its own comment says the plan is never executed, and three optimization flags are already turned off there for that reason. That optimize() call still ran the full second pass, so it also converted logical joins to physical ones: make_distributed_plan = false was the only thing that would otherwise have kept them logical (optimizeJoin.cpp, keep_logical = keep_logical_steps || make_distributed_plan). The right table's storage identity is captured while the plan is built, via tryGetStorageInTableJoin for a StorageJoin, a non-Range StorageDictionary or any IKeyValueEntity, and via tryMakeDirectJoinWithMergeTree for a MergeTree table; choosing a physical join is where its absence becomes fatal, because direct is the only algorithm whose candidate depends on it. The dummy replacement had just erased exactly that, so with join_algorithm = 'direct' the candidate loop ended empty and chooseJoinAlgorithm threw NOT_IMPLEMENTED out of a plan nobody was going to run. With the default join_algorithm list the loop falls through to hash in the throwaway plan and nothing is observable, which is why only a list whose every entry is storage-dependent surfaces this. Keeping that plan's joins logical fixes the whole family rather than one case: all four right-table kinds direct accepts were refused, and both ways of requesting filter collection reached it, the parallel-replicas row estimation under a non-zero parallel_replicas_min_number_of_rows_per_replica and a plain Distributed table with parallel replicas off entirely. Filter collection itself is unaffected: push-down is implemented for JoinStepLogical directly and runs in the first pass, and the passes skipped in the dummy plan are execution-shape optimizations that cannot change ReadFromDummy's collected filter. Checked rather than assumed, since a plan that collects nothing would also throw nothing, and checked with a join in the query, since without one this change has nothing to do and both builds are trivially equal: a selective filter on the left table still estimates one granule instead of the whole table and still leaves parallel replicas off, identically before and after, while a build with filter collection stubbed out fails that same check. Shard skipping is unchanged, and 220 tests across the shard-skipping, index-analysis, parallel-replicas and prewhere families are identical before and after. The new test pins the setting that reaches each route instead of drawing it, and asserts DirectKeyValueJoin is still chosen so a silent fall back to another algorithm cannot pass it. Its third arm asserts the estimate stays selective, so the filters cannot silently stop being collected either; that arm is green before the fix as well, which is what a non-regression lock should be. Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review (2 rounds, 9 findings adjudicated)Independent cold review of the resulting code plus a stateful second-model gate on each round,
Three things the review verified rather than took on trust, reported because they are what a reviewer
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20260921-005100 |
|
Workflow [PR], commit [6dfb162] Summary: ✅
AI ReviewSummaryThis PR keeps the filter-collection dummy plan from converting logical joins to physical joins, which avoids the spurious Missing context / blind spots
Final Verdict✅ No new blockers or majors in the current PR head. No new inline review comments were necessary. LLVM Coverage ReportMeasured on commit 6dfb162.
Changed lines: Changed C/C++ lines covered: 5/5 (100.00%) · Uncovered code |
convertLogicalJoinToPhysical is called from two places in optimizeTreeSecondPass. The main traversal calls it only when enable_parallel_replicas is off; with plan-based parallel replicas on, the joins are deliberately left logical there so applyParallelReplicas can clone a fragment, and a deferred pass converts whatever stayed in the outer plan afterwards. keep_logical_steps returns early at both, but the three arms shipped so far only reached the first: none of them pinned parallel_replicas_plan_based, and it is not one of the settings the test runner randomizes, so the deferred call site had no coverage at all. The setting reaches the filter-collection plan because that plan's optimization settings are built from the original query context, not from the copy its own tree carries. Measured on the base binary, the two routes throw from different lines of optimizeTreeSecondPass: the existing arm A from the main traversal, and the new arm from the deferred pass. Both new assertions fail with Code 48 NOT_IMPLEMENTED before the fix, measured one client invocation each so neither rides on the other's abort. The arm also repeats the filter-collection check in that mode, because plan-based is the one mode where applyParallelReplicas runs on the throwaway plan as well. It cannot rewrite it: it acts only through split markers, insertParallelReplicasSplit plants those above the MergeTree reads collectReadsToDistribute finds, and the dummy replacement leaves none, so it returns before planting any. Those two rows are green before the fix as well, which is what a non-regression lock should be; a build with collectFiltersForAnalysis stubbed out fails them, and it fails exactly them and arm C's pair, so they are not vacuous. Test only, no source change. 50 runs twice with randomization on, plus the 05211 carrier. Co-Authored-By: Claude Opus 5 <[email protected]>
CI finish ledger - 18d8a5eEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
156 checks succeeded, 18 were skipped, Session id: cron:our-pr-ci-monitor:20260921-103829 |
vdimir
left a comment
There was a problem hiding this comment.
It seems the fix is specific to parallel replicas, and the PR title does not indicate that.
|
Not specific to parallel replicas. The throwaway plan is built whenever the planner has to collect pushed-down filters before planning for real, and Measured on this PR's base and on its head, with parallel replicas off in every setting: CREATE TABLE l_local (k UInt64) ENGINE = MergeTree ORDER BY k;
CREATE TABLE l_dist AS l_local ENGINE = Distributed(test_shard_localhost, currentDatabase(), l_local);
CREATE TABLE r (k UInt64, v String) ENGINE = MergeTree ORDER BY k;
INSERT INTO l_local SELECT number FROM numbers(100);
INSERT INTO r SELECT number, toString(number) FROM numbers(1000);
SELECT count() FROM l_dist AS t0 INNER JOIN r AS t1 ON t1.k = t0.k
SETTINGS enable_analyzer = 1, join_algorithm = 'direct', query_plan_join_swap_table = 0,
enable_parallel_replicas = 0, parallel_replicas_min_number_of_rows_per_replica = 0,
prefer_localhost_replica = 1;Base throws The title named no trigger at all, which was worth fixing regardless: it is now "Fix NOT_IMPLEMENTED for a direct join with parallel replicas, a Distributed table or a View", and the changelog entry and description now name |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
NOT_IMPLEMENTED(None of the algorithms enabled by the 'join_algorithm' setting [direct] can execute this ALL INNER JOIN with the given right table storage type) for a query withjoin_algorithm = 'direct'that also makes the planner collect filters before planning, which happens when the query reads aDistributedtable or aView, or setsparallel_replicas_min_number_of_rows_per_replica.Description
Related: #71028 (comment)
Related: #119861
collectFiltersForAnalysisreplaces every table withStorageDummy, optimizes the plan, reads the pushed-down filters off itsReadFromDummynodes and throws it away; its own comment says it "is never executed". Thatoptimize()still ran the full second pass, so it also picked physical joins.directis the only algorithm whose candidate depends on the right table's real storage, and that storage is captured while the plan is built (tryGetStorageInTableJoin,tryMakeDirectJoinWithMergeTree) from the tables the dummy replacement had just erased, sochooseJoinAlgorithmhad nothing left to offer it. With any other list the loop falls through tohash, which is why onlydirectsurfaces it. The fix keeps that plan's joins logical, next to the three flags already turned off there for the same reason.This is not parallel-replicas-specific: a
Distributedtable or aViewreaches the same route withenable_parallel_replicas = 0. Four of the right-table kinds it accepts (MergeTree,Join, dictionary,EmbeddedRocksDB) failed before and succeed now.The reported repro fails 100% before and passes after; the new test pins the settings reaching each trigger. A plan that collects nothing would also throw nothing, so I checked collection still happens: push-down is implemented for
JoinStepLogicalandapplyFiltersruns before any join is physicalized, so the skipped conversion cannot reachReadFromDummy's filter. Measured on a joined query, the only shape this can affect: the filtered side still estimates one granule (8192 rows) instead of 1000000 and uses no replicas, identically before and after, while a build with collection stubbed out fails that check. The test carries that as a third arm, and a 220-test sweep over the consuming families is unchanged.Stack trace, which locates the throw inside the filter-collection plan
Frame 11 is
result_query_plan.optimize(optimization_settings), three lines under the comment/// This plan collects pushed-down filters and is never executed.Workflow [PR]
Sync PR [sync-upstream/pr/121256]