Skip to content

Fix parallel_hash global JOIN limit not enforced#109488

Merged
m-selmi merged 5 commits into
ClickHouse:masterfrom
m-selmi:fix-limit-tracking-in-concurrent-hash-join
Jul 9, 2026
Merged

Fix parallel_hash global JOIN limit not enforced#109488
m-selmi merged 5 commits into
ClickHouse:masterfrom
m-selmi:fix-limit-tracking-in-concurrent-hash-join

Conversation

@m-selmi

@m-selmi m-selmi commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Closes: #109400
Related: #108938

#108938 made getTotalRowCount / getTotalByteCount lock-free by using atomics and updating them at the end of addBlockToJoin.
This means addBlockToJoin could read a stale state of the atomics and not throw even though the limit was exceeded.
This PR adjusts the accounting to ensure each thread in addBlockToJoin sees an up-to-date state.

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

Fixed the global max_rows_in_join / max_bytes_in_join limit not being enforced for the parallel_hash join algorithm, where a query with join_overflow_mode = 'throw' could silently succeed instead of raising SET_SIZE_LIMIT_EXCEEDED.

Version info

  • Merged into: 26.7.1.717 (included in 26.7 and later)

@m-selmi m-selmi changed the title Fix limit tracking in concurrent hash join Fix parallel_hash global JOIN limit not enforced Jul 6, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [029f1ac]

Summary:


AI Review

Summary

The new global accounting in ConcurrentHashJoin looks like the right fix for the stale-snapshot race that let parallel_hash miss the global JOIN limit on ARM, and I do not see the earlier code-level correctness issues in the current head anymore. I cannot approve it yet, though, because the regression coverage still does not prove the same path under join_overflow_mode = 'break', and the PR metadata classifies a stable user-visible bug fix as an Improvement.

PR Metadata
  • Changelog category is not correct. This PR fixes user-visible misbehavior in the stable 26.7 line (parallel_hash could ignore max_rows_in_join / max_bytes_in_join after Reduce lock-contention from getTotalByteCount in ConcurrentHashJoin #108938), so it should be Bug Fix, not Improvement.
  • Changelog entry is required for Bug Fix, and the current entry is specific enough to keep after changing the category.
  • Exact replacement:
### Changelog category (leave one):
Bug Fix
Tests
  • ⚠️ [src/Interpreters/ConcurrentHashJoin.cpp:353] The changed accounting path is the shared global limit check for both join_overflow_mode = 'throw' and join_overflow_mode = 'break', but the only permanent regression coverage in tests/queries/0_stateless/04061_spilling_hash_join_overflow_limits.sql still exercises only throw. The previous revision of this PR already showed that a throw-only safety net can leave BREAK silently returning the full result, so this still needs a focused stateless test that forces join_algorithm = 'parallel_hash' with low max_rows_in_join / max_bytes_in_join and asserts truncation under join_overflow_mode = 'break'.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions:
    • Add focused parallel_hash regression coverage for join_overflow_mode = 'break'.
    • Change the Changelog category to Bug Fix.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 6, 2026
@m-selmi m-selmi added the can be tested Allows running workflows for external contributors label Jul 6, 2026
@antaljanosbenjamin antaljanosbenjamin self-assigned this Jul 6, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

Updating the branch to fix the 04001_join_reorder_through_expression test, which was broken today in master.

Comment thread src/Interpreters/ConcurrentHashJoin.cpp Outdated
Comment thread src/Interpreters/ConcurrentHashJoin.cpp Outdated
@clickhouse-gh

clickhouse-gh Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.70% 85.70% +0.00%
Functions 92.70% 92.70% +0.00%
Branches 77.90% 77.90% +0.00%

Changed lines: Changed C/C++ lines covered: 43/44 (97.73%) · Uncovered code

Full report · Diff report

@@ -347,7 +351,7 @@ bool ConcurrentHashJoin::addBlockToJoin(const Block & right_block_, bool check_l
}

if (check_limits && table_join->sizeLimits().hasLimits())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

parallel_hash is documented to honor both THROW and BREAK for join_overflow_mode, but the regression coverage here still only exercises THROW. The previous revision of this fix already showed that a throw-only safety net can leave BREAK returning the full result after the global limit is crossed, so I think this needs a focused stateless test that forces parallel_hash with low max_rows_in_join / max_bytes_in_join and asserts truncation under join_overflow_mode = 'break'.

@m-selmi

m-selmi commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@antaljanosbenjamin I changed the accounting to make the limit check in addBlockToJoin work more consistently with how it was before, would be great if you take another quick look

@clickhouse-gh clickhouse-gh Bot added pr-improvement Pull request with some product improvements and removed pr-bugfix Pull request with bugfix, not backported by default labels Jul 9, 2026
@m-selmi m-selmi added pr-bugfix Pull request with bugfix, not backported by default and removed pr-improvement Pull request with some product improvements labels Jul 9, 2026
@m-selmi
m-selmi added this pull request to the merge queue Jul 9, 2026
Merged via the queue into ClickHouse:master with commit ffeb980 Jul 9, 2026
681 of 684 checks passed
@m-selmi
m-selmi deleted the fix-limit-tracking-in-concurrent-hash-join branch July 9, 2026 15:01
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 9, 2026
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.

Flaky/regression: 04061_spilling_hash_join_overflow_limits fails on arm_binary — parallel_hash global JOIN limit not enforced

4 participants