Skip to content

Added possibility of compressing in HashJoin - #63696

Closed
p1rattttt wants to merge 10 commits into
ClickHouse:masterfrom
p1rattttt:hash_join_compression
Closed

p1rattttt wants to merge 10 commits into
ClickHouse:masterfrom
p1rattttt:hash_join_compression

Conversation

@p1rattttt

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • New Feature

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

Added possibility of compressing in HashJoin

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

* Added CacheBase<const Block *, Block>(LRU) that stores already decompressed blocks
@vdimir vdimir added the can be tested Allows running workflows for external contributors label May 13, 2024
@vdimir vdimir self-assigned this May 13, 2024
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-feature Pull request with new product feature label May 13, 2024
@robot-ch-test-poll2

robot-ch-test-poll2 commented May 13, 2024 •

Copy link
Copy Markdown
Contributor

This is an automated comment for commit f0de5dc with description of existing statuses. It's updated for the latest CI running

❌ Click here to open a full report in a separate page

Check nameDescriptionStatus
AST fuzzerRuns randomly generated queries to catch program errors. The build type is optionally given in parenthesis. If it fails, ask a maintainer for help❌ failure
CI runningA meta-check that indicates the running CI. Normally, it's in success or pending state. The failed status indicates some problems with the PR⏳ pending
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests❌ failure
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests❌ failure
Successful checks
Check nameDescriptionStatus
A SyncThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
ClickBenchRuns [ClickBench](https://github.com/ClickHouse/ClickBench/) with instant-attach table✅ success
ClickHouse build checkBuilds ClickHouse in various configurations for use in further steps. You have to fix the builds that fail. Build logs often has enough information to fix the error, but you might have to reproduce the failure locally. The cmake options can be found in the build log, grepping for cmake. Use these options and follow the general build process✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker keeper imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docker server imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docs checkBuilds and tests the documentation✅ success
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here✅ success
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integrational tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc✅ success
Install packagesChecks that the built packages are installable in a clear environment✅ success
Mergeable CheckChecks if all other necessary checks are successful✅ success
PR CheckThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors✅ success
Style checkRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report✅ success
Unit testsRuns the unit tests for different release types✅ success
Upgrade checkRuns stress tests on server version from last release and then tries to upgrade it to the version from the PR. It checks if the new server can successfully startup without any errors, crashes or sanitizer asserts✅ success

Comment thread src/Interpreters/HashJoin.cpp Resolved
Comment thread src/Interpreters/HashJoin.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Jun 25, 2024

Copy link
Copy Markdown
Contributor

Dear @vdimir, this PR hasn't been updated for a while. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@alexey-milovidov alexey-milovidov changed the title [WIP] Added possibility of compressing in HashJoin Added possibility of compressing in HashJoin Jun 16, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

The idea is sound. We can use compression first before oom or spilling to disk. This should apply for hash, parallel hash, and grace hash. But we need to test performance.

@alexey-milovidov

Copy link
Copy Markdown
Member

Thanks for this @p1rattttt. The idea is sound — compressing the right-side blocks in memory is a useful step before reaching an out-of-memory condition or spilling to disk. Since this branch has diverged significantly from the current HashJoin/ScatteredBlock architecture, I've re-implemented the idea against current master (adaptive, triggered under memory pressure, and covering hash, parallel_hash and grace_hash) in #107667. Closing this one in favor of that PR; full credit to the original author.

Re-implemented in: #107667

zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Re-implementation of the idea from PR ClickHouse#63696 ("Added possibility of compressing
in HashJoin") against the current `HashJoin`/`ScatteredBlock` architecture, with
the direction adjusted so compression is an adaptive step taken *before* an
out-of-memory condition or spilling to disk, and so it covers `hash`,
`parallel_hash` and `grace_hash` (which all build on the same `HashJoin`).

New settings:
- `enable_join_in_memory_compression` (Bool, default false): when a hash-based
  join hits memory pressure (the same trigger as block shrinking: more than half
  of `max_bytes_in_join`, or half the query memory limit), compress the stored
  right-side blocks instead of only shrinking them. Wired through both the legacy
  `Settings` path and the analyzer `JoinSettings` /
  `QueryPlanSerializationSettings` path.
- `join_decompressed_columns_cache_bytes` (UInt64, default 128 MiB): bounds the
  per-join cache of decompressed right-side blocks used during the probe phase.

Build side: `shrinkStoredBlocksToFit` and the shrink-on-insert path in
`addBlockToJoin` compress stored columns (`IColumn::compress`) when the setting
is on, setting `have_compressed`. Reranging is skipped for compressed data.

Probe side: stored `ColumnsInfo` are decompressed on demand through a thread-safe
`CacheBase` keyed by the stored block pointer (so a block is decompressed once and
reused). The lazy `buildOutputFromBlocks` path, the limit/offset path, `joinGet`,
the non-lazy ANY path, and the RIGHT/FULL non-joined-rows streams all translate
stored pointers through the cache; `buildOutputFromRowRefLists` (which reads raw
`RowRefList` pointers) is bypassed when compression is active.

Performance (measured, 2M-row 1:1 `INNER JOIN`, full payload through the join):
compressible payload shrinks the build side ~2.4x (402 -> 168 MiB) at ~1.85x
probe time; incompressible payload saves no memory but still costs ~1.5x. Hence
the feature is opt-in and only triggers under memory pressure: it lets a
memory-bound compressible join complete in memory instead of failing or spilling.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants