Skip to content

Fix max_rows_to_transfer for GLOBAL IN/JOIN under the analyzer - #104119

Merged
PedroTadim merged 7 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-103333-max-rows-to-transfer-new-analyzer
Jun 11, 2026
Merged

PedroTadim merged 7 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-103333-max-rows-to-transfer-new-analyzer

Conversation

@groeneai

@groeneai groeneai commented May 5, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

max_rows_to_transfer and max_bytes_to_transfer limit how many rows / bytes
the initiator may materialize for a GLOBAL IN or GLOBAL JOIN external table
before transmitting it to remote shards. Under the old analyzer
(enable_analyzer = 0) the limits fire correctly with
Code: 191. SET_SIZE_LIMIT_EXCEEDED. Under the new analyzer (the default), the
query runs to completion and the limit is silently ignored.

Reported in #103333:

SELECT t1.a1, t2.b2 FROM t1_all t1 GLOBAL JOIN t2_all t2 ON t1.a1 = t2.a2
SETTINGS max_rows_to_transfer = 10;
-- enable_analyzer = 0: Code 191 (SET_SIZE_LIMIT_EXCEEDED)
-- enable_analyzer = 1: returns 100 rows, no error

Root cause

Both analyzers eventually need to materialize the right-hand side of a
GLOBAL IN/GLOBAL JOIN into a temporary table that gets shipped to remote
shards. They diverge on where that materialization happens:

  • Old analyzer: GlobalSubqueriesVisitor::Data::addExternalStorage
    (src/Interpreters/GlobalSubqueriesVisitor.cpp) registers the subquery via
    prepared_sets->addFromSubquery(...). Later,
    InterpreterSelectQuery::executeSubqueriesInSetsAndJoins collects those
    subqueries via prepared_sets->getSubqueries() and wraps them in a
    DelayedCreatingSetsStep constructed with
    network_transfer_limits = SizeLimits(max_rows_to_transfer, max_bytes_to_transfer, transfer_overflow_mode).
    The corresponding CreatingSetsTransform::consume() increments cumulative
    rows / bytes and calls
    network_transfer_limits.check(rows, bytes, "IN/JOIN external table", ErrorCodes::SET_SIZE_LIMIT_EXCEEDED)
    for every chunk, raising the configured error or stopping reading.

  • New analyzer: buildQueryTreeForShard (src/Storages/buildQueryTreeForShard.cpp)
    detects GLOBAL IN/GLOBAL JOIN nodes in DistributedProductModeRewriteInJoinVisitor
    and calls executeSubqueryNode to materialize the subquery into a temporary
    table. executeSubqueryNode builds a pipeline
    query_plan -> SimpleSquashingChunksTransform -> external_storage->write but
    never reads max_rows_to_transfer / max_bytes_to_transfer, so the network
    transfer limits are never enforced.

Fix

Install the missing limit check on the new analyzer's materialization path. A
small ISimpleTransform (GlobalSubqueryTransferLimitsCheckingTransform) is
inserted after the squashing transform and mirrors CreatingSetsTransform 1:1:

  • same error code: SET_SIZE_LIMIT_EXCEEDED,
  • same what argument to SizeLimits::check: "IN/JOIN external table",
  • same overflow-mode semantics: THROW raises the exception, BREAK stops
    reading and lets the materialization complete with truncated data.

The transform is only added when network_transfer_limits.hasLimits() is
true, so the default zero configuration is a no-op and other tests
that materialize GLOBAL IN/GLOBAL JOIN subqueries are not affected.

Verification

  • Reproduced the bug locally on master with a 2-shard test_cluster_two_shards
    setup. After the fix, the query throws
    Code: 191. Limit for IN/JOIN external table exceeded, max rows: 10.00, current rows: 200.00. (SET_SIZE_LIMIT_EXCEEDED)
    exactly like the old analyzer.
  • New regression test 04204_global_in_join_max_rows_to_transfer_103333.sql
    asserts the limit fires under both analyzers, that
    transfer_overflow_mode = 'break' truncates without throwing, and that the
    unlimited happy path still returns the expected results.
  • 100/100 runs of the new test pass under full CI randomization.
  • Without the fix the test fails (The query succeeded but the server error '191' was expected),
    with the fix it passes — both directions verified locally.

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 max_rows_to_transfer and max_bytes_to_transfer being silently ignored for GLOBAL IN and GLOBAL JOIN queries under the new analyzer. The settings now raise SET_SIZE_LIMIT_EXCEEDED (or break, depending on transfer_overflow_mode) when the materialised external table exceeds the configured limit, matching the behavior of the old analyzer. Closes #103333.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.6.1.640

