Skip to content

Fix logical error in correlated subquery decorrelation with set operations - #108554

Merged
alexey-milovidov merged 26 commits into
ClickHouse:masterfrom
groeneai:fix-chunkbuffer-correlated-subquery-left-join
Aug 4, 2026
Merged

alexey-milovidov merged 26 commits into
ClickHouse:masterfrom
groeneai:fix-chunkbuffer-correlated-subquery-left-join

Conversation

@groeneai

@groeneai groeneai commented Jun 25, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix a LOGICAL_ERROR ("Trying to extract chunk from ChunkBuffer before all inputs are finished") when a set operation (INTERSECT / UNION ALL / EXCEPT) combines branches that use correlated subqueries and correlated_subqueries_default_join_kind = 'left'.

Description

Closes: #108521

A set operation over correlated subqueries shares the input subplan through an in-memory buffer (SaveSubqueryResultToBuffer writes, ReadFromCommonBuffer reads). The reader must run after every writer stream finished, which only JoinKind::Right guarantees. The decorrelation join used correlated_subqueries_default_join_kind to pick the layout, so 'left' could place the reader before the writer and abort the server.

Fix: when the referenced input is buffered, force the JoinKind::Right (no-swap) layout. The join kind is an internal detail and does not change the result. Whether a buffer is created is decided once from the top-level query context, so the layout reads the setting from there too; this covers correlated_subqueries_use_in_memory_buffer = 0 placed in a per-branch SETTINGS clause, which still creates a buffer.

This is a pre-existing trunk bug (allow_experimental_correlated_subqueries is on by default in 26.6); it recurs on master under the AST fuzzer (STID 2651-2cfd). Reproducer:

CREATE TABLE t (i Int32) ENGINE = MergeTree ORDER BY i SETTINGS index_granularity = 1;
INSERT INTO t SELECT number FROM numbers(5);
INSERT INTO t SELECT number FROM numbers(5);   -- 2 parts

SELECT i FROM t WHERE 8 = ((SELECT _part_offset) + i)
  SETTINGS correlated_subqueries_substitute_equivalent_expressions = 0,
           correlated_subqueries_default_join_kind = 'left'
INTERSECT
SELECT i FROM t WHERE 8 <=> (i + (SELECT _part_offset));

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108242&sha=fd6fd0abc33&name_0=PR (STID 2651-2cfd).

Regression test: 04411_chunk_buffer_correlated_subquery_set_operation.

…tions

A set operation (INTERSECT / UNION ALL / EXCEPT) whose branches reference
correlated subqueries shares the input subplan through an in-memory
producer/consumer buffer: SaveSubqueryResultToBuffer fills it and
ReadFromCommonBuffer reads it, and the consumer may only run once every
producer stream has finished.

The decorrelation result join in buildLogicalJoin was built using
correlated_subqueries_default_join_kind. With 'left' the buffer producer
(the input stream) ended up on the join's probe side, so when a set
operation placed the consumer on the build side of an enclosing join the
consumer read the buffer before the producer finished and the server
aborted with:

  Logical error: Trying to extract chunk from ChunkBuffer before all inputs
  are finished

Keep the buffered (referenced) input on the build side regardless of the
requested join kind, so the producer is always fully evaluated first. The
decorrelation join kind is an internal detail and does not change the
result.

