Repository navigation
Fix the missing WITH TOTALS row of a JOIN whose ON is constant false - #124134
Conversation
The constant-false ON short-circuit (ClickHouse#110234) replaces every input the join kind does not preserve with ReadNothing. No row of such an input reaches the output, but the join builds its totals row from the totals of both inputs (joinPipelinesRightLeft), and that stream does not go through ON. So a `WITH TOTALS` input lost its totals row (or got defaults for it) since 26.8. The pass now keeps an input whose plan can produce totals: TotalsHavingStep, ReadFromRemote whose shards send totals (stage Complete and a WITH TOTALS shard query, the predicate addPipe/addLazyPipe already used, now one helper), a query result cache hit whose pipe has totals, any of these in a nested plan the step owns (a SQL SECURITY DEFINER view), and ReadFromMerge, whose child plans are built on request and so are not inspected here. The walk stops below AggregatingStep and MergingAggregatedStep, which drop incoming totals, and does not ask LazyReadReplacingFinalStep (one source, no totals). Inputs without totals keep the fast path. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Remove the obvious doc comment on ReadFromRemote::hasTotals. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 findings; 1 full pass).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-49:20261006-022300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261006-012400 |
|
Workflow [PR], commit [5574c65] Summary: ✅
AI ReviewSummaryThe PR preserves Missing context / blind spots
Final VerdictStatus: ✅ Approve. No code changes requested; await the remaining CI results. |
…join-totals # Conflicts: # src/Processors/QueryPlan/ReadFromRemote.h
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes5 object files changed (+24.31 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units22 translation units recompiled, 196 s compile time in total, 22 of them have a recent master baseline.
|
…ult has totals On a subquery query cache hit, the Planner replaces the subquery plan, its `TotalsHaving` included, with a `ReadFromQueryResultCacheStep` whose pipe has a totals port when the cached entry has totals. `canProduceTotals` only knew `TotalsHavingStep` and the remote reads, so lazy materialization over joins was applied and the cached totals block reached the expression above the `LIMIT` without the lazily read column: the second run of a `LEFT JOIN` of a cached `WITH TOTALS` subquery threw NOT_FOUND_COLUMN_IN_BLOCK, while the first run (a miss, which still has `TotalsHaving` in the plan) was correct. Count a cache read whose pipe has totals as a totals source. A cache hit without totals keeps lazy materialization. The `hasTotals()` accessor is the same line as in ClickHouse#124134, which needs it for the constant-false join shortcut. Co-Authored-By: Claude Opus 5.5 <[email protected]>
26.10 does not include Formats/FormatSettings.h in StorageView.cpp, and does not have the GRANTs of #123729 in 05257_sql_security_view_sealed.sh, so only this PR's lines are added there. The test 05331_short_circuit_constant_false_join_totals (#124134) is not on 26.10, so this PR's change to it is dropped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #123702
Related: #110234
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a missing or wrong
WITH TOTALSrow of aJOINwhoseONcondition is constant false when an input that the join does not need to read produces totals. Appeared in 26.8 withquery_plan_short_circuit_constant_false_join.Description
On 26.8.18.2, this query returns no totals row instead of
0 0 6(the same query withquery_plan_short_circuit_constant_false_join = 0, or on 26.7):With totals on both inputs the totals row is
0 45 0 0instead of0 45 0 6.The constant-false
ONshort-circuit (#110234) replaces an input that the join kind does not preserve withReadNothing. No row of that input reaches the output, but the join builds its totals row from the totals of both inputs, andReadNothinghas none.The pass now keeps an input whose plan can produce totals: a
TotalsHavingstep, a remote read whose shard query hasWITH TOTALS, a query result cache hit with totals, the same inside a nested plan (aSQL SECURITY DEFINERview), or aMergetable (its child plans are not built here). It does not look below an aggregation, which drops the totals of its input. Everything else keeps the fast path.The new test covers LEFT, RIGHT, INNER, both inputs with totals, an aggregation over a
WITH TOTALSsubquery,remote()with and without totals, a sealed view,merge()and the query result cache; the expected output is the output of the same queries with the setting off.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/124134]
Version info
26.11.1.1567-master(included in26.11and later)