The `max_rows_to_transfer` and `max_bytes_to_transfer` settings limit how
much data the initiator may materialize for a `GLOBAL IN` or `GLOBAL JOIN`
external table before sending it to remote shards. Under the old analyzer
this was enforced inside `CreatingSetsTransform`, which is built from
`prepared_sets->getSubqueries()` via `DelayedCreatingSetsStep` and runs
the check `network_transfer_limits.check(rows, bytes, "IN/JOIN external
table", ErrorCodes::SET_SIZE_LIMIT_EXCEEDED)` for every chunk.

The new analyzer materializes the same subqueries in a different place:
`executeSubqueryNode` in `src/Storages/buildQueryTreeForShard.cpp`. The
helper builds a pipeline that writes the subquery's output into a
temporary table (`query_plan -> SimpleSquashingChunksTransform ->
external_storage->write`) but never installed `network_transfer_limits`,
so both settings were silently ignored — every `GLOBAL IN`/`GLOBAL JOIN`
on a distributed cluster could materialize an unbounded amount of data on
the initiator regardless of the configured limits.

This commit installs the same check on the new analyzer's path. A small
`ISimpleTransform` (`GlobalSubqueryTransferLimitsCheckingTransform`) is
inserted after the squashing transform and mirrors `CreatingSetsTransform`
exactly: same error code (`SET_SIZE_LIMIT_EXCEEDED`), same
`"IN/JOIN external table"` reason string, same overflow-mode semantics
(`THROW` raises an exception, `BREAK` stops reading). The transform is
only added when `network_transfer_limits.hasLimits()` is true, so the
default-zero configuration is a no-op.

Also adds a stateless regression test that asserts the limit fires for
both `GLOBAL JOIN` and `GLOBAL IN` under both analyzers, that
`transfer_overflow_mode = 'break'` truncates without throwing, and that
the unlimited happy path still returns the expected results.

Closes ClickHouse#103333
@groeneai

groeneai commented May 5, 2026

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

Per the worker workflow used to author this fix, here are the answers to the mandatory pre-PR validation gate questions, all confirmed before opening this PR.

Session id: cron:clickhouse-ci-task-worker:20260505-144500

a) Deterministic repro? Yes. With a 2-shard test_cluster_two_shards setup populated by numbers(10000) / numbers(100), the query

SELECT count() FROM t1_dist t1 GLOBAL JOIN t2_dist t2 ON t1.a = t2.a
SETTINGS max_rows_to_transfer = 10

returns 400 on master HEAD and throws Code: 191. SET_SIZE_LIMIT_EXCEEDED with this PR. Same query with enable_analyzer = 0 already throws on master, so the divergence is reproducible on demand.

b) Root cause explained? The new analyzer materializes GLOBAL IN/GLOBAL JOIN subqueries via executeSubqueryNode in src/Storages/buildQueryTreeForShard.cpp. That helper builds the pipeline query_plan -> SimpleSquashingChunksTransform -> external_storage->write and never reads max_rows_to_transfer/max_bytes_to_transfer. The old analyzer materializes the same subqueries via prepared_sets->getSubqueries() -> DelayedCreatingSetsStep -> CreatingSetsTransform, where CreatingSetsTransform::consume runs network_transfer_limits.check(rows, bytes, "IN/JOIN external table", ErrorCodes::SET_SIZE_LIMIT_EXCEEDED) on every chunk. The new analyzer's path was added without porting that check.

c) Fix matches root cause? Yes. The fix inserts a small ISimpleTransform (GlobalSubqueryTransferLimitsCheckingTransform) into the same pipeline at the same logical position the old analyzer enforces it (during materialization, before the data is written to the temporary external table). The transform mirrors CreatingSetsTransform exactly: same error code (SET_SIZE_LIMIT_EXCEEDED), same what string "IN/JOIN external table", same THROW/BREAK semantics. No bounds widening, no no-random-* workaround, no symptom patch.

