Repository navigation
Conversation
… left Decorrelation of a correlated subquery builds a result JOIN. When the input stream is buffered in memory (correlated_subqueries_use_in_memory_buffer), the buffer's consumer (ReadFromCommonBuffer) may only read after the producer (SaveSubqueryResultToBuffer) has filled it. This holds only when the subquery input is on the build side of the result join, i.e. join_kind = right. For join_kind = left the input ends up on the probe side, so the consumer can start before the producer finished and aborts with: Logical error: Trying to extract chunk from ChunkBuffer before all inputs are finished The buffer-vs-materialize choice was derived from the optimizer flag correlated_subqueries_use_in_memory_buffer, which folds in the top-level correlated_subqueries_default_join_kind == right. That top-level value does not reflect the per-branch SETTINGS of a set operation (INTERSECT/UNION): a branch decorrelated as join_kind = left was still buffered because the outer plan was optimized with the default (right). Single-statement left queries materialized correctly; only set-operation branches with a per-branch left setting hit the bug. Decide materialization per decorrelation instead of from the global flag: a CommonSubplanReferenceStep built for a left-join decorrelation is flagged to be materialized, and is materialized before the buffer optimization regardless of the global setting. Producers that still have a buffered reference are kept. The right-join buffer path is unchanged.
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-3:20260623-072200 |
|
cc @novikd @KochetovNicolai — could you review this? It fixes the |
|
Workflow [PR], commit [6eef11f] Summary: ❌
AI ReviewSummaryThis PR fixes the Missing context / blind spots
Final Verdict✅ No inline findings to post. |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 50/53 (94.34%) | Lost baseline coverage: none · Uncovered code |
CI summary (head 6eef11f)CI finished. One test failure, not caused by this PR:
The Session id: cron:our-pr-ci-monitor:20260623-170000 |
|
Closing in favor of #108554, which fixes the same bug (ChunkBuffer LOGICAL_ERROR for #108554 forces the no-swap |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
Logical error: Trying to extract chunk from ChunkBuffer before all inputs are finishedfor correlated subqueries decorrelated withcorrelated_subqueries_default_join_kind = 'left'inside a set operation (INTERSECT/UNION) whencorrelated_subqueries_use_in_memory_buffer = 1.Description
Found by the AST fuzzer (
AST fuzzer (amd_debug, targeted)), STID2651-2cfd.Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108242&sha=fd6fd0abc33aecc2b385c994b2d87c98f53ed3b0&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%29
Decorrelation of a correlated subquery builds a result JOIN. When the subquery input is buffered in memory (
correlated_subqueries_use_in_memory_buffer), the buffer consumer (ReadFromCommonBuffer) may only read after the producer (SaveSubqueryResultToBuffer) has finished. That holds only when the input is on the build side of the result join, i.e.join_kind = right. Forjoin_kind = leftthe input is on the probe side, so the consumer can start before the producer finished and the query aborts with the logical error above.The buffer-vs-materialize choice was derived from the optimizer flag which folds in the top-level
correlated_subqueries_default_join_kind == right. That top-level value does not reflect the per-branchSETTINGSof a set operation, so a branch decorrelated asleftwas still buffered. Single-statementleftqueries materialized correctly; only set-operation branches with a per-branchleftsetting hit the bug.The fix decides materialization per decorrelation: a reference built for a
left-join decorrelation is flagged to be materialized (never buffered), independently of the global setting. Theright-join buffer path is unchanged.This is the surviving manifestation of the bug class from #96445 / #103322 (which fixed the join-size-limit / break-mode case); this PR fixes the
join_kind = leftordering case.A regression test asserts via
EXPLAIN PIPELINEthat aleft-join decorrelation branch no longer containsReadFromCommonBuffer, that theright-join branch still does, and that the query executes without the logical error.