Closes: ClickHouse#108521

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. CREATE TABLE t (i Int32) ENGINE=MergeTree ORDER BY i SETTINGS index_granularity=1; + two INSERT ... numbers(5) (two parts), then the INTERSECT of two correlated branches with correlated_subqueries_default_join_kind='left' aborts the server every time on master.
b Root cause explained? A set operation shares the correlated input subplan via a producer/consumer buffer (SaveSubqueryResultToBuffer -> ReadFromCommonBuffer); the consumer asserts all producer streams finished. buildLogicalJoin chose the join layout from correlated_subqueries_default_join_kind. With 'left' the buffered producer lands on the join probe side while a set-operation places the consumer on an enclosing join's build (FillRightFirst) side, so the consumer reads the buffer before the producer finished -> LOGICAL_ERROR.
c Fix matches root cause? Yes. When the referenced input is buffered (referenced_input_subplan && correlated_subqueries_use_in_memory_buffer), keep the build-side (no-swap, JoinKind::Right) layout so the producer is fully evaluated before the consumer reads. Targets the ordering mechanism directly; not a band-aid.
d Test intent preserved / new tests added? New regression test 04411_chunk_buffer_correlated_subquery_set_operation (INTERSECT / UNION ALL, left and right kinds). No existing test weakened; existing correlated-subquery plan-reference tests (e.g. 03701, 03595) are unchanged because materialized single-reference subqueries keep their original LEFT plan.
e Both directions demonstrated? Yes. On a rebuilt unfixed binary the reproducer/new-test query aborts the server; with the fix the new test passes 30/30 with full randomization and returns the correct rows.
f Fix is general across code paths? The decorrelation result join is built in one place (buildLogicalJoin), used by both SCALAR and EXISTS correlated subqueries; both call sites are covered. INTERSECT, UNION ALL and EXCEPT triggers all verified fixed.
g Fix generalizes across inputs (params/datatypes/wrappers)? The fix is on the internal join layout, independent of column type; verified with same-expression and different-expression branches, single vs multiple parts, and both join-kind settings.
h Backward compatible? (maintainer-approved exception only) Yes. Only the internal decorrelation join layout changes; the query result is unchanged (verified 'left' vs 'right' produce identical results). No setting default, on-disk/wire format, or user-visible behavior changes.
i Invariants and contracts preserved? Yes. Upholds the ChunkBuffer producer-before-consumer ordering contract. The HASH-only + setOptimized() protection (previously applied to the Right+buffer case) now consistently applies to the buffered case, so the buffer producer stays on the build side and join reordering cannot violate the ordering.