d) Test intent preserved? / New tests added? New regression test tests/queries/0_stateless/04204_global_in_join_max_rows_to_transfer_103333.sql covers GLOBAL JOIN and GLOBAL IN under both analyzers (the old analyzer assertion is a regression-prevention sanity check), transfer_overflow_mode = 'break', and the unlimited happy path. No existing test was weakened.

e) Both directions demonstrated? Yes.

  • Without the fix (reverted source, rebuilt): clickhouse-test --no-random-settings --no-random-merge-tree-settings 04204_global_in_join_max_rows_to_transfer_103333 fails with The query succeeded but the server error '191' was expected for the four serverError SET_SIZE_LIMIT_EXCEEDED queries.
  • With the fix: 100/100 runs pass under full randomized settings; 30/30 pass without randomization.

f) Fix is general, not a narrow patch? executeSubqueryNode is the single point of GLOBAL IN/JOIN subquery materialization in the new analyzer (called from the loop over global_in_or_join_nodes in buildQueryTreeForShard). One transform installed there covers both GLOBAL IN and GLOBAL JOIN, all kinds of right-table expressions (QUERY, UNION, TABLE, TABLE_FUNCTION, ARRAY_JOIN), and both THROW and BREAK overflow modes. The fix is at the source of the missing check (the materialization step), not a defensive guard at the symptom site. The transform is gated on network_transfer_limits.hasLimits(), so the default zero configuration is a no-op for unrelated callers.

@groeneai

groeneai commented May 5, 2026

Copy link
Copy Markdown
Collaborator Author

cc @KochetovNicolai @vdimir @PedroTadim — could you review this? It restores enforcement of max_rows_to_transfer / max_bytes_to_transfer for GLOBAL IN/GLOBAL JOIN under the new analyzer by adding the missing network_transfer_limits check to executeSubqueryNode in buildQueryTreeForShard.cpp (the old analyzer enforces it inside CreatingSetsTransform, the new analyzer's materialization path was missing it). Closes #103333.

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label May 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2aecdb1]

Summary: ❌

job_name test_name status info comment
AST fuzzer (arm_asan_ubsan) FAIL
Logical error: Cannot find input column A on its position in inputs of expression actions DAG, expected inputs B in (STID: 2409-5283) FAIL cidb IGNORED

AI Review

Summary

This PR restores max_rows_to_transfer / max_bytes_to_transfer enforcement for new-analyzer GLOBAL IN and GLOBAL JOIN materialization by routing the temporary-table fill through the existing CreatingSetsTransform, matching the old analyzer's limit accounting and transfer_overflow_mode behavior. I found no new blocker or major code-review findings in the current diff.

Missing context / blind spots
  • ⚠️ The refreshed CI run for SHA 2aecdb1750a7377fbd72828bea243716535dc8bb was still pending when checked; Style check had passed and the Praktika report showed no failed tests so far, but Fast test, Bugfix validation, Build (arm_tidy), and the aggregate PR status were not complete. A green current CI run would close this gap.
Final Verdict

✅ No inline findings to post. The implementation and focused regression coverage look consistent with the PR contract; wait for the refreshed CI run to finish before merge.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label May 5, 2026
Comment thread src/Storages/buildQueryTreeForShard.cpp Resolved
@novikd novikd self-assigned this May 5, 2026
…4119 review)

`GlobalSubqueryTransferLimitsCheckingTransform` was counting raw
`chunk.bytes()`. For a `ColumnConst` that only accounts for the single
stored value (e.g. one `Int32` for a 1000-row literal column) and
silently undercounts `max_bytes_to_transfer`, letting subqueries that
produce const columns through.

`CreatingSetsTransform::consume` (the equivalent old-analyzer path) calls
`materializeBlock` first and counts `block.bytes()`, so a `ColumnConst`
is expanded to its full per-row payload before being checked against
`max_bytes_to_transfer`. Mirror that exactly:
materialize, count, push the materialized columns downstream so the
temporary table receives the same bytes as the old analyzer would.

