Repository navigation
Cherry pick #101494 to 26.2: Defer dedup data hash computation to eliminate squashing overhead - #101734
Merged
Conversation
…ng squashing During INSERT with `deduplicate_insert=enable`, `calculateDataHash` was called eagerly in `updateOriginalBlock` on every squashing step. For 10M rows this meant ~17 intermediate hash computations (each O(rows * columns) with SipHash), all discarded except the last. This caused ~1.7s overhead (2.06s vs 0.35s for Engine=Null, 2.27s vs 0.67s for MergeTree). The fix defers hash computation: `updateOriginalBlock` stores the block with COW-shared columns instead of computing the hash eagerly and discarding. The hash is computed lazily on first access in the sink via `calculateDataHash`, which caches the result and then releases the block columns. After the fix, dedup ON/OFF performance is identical (0.19s/0.36s Null, 0.66s/0.66s MergeTree for 10M rows, 13 columns). Ref: #99241 Co-Authored-By: Claude Opus 4.6 <[email protected]>
Adds a performance test comparing INSERT with `deduplicate_insert=enable` vs `disable` on both Engine=Null (isolates hash overhead) and MergeTree (combined overhead with part writes). Uses 5M rows, 13 columns, INSERT SELECT with ORDER BY ALL to make the query deduplication-eligible. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Prevents parts from piling up across iterations, keeping each run independent. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Use rand() in one column so each run produces unique data hashes, preventing the dedup log from suppressing writes on subsequent iterations. Also truncate MergeTree table between runs to avoid accumulating parts. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Without non_replicated_deduplication_window the dedup log is inactive, so getDeduplicationHashes returns empty and the hash is never computed — making the MergeTree benchmark meaningless. Also switch to ORDER BY () to isolate dedup overhead from sorting cost. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Add `IColumn::updateHashWithValueRange` virtual method that hashes a range of rows in one call. The default implementation loops row-by-row; overrides in `ColumnVector`, `ColumnDecimal`, `ColumnFixedString`, `ColumnString`, `ColumnArray`, `ColumnNullable`, `ColumnTuple`, and `ColumnMap` feed contiguous memory to SipHash, eliminating per-row virtual dispatch. `InsertDeduplication` now uses `calculateDataHashBatch` (calling the new method) for the unified hash path. The old row-by-row path is kept for backward-compatible hashes during the `COMPATIBLE_DOUBLE_HASHES` period. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Add Decimal64, Float64, DateTime64, FixedString, String, Array, Nullable, Tuple, and Map columns to exercise all `updateHashWithValueRange` overrides. Add a query with `insert_deduplication_token` to show zero hash overhead when a user token is set. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Add tables for Decimal64, Float64, FixedString, String, Array, Nullable, Tuple, Map, and a mixed-types table to `03711_deduplication_blocks_part_log`. This verifies that `updateHashWithValueRange` batch hashing produces stable deduplication hashes for every overridden column type. Update reference hashes: the unified hash changed for tables containing String and other variable-length columns because batch hashing feeds data differently to SipHash. The old (row-by-row) hash is unchanged. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Add async insert tables for UInt32, String, Array, and mixed types to `03711_deduplication_blocks_part_log`. Async inserts compute data hash directly from the block via `calculateDataHashBatch`, exercising the batch hashing path independently from the sync MergeTreePartWriter path. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…pdateHashWithValueRange
Co-authored-by: clickhouse-gh[bot] <173705893+clickhouse-gh[bot]@users.noreply.github.com>
`doExtend` resets `data_hash` when the token range changes but missed resetting `data_hash_batch`, which could leave a stale cached value for the unified hash path. #101494 (comment) Co-Authored-By: Claude Opus 4.6 <[email protected]>
The comment said `calculateDataHash` releases columns, but after refactoring the release moved to `getDeduplicationHashes`. #101494 (comment) Co-Authored-By: Claude Opus 4.6 <[email protected]>
…ults `calculateDataHash` → `calculateDataHashRowWise` (row-major iteration) `calculateDataHashBatch` → `calculateDataHashColumnWise` (column-major iteration) The naming makes it obvious that these are two distinct hash algorithms producing different values, not just different implementations of the same hash. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…heck The flaky check randomizes MergeTree settings, which changes serialized bytes and deduplication hashes. Pin all serialization-affecting settings at the table level: - `index_granularity = 8192` on all tables (compact parts interleave columns per-granule, so different boundaries change the hash) - `dynamic_serialization_version = 'v2'` on Dynamic table - `object_serialization_version`, `object_shared_data_serialization_version`, `object_shared_data_serialization_version_for_zero_level_parts` on JSON tables Also qualify all table names with `03711_database.` prefix — the flaky check uses a randomized default database, so unqualified names landed in the wrong database and the `part_log` query returned empty results. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
…head Defer dedup data hash computation to eliminate squashing overhead
Contributor
Member
|
The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #101494
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job