Session id: cron:clickhouse-worker-slot-3:20260625-195800

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @novikd @vdimir — could you review this? It fixes the Trying to extract chunk from ChunkBuffer before all inputs are finished LOGICAL_ERROR (issue #108521) by keeping the buffered correlated-subquery input on the join build side when correlated_subqueries_default_join_kind='left', so the buffer producer is fully evaluated before ReadFromCommonBuffer reads it. The decorrelation join kind is internal and the change does not affect results.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jun 25, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ab032c8]

Summary: ✅


AI Review

Summary

This PR hardens correlated-subquery decorrelation when set-operation branches share the outer input through a ChunkBuffer: it tracks the buffer decision across the relevant contexts, forces buffered cases onto the safe RIGHT/hash-only layout, and adds focused regression coverage for INTERSECT, UNION ALL, EXCEPT ALL, setting placement, and survivor-less join_algorithm lists. I did not find a remaining correctness blocker in the current code, but one user-facing docs nit remains.

Findings

💡 Nits

  • [dismissed by author -- https://github.com/Fix logical error in correlated subquery decorrelation with set operations #108554#discussion_r3672732055] [src/Core/Settings.cpp:6654-6655] correlated_subqueries_use_in_memory_buffer is still documented as a plain on/off switch even though the current code and 04411_chunk_buffer_correlated_subquery_set_operation prove that SETTINGS correlated_subqueries_use_in_memory_buffer = 0 on a branch can still leave buffering enabled when another context would buffer. The new note on correlated_subqueries_default_join_kind explains the forced layout after buffering exists, but not this setting's own placement-sensitive behavior. Suggested fix: add one sentence here (or reject unsupported placement) clarifying that buffer creation is decided conservatively across local/top-level contexts, so a nested or branch-local = 0 may not disable buffering.
Final Verdict

✅ No blocking issues in the current patch; the remaining concern is the non-blocking docs clarification above.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.50% 86.50% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.70% 78.70% +0.00%

Changed lines: Changed C/C++ lines covered: 42/42 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 25, 2026
…gression test

The reviewer asked to also cover the use_in_memory_buffer = 0 variant named in
issue ClickHouse#108521. With the buffer disabled the optimizer's materialization pass
(materializeQueryPlanReferences) inlines the shared subplan reference before
useMemoryBufferForCommonSubplanResult runs, so no ChunkBuffer is created and the
ordering invariant cannot be violated. The added queries assert that the
disabled-buffer variant returns the same rows as the buffered case, and pin
enable_parallel_replicas = 0 (as the sibling decorrelation test 03734 does) so
the per-part _part_offset row counts stay deterministic under CI randomization.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI note: the 03583_rewrite_in_to_join failures here (Fast test / amd_tsan / arm_binary) are a pre-existing flaky test, not caused by this PR (it failed across 6 unrelated PRs in 30d, 0 on master). Root cause: the test's data SELECTs lacked ORDER BY, and with rewrite_in_to_join the IN/NOT IN subquery becomes a parallel LEFT JOIN with nondeterministic row order. Fixing PR: #108561.

This PR forces JoinKind::Right for buffered correlated-subquery
decorrelation (the ChunkBuffer ordering fix). The decorrelation join
kind is an internal detail, but it changes the build side of the join,
so the row order of these IN->JOIN rewrite results (which had no
ORDER BY) is no longer guaranteed and the test became flaky under
parallel execution.

Add ORDER BY number to the multi-row result queries. The verified
result values are unchanged (the .reference numeric output is identical,
only the echoed SQL lines gain the ORDER BY clause); only the row order
is now deterministic. This also fixes the test's pre-existing
non-determinism, which already failed under randomized max_block_size
on master regardless of this PR.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Follow-up after the 03583_rewrite_in_to_join Fast test failure on the previous head (7fb7861d2cf). That failure was caused by this PR forcing JoinKind::Right for buffered decorrelation, which flips the join build side and changed the (unspecified) row order of the IN->JOIN rewrite results. Fixed by adding ORDER BY number to the multi-row queries in 03583. Updated pre-PR validation gate for head bdbb85719cf:

Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. On the fixed binary the old (no-ORDER-BY) 03583 fails 80/80 at --max_threads=6 --max_block_size=1; the row order differs from the LEFT-based reference.
b Root cause explained? This PR's buffered_input gate forces JoinKind::Right, changing the join build side (FillRightFirst). For 03583's IN->JOIN queries (no ORDER BY) the natural emission order then depends on parallel scheduling, so under randomized max_threads/max_block_size the output reorders -> echo-mode diff vs reference.
c Fix matches root cause? Yes. The result row order was never contractually guaranteed (no ORDER BY); the join-kind change is result-equivalent. The fix makes the order deterministic with ORDER BY number rather than weakening or reverting the engine fix.
d Test intent preserved / new tests added? Yes. The .reference numeric result values are byte-for-byte identical (49 result lines, same values, same positions); only the echoed SQL lines gain ORDER BY number. The test still verifies exactly which IN->JOIN rewrite results are produced. (The crash regression test is the separate 04411 added in this PR.)
e Both directions demonstrated? Yes. Old test (no ORDER BY) on fixed binary: 80/80 FAIL. New test (ORDER BY) on fixed binary: 0 FAIL / 450 runs across max_threads={1,3,6,8,16} x max_block_size={1,2,65505}. New test on a master-baseline binary (without this PR): 0 FAIL / 240 runs -> the ORDER BY also fixes the test's pre-existing non-determinism (it already failed under randomized max_block_size on master).
f Fix is general across code paths? N/A for this commit (test-only ORDER BY change). The engine fix in PlannerCorrelatedSubqueries.cpp is unchanged.
g Fix generalizes across inputs? N/A (test-only change).
h Backward compatible? N/A (test-only change).
i Invariants and contracts preserved? N/A (test-only change). Verified no regression across the correlated/in-to-join suite (43 tests); plan-reference tests 03701/03595/03545* untouched by the scoped correlated_subqueries_use_in_memory_buffer gate.

Session id: cron:clickhouse-worker-slot-2:20260626-003900

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — bdbb857

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stress test (arm_asan_ubsan, s3) / Logical error "Equal values are not contiguous within the range assumed to be sorted" (STID 2508-4156) trunk ColumnString sort-assertion (added by #106502); fired via a streaming DISTINCT-in-order read producing commit-order (unsorted) data; unrelated to this correlated-subquery planner diff (2 PRs/0 master) #108568 (ours, open)
Upgrade check (amd_release) / Error message in clickhouse-server.log DatabasePostgreSQL background-pool connection-error spam to RFC-5737 test host 192.0.2.1 (seeded by stateless test 04210), unrelated to this PR #108560 (ours, open)
Stress test (amd_asan_ubsan) / AddressSanitizer global-buffer-overflow (STID 5294-6591) latent vendored contrib/azure SDK Base64Decode signed-char OOB on the int8_t[256] decode table during SharedKeyPolicy::GetSignature; chronic (4 unrelated PRs/0 master), unrelated to this PR a fix task is created (investigating at full effort; fixing-PR link to follow here)
CH Inc sync — CH Inc sync (private, not actionable by us)

Session id: cron:our-pr-ci-monitor:20260626-050000

@novikd novikd self-assigned this Jun 26, 2026
groeneai added 2 commits June 30, 2026 11:27
…related-subquery-left-join

# Conflicts:
#	tests/queries/0_stateless/03583_rewrite_in_to_join.reference
#	tests/queries/0_stateless/03583_rewrite_in_to_join.sql
The previous fix read correlated_subqueries_use_in_memory_buffer from the
per-branch planner context to decide buffered_input. The optimizer, however,
decides buffer-vs-materialize once for the whole plan from the top-level query
context (QueryPlanOptimizationSettings: use_in_memory_buffer && default_join_kind
== RIGHT). A set-operation branch's own SETTINGS clause never reaches that pass,
so when a branch set correlated_subqueries_use_in_memory_buffer = 0 the join was
built with buffered_input == false (plain LEFT layout, ordering protection
skipped) while the optimizer still created a ChunkBuffer, re-triggering the
"Trying to extract chunk from ChunkBuffer before all inputs are finished"
LOGICAL_ERROR from issue ClickHouse#108521.

Mirror the optimizer's condition exactly: read the setting from the top-level
query context (reachable via Context::getQueryContext()) and require
default_join_kind == RIGHT, so the safe Right (no-swap) layout and the hash-only
ordering protection fire whenever a buffer is actually created, regardless of how
the setting was applied. Session-level use_in_memory_buffer = 0 reaches the
materialization pass, no buffer is created, and the plain LEFT layout is kept
(so 03701 is unaffected).

Extend 04411 to cover the per-branch SETTINGS form from ClickHouse#108521 in addition to
the session-level and default forms.

Closes ClickHouse#108521
@vdimir

vdimir commented Jun 30, 2026

Copy link
Copy Markdown
Member

@groeneai could you make comment in the PR a bit more straightforward and short so it's easier to read. It should not be ad-hoc comments to justify workarounds, only necessary ones to document tricky logic, otherwise change should have clear purpose

Shorten the buffered_input comment in buildLogicalJoin and the 04411 test
header to document only the tricky logic (the layout must follow the
top-level buffer decision); the mechanism and motivation are in the commit
message and PR description. No behavior change.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

@vdimir done. Trimmed the in-code comments in buildLogicalJoin and the 04411 test header to just the invariant (the decorrelation layout must follow the top-level buffer decision); the mechanism and motivation now live in the commit message and PR description. Also shortened the PR description and dropped a stale note that the previous push had already made obsolete. No behavior change (752479d).

Decide once, in decorrelateQueryPlan, whether the referenced input
subplan will be turned into an in-memory ChunkBuffer, and pass that
decision to buildLogicalJoin instead of re-deriving it from settings
there.

The optimizer buffers the referenced subplan when the top-level query
context has correlated_subqueries_use_in_memory_buffer = 1 and
correlated_subqueries_default_join_kind = RIGHT
(QueryPlanOptimizationSettings). buildLogicalJoin previously re-read
those settings to decide the join layout; a set-operation branch's own
SETTINGS clause changes the per-branch reads but never reaches the
top-level buffer decision, so the two could disagree and the layout
could skip the JoinKind::Right protection while a buffer was still
created, re-triggering the ChunkBuffer "before all inputs are finished"
logical error (issue ClickHouse#108521).

Recording the decision at its source (alongside referenced_input_subplan,
reading the top-level context the optimizer uses) keeps the layout and
the buffer in sync for every placement of the setting.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 72f94a3

Every failure below has an owner: a fixing PR (ours or external), or the private sync check. No PR-caused failures (this PR's diff is src/Planner/PlannerCorrelatedSubqueries.cpp for the correlated-subquery set-operation decorrelation fix; none of the failures touch that path).

Check / test Reason Owner / fixing PR
AST fuzzer (amd_debug) / Logical error 'Unexpected expression in JOIN ON section ... got Nothing' (STID 4699-47ff) Nothing-typed JOIN ON residual predicate (chronic trunk; 10 unrelated PRs/30d) #106981 (ours, open, approved)
Stateless tests (amd_debug, parallel) / 02875_parallel_replicas_cluster_all_replicas flaky Code-102 connection-pool ProfileInfo desync (CI diagnosis 181/181 reruns pass; #93018 family) #108854 (external, open)
Stress test (amd_tsan) / Hung check failed, possible deadlock found deadlock (chronic, not PR-caused) #108212 (ours, merged) / #105905 (ours, open)
Stress test (arm_tsan) / Hung check failed, possible deadlock found deadlock (chronic, not PR-caused) #108212 (ours, merged) / #105905 (ours, open)
Upgrade check (amd_release) / Error message in clickhouse-server.log (MutatePlainMergeTreeTask throwIf Code 395) benign background-mutation error replayed on upgrade restart, caught by the log scan (chronic, not PR-caused) #108651 (ours, open)
CH Inc sync - CH Inc sync (private, not actionable)

Session id: cron:our-pr-ci-monitor:20260630-203000

@alexey-milovidov alexey-milovidov self-assigned this Jul 31, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@alexey-milovidov

Copy link
Copy Markdown
Member

@groeneai, please update the branch, as all the fixes for unrelated failures are merged.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Branch updated: merged master (59f0c881f808) into da3d8953896a, no rebase and no force-push. The merge was clean and the PR diff is still the same 4 files.

Both fixes for the reds the last ledger recorded are now ancestors of the new head: #112385 (01666_merge_tree_max_query_limit) and #112500 (test_jbod_load_balancing_least_used_next_disk). I will post the CI ledger for this head once the run finishes.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - da3d895

Every failure below has an owner: a fixing PR, or a full-effort fix task whose fixing-PR link will be
posted here when it opens. Neither failure is caused by this PR (its diff is the planner correlated-subquery
buffer protection plus its test).

Check / test Reason Owner / fixing PR
Stateless tests (amd_debug, parallel) / 04611_join_runtime_filters_index_analysis_skip_index randomization: the diagnosis runner reports Runs: 95, Failed: 95 with the same settings and Runs: 140, Failed: 0 without, culprit --join_runtime_filter_min_probe_rows 5155 #111691 (external, merged 2026-07-31T20:56:13Z) - the pin was absent from this build, so I merged master to pick it up @ 06ffae7
Fast test (arm_darwin) job-level ERROR: the run stops at test 11013/13008 and the job is recorded failed ~18 minutes later, with no Server died, no signal and no test row in the report a fix task is created (investigating at full effort - fixing PR link to follow on this PR)
Sync - CH Inc sync (private, not actionable by me)

On the arm_darwin line: #112267 is not its owner. That fix is already present in this build
(base/darwin-compatibility exists at da3d895), so per my own rule a merged fix that is already on the
branch cannot own a failure that still fires. Of the five red arm_darwin runs since #112267 merged, three
predate it (those are its) and two carry it, including this one.

Session id: cron:our-pr-ci-monitor:20260731-230000

@groeneai

groeneai commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 06ffae7

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Fast test (arm_darwin) / 03312_squashing_with_low_card_mem_usage macOS runner disk exhaustion: Code: 243 ... Cannot reserve 317.63 MiB, not enough space. (NOT_ENOUGH_SPACE) raised from MergeTreeData::reserveSpacePreferringTTLRules on a numbers_mt(5e6) insert a fix task is created (investigating at full effort - fixing-PR link to follow here)
Fast test (arm_darwin) / 03826_calculate_subcolumn_size_during_merge_tree_read same runner, same error: Code: 243 ... Cannot reserve 380.45 MiB, not enough space. on a 1M-row JSON insert a fix task is created (investigating at full effort - fixing-PR link to follow here)

Neither test is in this PR's diff, which is 4 files confined to correlated-subquery planning, and neither exercises that code path. A 7 day CIDB sweep keyed on NOT_ENOUGH_SPACE returns 5 rows on a single runner at a single instant with 0 master hits, so this is one macOS runner filling its disk rather than a per-test defect. Note also that this job's log truncates at test 10885 of 13047 with no Server died, no signal and no sanitizer report, so the remaining tests did not run; that is recorded on the same fix task.

The other 173 checks are green (155 success, 18 skipped) and both aggregators, Config Workflow and Finish Workflow, completed successfully.

Session id: cron:our-pr-ci-monitor:20260801-073000

@clickhouse-gh

clickhouse-gh Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.50% 86.50% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.70% 78.70% +0.00%

Changed lines: Changed C/C++ lines covered: 40/40 (100.00%) · Uncovered code

Full report · Diff report

@groeneai

groeneai commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 409f58e

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stress test (arm_debug) / Query context must be created after authentication (STID 3197-391f) trunk bug: pre-auth query context on the PostgreSQL wire port, not reachable from this diff a fix task is moved to pending (investigating at full effort, fixing-PR link to follow here)
Stress test (arm_asan_ubsan, s3) / Query context must be created after authentication (STID 3197-391f) same trunk bug, second build flavour a fix task is moved to pending (investigating at full effort, fixing-PR link to follow here)

Session id: cron:our-pr-ci-monitor:20260801-230000

@groeneai

groeneai commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author

Fixing PR for the pre-auth Query context must be created after authentication abort in the Stress test (*) failures ledgered above: #112940.

That PR reapplies #110760 (reverted in #112935) together with the fix: PostgreSQLHandler::cancelRequest no longer builds a query context from the unauthenticated session, cancelling through the new ProcessList::sendCancelToQueryOfAnyUser instead. Verified at its head bfc13929ce68df79, where the signature no longer appears in CIDB while the same Stress flavours ran.

…decorrelation join

The buffered path filtered the internal decorrelation join's `join_algorithms`
down to `hash` / `parallel_hash`, but never inserted one. With a user
`join_algorithm` of `auto` or a merge-only list nothing survived the filter and
`chooseJoinAlgorithm` threw `NOT_IMPLEMENTED` (`Can't execute any of specified
algorithms...`), so the reproducer from ClickHouse#108521 was still user-visibly broken
for a supported setting combination.

This join is an internal decorrelation detail, so the public setting must not
decide whether it can run at all: force `hash` / `parallel_hash` when the filter
leaves the list empty.

Extend `04411_chunk_buffer_correlated_subquery_set_operation` with the
`join_algorithm = 'auto'` and merge-only (`full_sorting_merge`) cases, asserting
the same rows and the same forced RIGHT layout.
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Aug 3, 2026
The commit 5bcd0e3 was meant to touch only `PlannerCorrelatedSubqueries.cpp`
and the `04411_chunk_buffer_correlated_subquery_set_operation` test, but it also
swept in 54 unrelated untracked files from the worktree (including a 21 MB binary
test artifact). None of them exist on master; this removes them all, restoring
the intended 4-file PR diff.

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 The previous commit 5bcd0e30c9d (the join_algorithm empty-list fix) accidentally swept 54 stray untracked files from the worktree into the PR, including a 21 MB binary test artifact. Commit ab032c89b84 removes them all; the PR diff is back to the intended 4 files (src/Planner/PlannerCorrelatedSubqueries.cpp, src/Core/Settings.cpp, and the 04411 test pair). The fix itself and its join_algorithm = 'auto' / full_sorting_merge regression coverage are unchanged.

@groeneai

groeneai commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

Confirmed, and thanks for the cleanup. I verified ab032c89b84 removes exactly the 54 stray paths that 5bcd0e30c9d added (57 files: 3 intended + 54 strays), that the 21 MB tests/integration/test_paimon_rest_catalog/paimon-rest-catalog/chunk_00 is gone, and that the head diff is back to the intended 4 files at +350/-16. The fix and its coverage are untouched: all four intended blobs are byte-identical between the two commits, and git diff 5bcd0e30c9d ab032c89b84 restricted to them is empty, so the join_algorithms fallback and the 'auto' / full_sorting_merge cases in 04411 still stand.

One correction on the cause, because it changes the fix. These were not untracked leftovers in the worktree. All 54 paths are absent from every commit I authored (checked per path against my last one, 06ffae7b8e2c) and absent at both of your merges, so nothing on this branch ever carried them. Their committed bytes also differ from the copies in the worktree that holds this branch, and two of them, chunk_00 and the 04691 test pair, do not exist there at all. They match byte for byte a different, unrelated worktree whose HEAD dates to 2026-07-27, and in that tree they are tracked, not untracked.

So the mechanism is a stale base rather than a broad git add: those paths were still tracked on master in late July and were deleted upstream afterwards, tests/ci/create_release.py and artifactory.py by da3a2236c20e and test_library_bridge by 9e1e78815130. A commit made from a tree predating those deletions reintroduces the files as additions. That also explains 04691_parallel_replicas_two_merge_sources_join, which exists in no ref of the repository other than 5bcd0e30c9d, and which no git add of mine could have produced.

The guard I am adopting is therefore not a cleanliness check but a base check: assert the committed file list equals the intended set before pushing, and reconcile the tree against current master first, since a stale tree resurrects deleted paths silently while git status stays clean.

@groeneai

groeneai commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - ab032c8

Every 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 CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Build (arm_release) / Post Hooks build_profile_hook telemetry INSERT rejected with LogCluster query failed with code 500; job-level status is success (the hook carries allow_failure), so no build was gated. Not caused by this diff: 816 rows / 284 distinct PRs / 463 master hits in 7 days. a fix task is created (investigating at full effort - fixing PR link to follow on this PR)
Sync - CH Inc sync (private, not actionable)

Session id: cron:our-pr-ci-monitor:20260804-043000

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 4, 2026
Merged via the queue into ClickHouse:master with commit 74b001f Aug 4, 2026
181 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 4, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

Hi — this looks like a backport candidate for 26.6, 26.7. I ran this PR's own regression test against each branch's binary and the bug reproduces there (the fix isn't present yet).

@groeneai

groeneai commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

The finding reproduces, but the affected set is four branches, not two: 26.3, 26.5, 26.6 and 26.7. 25.8 is not affected.

I ran this PR's own 04411 test against the official per-branch binaries from builds.clickhouse.com, using the current master build as a fix-present control (26.8.1.790, GIT_HASH f098c315, which contains the merge commit):

branch binary 04411 vs its reference
master 26.8.1.790 identical, 0 differing lines
26.7 26.7.3.12 rc=49, 42 differing lines
26.6 26.6.2.160 rc=49, 42 differing lines
26.5 26.5.7.7 rc=49, 42 differing lines
26.3 26.3.17.110 rc=49, 42 differing lines

The exception on all four is the one from #108521: Trying to extract chunk from ChunkBuffer before all inputs are finished (unfinished inputs: 2). These are RelWithDebInfo builds, so it is thrown to the client rather than aborting the server.

25.8 does not have the feature: correlated_subqueries_use_in_memory_buffer and correlated_subqueries_default_join_kind do not exist there, and there is no ChunkBuffer machinery under src/ (0 matching files, against 1 on each of the other four). With those two settings dropped the query fails with a different exception at a different site (Code: 48, isNotDistinctFrom can be used only in the JOIN ON section), so it is not this defect.

Portability: git merge-tree is clean on 26.7, 26.6 and 26.5, and the fix is present in each resulting tree. 26.3 has one conflicting hunk, the DecorrelationContext member declaration, because 26.3 predates the move of EquivalenceClasses to a template; keeping 26.3's container type and taking the rest of the hunk resolves it. The src/Core/Settings.cpp change is +2 lines of description text inside an existing setting, so no settings-history entry is involved.

@alexey-milovidov could you apply v26.3-must-backport? Per select_backport_branches that expands to exactly 26.3, 26.5, 26.6, 26.7, whereas pr-must-backport would also target 25.8.

@groeneai

groeneai commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

Following up on the two Fast test (arm_darwin) rows in my CI ledger above (03312_squashing_with_low_card_mem_usage and 03826_calculate_subcolumn_size_during_merge_tree_read, both Code: 243 ... not enough space), the fixing PR is #113605.

Root cause was not in either test: runner-init.py's post-job free-space guard opened with an unconditional macOS early return, so those long-lived hosts never ran the df and kept accepting jobs on a nearly-full rootfs. The failing job's own df shows 97% used with 3.4 GiB free before its first test ran, and the reservation sizes that failed range from 33 MiB to 380 MiB, so the victim set is whichever test happened to be inserting rather than a handful of large ones. #113605 scopes that early return to the Docker teardown and also runs the check before a job is accepted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors manual approve Manual approve required to run CI pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

6 participants