Extends the regression test in
`04204_global_in_join_max_rows_to_transfer_103333.sql` with two
constant-only subquery cases (one `GLOBAL JOIN` and one `GLOBAL IN`)
that rely on the materialized byte count to fire the limit. Without
this commit both queries silently succeed; with it, both throw
`SET_SIZE_LIMIT_EXCEEDED`. The `GLOBAL IN` case explicitly disables
`enable_add_distinct_to_in_subqueries` so the optimizer does not collapse
the constant-only subquery to a single row before the bytes are counted.

Bot review on PR ClickHouse#104119:
ClickHouse#104119 (comment)
@groeneai

groeneai commented May 5, 2026

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate (per cron:clickhouse-ci-task-worker:20260505-164500):

a) Deterministic repro? Yes. build/programs/clickhouse client -q 'SELECT count() FROM t1_dist WHERE a GLOBAL IN (SELECT toInt32(42) AS x FROM numbers(1000)) SETTINGS max_rows_to_transfer = 0, max_bytes_to_transfer = 100, enable_add_distinct_to_in_subqueries = 0' against the 2-shard cluster fails with SET_SIZE_LIMIT_EXCEEDED with the fix and silently returns 2 (1000 rows of constant 42, but only 2 t1 rows match) without the fix.

b) Root cause explained? Chunk::bytes() on a column produced as ColumnConst<ColumnInt32> returns ~4 bytes (one stored value), not 4 bytes × 1000 rows. The old-analyzer path CreatingSetsTransform::consume calls materializeBlock(block) first, expanding the ColumnConst to a regular ColumnVector<Int32> of length 1000, and then sums block.bytes() ≈ 4000. The new-analyzer transform was reading chunk.bytes() directly without that materialization step, so a const-only subquery would always pass any max_bytes_to_transfer greater than the size of one stored value.

c) Fix matches root cause? Yes — directly mirrors CreatingSetsTransform::consume: clone header, materializeBlock, sum block.bytes(), re-attach columns to the chunk so downstream insertion to the temp table also receives the materialized form. Same byte-counting semantics as the old analyzer for any input shape.

d) Test intent preserved? The original 6 test cases (new-analyzer rows-limit GLOBAL JOIN / GLOBAL IN, old-analyzer parity, break mode, happy-path baselines) are unchanged and still cover the rows-limit dimension that #103333 reported. Three new test cases were added that specifically exercise max_bytes_to_transfer against ColumnConst-producing subqueries — without the commit, all three fail; with it, all three pass. enable_add_distinct_to_in_subqueries = 0 is pinned only on the const-IN cases (the optimizer would otherwise collapse the const-only subquery to one row and defeat the bytes assertion); GLOBAL JOIN does not need it.

e) Both directions demonstrated? Yes. Reverted the C++ change, kept the test changes, rebuilt: 1 case fails with "The query succeeded but the server error '191' was expected" (the const-only GLOBAL JOIN and GLOBAL IN queries returned 2000 and 2 rows respectively when they should have thrown). Restored the C++ change, rebuilt: 50 / 50 passes under default settings randomization (--test-runs 50).

f) Fix is general? Yes. Materializing applies uniformly for all input column shapes (regular column, ColumnConst, ColumnSparse, ColumnLowCardinality, etc.) so the bytes count is always equivalent to what the temp table will store. No symmetric old-analyzer path was affected — CreatingSetsTransform already materializes; only the new-analyzer code path was missing it.

cc @KochetovNicolai @vdimir @PedroTadim — pinging since you're the original reviewers; feel free to take another look at the new commit when you have a moment.

Session: cron:clickhouse-ci-task-worker:20260505-164500

The CI test profile (`tests/config/users.d/limits.yaml`) sets
`max_rows_to_transfer = 1G` and `max_bytes_to_transfer = 1G`. After
PR ClickHouse#104119 made the new analyzer enforce these limits inside
`buildQueryTreeForShard::executeSubqueryNode` via the new
`GlobalSubqueryTransferLimitsCheckingTransform`, the existing
`02916_glogal_in_cancel.sql` query started failing on CI: the
inner `SELECT number FROM numbers(10000000000.)` materializes well
past 1 GiB before the test's `max_execution_time = 0.5` cancellation
fires, so the bytes limit raises `SET_SIZE_LIMIT_EXCEEDED (191)`
inside the limits transform.

This test exists purely to exercise the `GLOBAL IN` cancellation path
(`max_execution_time` + `timeout_overflow_mode = 'break'`), not the
transfer limits. Pin both `max_rows_to_transfer` and `max_bytes_to_transfer`
to 0 in the session so the new transform is gated out
(`SizeLimits::hasLimits()` returns false → transform not installed)
and the timeout cancellation path is what gets exercised, regardless
of how the test profile sets the transfer limits.
@groeneai

groeneai commented May 5, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed 48e53e7c9e55 — pin max_rows_to_transfer = 0, max_bytes_to_transfer = 0 in 02916_glogal_in_cancel.sql to fix the PR-caused regression.

Why the test broke

The test profile (tests/config/users.d/limits.yaml) sets max_rows_to_transfer = 1G and max_bytes_to_transfer = 1G (with the comment "set every other limit to a high value, so it will not limit anything, but we will test that code around it"). Before this PR the new analyzer silently ignored those limits for GLOBAL IN, so the test's pathological subquery SELECT number FROM numbers(10000000000.) was never actually capped by them — the max_execution_time = 0.5 + timeout_overflow_mode = 'break' cancellation path is what the test was actually exercising.

Once this PR's GlobalSubqueryTransferLimitsCheckingTransform is in place, materialization of that 80 GB inner stream crosses 1 GiB before the 0.5 s timeout fires on CI's debug runner, so the limits transform raises Code: 191. SET_SIZE_LIMIT_EXCEEDED — Limit for IN/JOIN external table exceeded, max bytes: 953.67 MiB, current bytes: 953.73 MiB. CIDB stack trace confirmed the throw site:

6. src/Storages/buildQueryTreeForShard.cpp:439:21:
   DB::(anonymous namespace)::GlobalSubqueryTransferLimitsCheckingTransform::transform(DB::Chunk&)

--diagnose-random-settings reproduced 91/91 with random and 104/104 without — fully deterministic, not a randomization issue.

Fix

Add max_rows_to_transfer = 0, max_bytes_to_transfer = 0 to the session set at the top of the test, plus a comment explaining why. With both at zero, SizeLimits::hasLimits() returns false in executeSubqueryNode, the transform is not installed at all, and the test exercises the same cancellation path it always did. The CI profile values can stay at 1G — they just stop applying to this specific test.

Verification

  • 50/50 passes locally with the fix (debug build, full randomization).
  • Verified that the session-level set overrides the profile even when I forced the profile down to max_bytes_to_transfer = 100: 5/5 passes — session takes precedence over profile, as expected.
  • Did not attempt to reproduce the CI failure locally: my host materializes the inner stream so fast that the 0.5 s timeout always wins on this hardware (5/5 passes both with and without the fix on a 100-byte profile limit). The local fast-path doesn't disprove the CI failure — CIDB shows it deterministic on Stateless tests (amd_debug, parallel) and Fast test. The fix is sound by code analysis (hasLimits() gate) and timing-independent.

Pre-PR validation

a) Deterministic repro — yes, on CI (91/91, 104/104). Locally: timing-bound, but unambiguous from CIDB.
b) Root cause — limits transform installed by this PR fires the 1 GB profile limit before the test's 0.5 s timeout cancellation.
c) Fix matches root cause — opting out of the transfer limit (gating the transform out of the pipeline) makes the test exercise the cancellation path it actually wants to test.
d) Test intent preserved — the test still tests GLOBAL IN cancellation via max_execution_time + break mode. Pinning the unrelated transfer limits doesn't touch that.
e) Both directions — fix demonstrated via 50/50 local passes + CI-side via the next CI run on this branch. Local "without-fix" reproduction is timing-blocked on my hardware (the 0.5 s timeout always wins locally), so I'm relying on CIDB for the failing-side evidence.

CIDB hits this is keyed off:

cc @KochetovNicolai @vdimir @PedroTadim — should be a small turnaround on CI now that the regression is contained.

@alexey-milovidov alexey-milovidov changed the title Fix max_rows_to_transfer for GLOBAL IN/JOIN under new analyzer Fix max_rows_to_transfer for GLOBAL IN/JOIN under the analyzer May 5, 2026
Comment thread src/Storages/buildQueryTreeForShard.cpp Outdated
* same `"IN/JOIN external table"` reason string, and the same overflow-mode
* semantics (`THROW` raises `SET_SIZE_LIMIT_EXCEEDED`; `BREAK` stops reading).
*/
class GlobalSubqueryTransferLimitsCheckingTransform : public ISimpleTransform

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.

@groeneai, is it possible to fix without the creation of a new Transform?

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.

Should be done. @novikd is this PR in a good shape to merge?

…04119 review)

Per @novikd's review of PR ClickHouse#104119, drop the bespoke
`GlobalSubqueryTransferLimitsCheckingTransform` and instead reuse the
existing `CreatingSetsTransform` to fill the temporary table for
`GLOBAL IN` / `GLOBAL JOIN` subqueries under the new analyzer.

`CreatingSetsTransform` already handles the `external_table` write,
calls `materializeBlock` (so `ColumnConst` columns are correctly
accounted for in `bytes_to_transfer`), and applies the
`network_transfer_limits` check with the same `SET_SIZE_LIMIT_EXCEEDED`
error code and `"IN/JOIN external table"` reason that the old analyzer
uses inside `DelayedCreatingSetsStep`. Passing
`SetAndKey{external_table = external_storage}` with `set` left null
makes it skip the set-building branch and only fill the table.

Net effect on this file: the entire `GlobalSubqueryTransferLimitsCheckingTransform`
class is removed (~50 lines), the manual `external_storage->write(...)` is
removed (`CreatingSetsTransform::startSubquery` does the same call
internally), and the pipeline is closed with `EmptySink` to consume the
empty header that `CreatingSetsTransform` produces - mirroring the
existing pattern in `FutureSetFromSubquery::buildSetInplace`
(`src/Interpreters/PreparedSets.cpp`).

Behaviour is unchanged: the same limit check runs at the same logical
position, against the same materialized blocks, with the same error
code and reason. The new-analyzer path is now in lockstep with the
old-analyzer path through a single shared transform.

Verified locally:
- `04204_global_in_join_max_rows_to_transfer_103333` (regression test
  for issue ClickHouse#103333, including the const-column edge case): 50/50 pass
  with full randomization.
- `02916_glogal_in_cancel` (the test that regressed earlier in this
  PR's history): 50/50 pass with full randomization.
@groeneai

groeneai commented May 7, 2026

Copy link
Copy Markdown
Collaborator Author

@novikd — reworked in f3e0745af1e. Dropped the custom GlobalSubqueryTransferLimitsCheckingTransform and routed executeSubqueryNode through the existing CreatingSetsTransform instead.

Concretely, in src/Storages/buildQueryTreeForShard.cpp the squashed pipeline is now closed with:

auto set_and_key = std::make_shared<SetAndKey>();
set_and_key->external_table = external_storage;

builder->addCreatingSetsTransform(
    std::make_shared<const Block>(Block{}),
    std::move(set_and_key),
    network_transfer_limits,
    /* prepared_sets_cache = */ nullptr);

auto pipeline = QueryPipelineBuilder::getPipeline(std::move(*builder));
pipeline.complete(std::make_shared<EmptySink>(pipeline.getSharedHeader()));

With set_and_key->set left null, CreatingSetsTransform::startSubquery skips the set-building branch and only fills the external table — the same path the old analyzer takes through DelayedCreatingSetsStep. The materializeBlock + bytes_to_transfer accumulation + network_transfer_limits.check(..., "IN/JOIN external table", SET_SIZE_LIMIT_EXCEEDED) is CreatingSetsTransform::consume itself, so we get the const-column accounting and the matching error code / reason / THROW-vs-BREAK semantics for free, by construction. The pattern (build → addCreatingSetsTransform → complete(EmptySink)) is the same one already used in FutureSetFromSubquery::buildSetInplace (src/Interpreters/PreparedSets.cpp:297-313).

Net diff for this commit: +20 / −71 in buildQueryTreeForShard.cpp — the whole GlobalSubqueryTransferLimitsCheckingTransform class and the manual external_storage->write(...) are gone (CreatingSetsTransform calls external_table->write({}, ..., nullptr, ...) itself).

I considered LimitsCheckingTransform first (since the name almost matches), but it doesn't fit:

  • it raises TOO_MANY_ROWS_OR_BYTES (not SET_SIZE_LIMIT_EXCEEDED),
  • its reason is hardcoded to "result" (not "IN/JOIN external table"),
  • it counts chunk.bytes() without materializeBlock, so it would carry the same ColumnConst undercount the bot flagged earlier.

CreatingSetsTransform reuse keeps the new-analyzer path in lockstep with the old analyzer through a single shared transform.

Verified locally on the rework: 04204_global_in_join_max_rows_to_transfer_103333 (regression test, including const-column edge case) and 02916_glogal_in_cancel: 100/100 pass with full randomization (50 runs each).

Session id: cron:clickhouse-ci-task-worker:20260507-174500.

…House#104119 review)

The `ColumnConst`-regression comment in
`tests/queries/0_stateless/04204_global_in_join_max_rows_to_transfer_103333.sql`
referenced
`https://github.com/ClickHouse/ClickHouse/pull/104119#discussion_r...` with the
discussion id truncated. The link pointed nowhere. The actual bot review that
flagged the `chunk.bytes()` vs `materializeBlock(block).bytes()` divergence is
discussion `r3189697129`. Replace the placeholder with the full URL so the
test documentation stays anchored to a real review thread.

Reported by clickhouse-gh[bot] at
ClickHouse#104119 (comment)
endorsed by @PedroTadim at
ClickHouse#104119 (comment)
@PedroTadim PedroTadim self-assigned this Jun 3, 2026
@PedroTadim

Copy link
Copy Markdown
Member

@novikd can this PR be merged?

@groeneai

groeneai commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator Author

CI ledger — covered SHA: 4ccbdbb7666cc00b2aa2f740b6cb602f3c54d6df

CI fully finished (Mergeable Check completed; 0 pending checks).

Check Test Disposition
Stateless tests (amd_tsan, parallel, 1/2) 00096_obfuscator_save_load flaky chronic trunk — task 2026-06-02-ci-00096obfuscatorsaveload-chronic-f
Stateless tests (amd_tsan, parallel, 1/2) 00175_obfuscator_schema_inference flaky chronic trunk — task 2026-06-02-ci-00175obfuscatorschemainference-ab
Unit tests (asan_ubsan) (check-level) infra/chronic UBSan UntrackedMemoryCounter — task 2026-06-03-ci-p1-chronic-ubsan-in-untrackedmemoryc
Bugfix validation (functional tests) 02916_glogal_in_cancel not this PR's own test (this PR adds 04222_max_rows_to_transfer_global_in_join). 30d cross-PR confirms chronic flake unrelated to GLOBAL IN/JOIN analyzer fix.

No PR-caused failures. Awaiting human review.

Session: cron:our-pr-ci-monitor:20260604-213000

@groeneai

groeneai commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator Author

Correction to ledger comment above: 02916_glogal_in_cancel is modified by this PR (changed-file). The Bugfix validation failure is the framework's known limitation when the modified test doesn't fail on master HEAD (the bug-class this PR addresses isn't reproducible on master; the new 04204_global_in_join_max_rows_to_transfer_103333 test is the bug witness). Not a real correctness regression in the PR. Awaiting human review on the analyzer fix itself.

Session: cron:our-pr-ci-monitor:20260604-213000

@PedroTadim

Copy link
Copy Markdown
Member

@groeneai merge with master

@clickhouse-gh

clickhouse-gh Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Dear @novikd, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@groeneai

groeneai commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator Author

@ PedroTadim — merged master (3b13ddf415ec) into the branch. Branch HEAD: 2aecdb1750a7. No conflicts. CI now running on the refreshed branch.

Session: cron:clickhouse-ci-task-worker:20260608-205800

@clickhouse-gh

clickhouse-gh Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.60% 84.50% -0.10%
Functions 92.30% 92.30% +0.00%
Branches 77.20% 77.20% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 23/23 (100.00%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 1 line(s) · Uncovered code

Full report · Diff report

@groeneai

groeneai commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator Author

CI Ledger — covered SHA: 2aecdb1750a7377fbd72828bea243716535dc8bb (master merge)

CI fully finished. Gate (a) all CheckRuns COMPLETED ✓, gate (b) Finish Workflow=SUCCESS ✓, gate (c) ≥20-min CIDB ingestion buffer ✓.

Single failure, not PR-caused:

Check / Test Classification Disposition
AST fuzzer (arm_asan_ubsan) — STID 2409-5283 Logical error: Cannot find input column __table14.number on its position in inputs of expression actions DAG (failing query: WITH RECURSIVE alias2 AS (SELECT DISTINCT number FROM test_aliases LIMIT 255, -2147483649 UNION DISTINCT ...)) chronic trunk bug Cross-PR query (30d): 3 unrelated PRs hit (#103112, #104662, this one), 0 master. CTE / RECURSIVE / WITH UNION DISTINCT column-binding bug in the analyzer's actions DAG construction — fully orthogonal to this PR's diff (buildQueryTreeForShard.cpp GLOBAL JOIN/IN external table size limits). Tracked in task 2026-06-08-ci-p1-stid-2409-5283-ast-fuzzer-logical.

All 11 builds, AST fuzzer (amd_debug / amd_msan / amd_tsan / amd_debug-targeted / amd_debug-targeted-old_compatibility), BuzzHouse (4 variants), all stress tests, all integration tests, all functional tests (parallel + sequential + s3 + WasmEdge + DatabaseReplicated + ParallelReplicas + AsyncInsert + flaky-checks across all sanitizers), unit tests (asan/tsan/msan), Style check, Fast test, Bugfix validation, Code Review, LLVM Coverage, SQLLogic, Performance Comparison, Compatibility, Install packages, Docker images, Upgrade check: all SUCCESS.

Awaiting reviewer re-review.

@PedroTadim
PedroTadim added this pull request to the merge queue Jun 11, 2026
@PedroTadim

Copy link
Copy Markdown
Member

@groeneai is there a fix PR for the failed AST fuzzer job? If not, add one

@PedroTadim
PedroTadim removed this pull request from the merge queue due to a manual request Jun 11, 2026
@PedroTadim
PedroTadim added this pull request to the merge queue Jun 11, 2026
@PedroTadim
PedroTadim removed this pull request from the merge queue due to a manual request Jun 11, 2026
@PedroTadim
PedroTadim added this pull request to the merge queue Jun 11, 2026
@PedroTadim
PedroTadim removed this pull request from the merge queue due to a manual request Jun 11, 2026
@PedroTadim
PedroTadim added this pull request to the merge queue Jun 11, 2026
Merged via the queue into ClickHouse:master with commit eb96a8a Jun 11, 2026
164 of 166 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 11, 2026
@antaljanosbenjamin

Copy link
Copy Markdown
Member

The test is flaky @PedroTadim could you please either check why it is flaky or revert it?

@PedroTadim

Copy link
Copy Markdown
Member

The test is flaky @PedroTadim could you please either check why it is flaky or revert it?

I am going to try fix the test

@groeneai

groeneai commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

The 04204 failures are not a bug in the test. They are the master-wide connection-pool packet desync Unexpected packet from server (expected TablesStatusResponse, got ProfileInfo) (Code 102, UNEXPECTED_PACKET_FROM_SERVER), a recurrence of #93018: a pooled connection is returned with an undelivered ProfileInfo after a cancelled distributed query and then reused for the next TablesStatusRequest handshake, which misreads the stale packet.

@PedroTadim the authoritative fix already merged today at 13:22 UTC: #108854 (commit 2e573a8), which disconnects out-of-sync pooled connections in RemoteQueryExecutor::finish and soft-retries UNEXPECTED_PACKET_FROM_SERVER in ConnectionEstablisher, plus a deterministic test. So reverting or altering 04204 is not needed and would not fix the class.

CIDB confirms the fix: the signature dropped from 142 failures / 12 on master over the 4 days before the merge (across 41 distinct distributed tests and 110 PRs) to 4 failures / 0 on master after it. The 4 residual hits are all stale-base PR branches whose CI ran within 34 min of the merge (binaries built before 13:22 UTC). Every same-settings rerun of 04204 passed. 04204's own logic is correct.

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 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

Development

Successfully merging this pull request may close these issues.

max_rows_to_transfer doesn't work with the default analyzer

7 participants