Skip to content

Fix position-dependent column-wise insert deduplication hash - #107915

Merged
CheSema merged 5 commits into
masterfrom
chesema/fix-dedup-columnwise-hash-position
Jun 19, 2026
Merged

CheSema merged 5 commits into
masterfrom
chesema/fix-dedup-columnwise-hash-position

Conversation

@CheSema

@CheSema CheSema commented Jun 18, 2026 •

Copy link
Copy Markdown
Member

ColumnString::updateHashWithValueRange and ColumnArray::updateHashWithValueRange hashed the absolute cumulative offsets of the [begin, end) row range. Because the offsets are cumulative, the same value at a different position has a different offset, so the hash depended on the row's position in the column rather than only on its content.

These methods are used only by the column-wise data hash of the unified insert deduplication path (server setting insert_deduplication_version = new_unified_hash and compatible_double_hashes). As a result, two identical blocks located at different offsets — e.g. repeated rows combined into one asynchronous insert flush — produced different deduplication block ids and were not deduplicated. Fixed-width columns (UInt32, …) are position-invariant and did not expose the bug.

The fix hashes the boundaries relative to the start of the range, so equal data hashes equally regardless of its position.

This changes the unified deduplication hashes, which needs no backward compatibility: under the default compatible_double_hashes, deduplication correctness comes from the legacy id (unchanged here), so the unified id only becomes authoritative once new_unified_hash is the default — and the previously-broken unified hashes are not worth preserving.

Tests (both fail before the fix, pass after):

  • a unit test deduplicating equal String blocks located at different offsets (gtest_async_inserts);
  • an integration test doing async self-deduplication under new_unified_hash with String and Array columns (test_migration_deduplication_hash).

Related: #95409
Related: #107886

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 insert deduplication computing wrong hashes for String and Array columns with the server setting insert_deduplication_version = new_unified_hash: identical inserts could fail to deduplicate because the deduplication hash depended on the row's position within the inserted block.

🤖 Generated with Claude Code

Version info

  • Merged into: 26.6.1.1028
  • Backported to: 26.5.3.49, 26.4.5.56, 26.3.14.46

ColumnString::updateHashWithValueRange and ColumnArray::updateHashWithValueRange
hashed the absolute cumulative offsets of the row range, so the hash depended on
the position of the range within the column. This function computes the
column-wise data hash used by the unified insert deduplication path
(insert_deduplication_version = new_unified_hash and compatible_double_hashes),
so two identical blocks located at different offsets - e.g. repeated rows
combined into one async insert flush - produced different deduplication block ids
and were not deduplicated. Fixed-width columns were already position-invariant.

Hash the boundaries relative to the start of the range instead. For begin == 0
(every single-block insert) the bytes fed to the hash are unchanged, so unified
deduplication ids already persisted under compatible_double_hashes stay valid;
only the broken multi-offset case changes.

Add a unit test (equal String blocks at different offsets) and an integration
test (async self-deduplication under new_unified_hash with String and Array
columns). Both fail before the fix and pass after.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [97d614e]

Summary: ❌

job_name test_name status info comment
Stress test (arm_debug) FAIL
Cannot start clickhouse-server FAIL cidb
Logical error: 'Unexpected exception in refresh scheduling' (STID: 2508-34af) FAIL cidb
Check failed FAIL cidb
BuzzHouse (amd_msan) ERROR

AI Review

Summary

This PR makes the unified insert deduplication hash position-independent for variable-length String and Array ranges by hashing relative boundaries in ColumnString::updateHashWithValueRange and ColumnArray::updateHashWithValueRange. The change is scoped to the new_unified_hash column-wise data hash path and includes focused unit/integration regression coverage; I did not find issues requiring changes.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 18, 2026
Comment thread src/Columns/ColumnString.cpp Resolved
… byte stream

Use the raw-byte SipHash overload for the computed relative offset instead of
SipHash::update(UInt64), which endian-normalizes the value on big-endian targets.
This keeps the begin == 0 byte stream identical to the previous absolute-offset
hashing on all architectures (including s390x), so unified deduplication ids
already persisted under compatible_double_hashes stay valid there too.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
CheSema added a commit that referenced this pull request Jun 18, 2026
…fault"

This reverts commit 36d9384.

The reference changes are regenerated after the unified deduplication hash fix
in #107915 lands, so that only the
genuinely intended changes remain (the async tests pass the original references
once the hash is fixed).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@george-larionov george-larionov self-assigned this Jun 18, 2026

@george-larionov george-larionov 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.

LGTM, just a few comments about the comments.

Comment thread src/Columns/ColumnString.cpp Outdated
hash.update(reinterpret_cast<const char *>(&chars[chars_begin]), chars_end - chars_begin);
hash.update(reinterpret_cast<const char *>(&offsets[begin]), (end - begin) * sizeof(offsets[0]));
/// Relative offsets: equal data must hash equally at any position in the column (deduplication).
/// Raw bytes, not the integer overload that normalizes byte order on big-endian.

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.

This comment is kind of confusing to me. Do you mean that we use the raw bytes version for back compatibility with existing hashes? If so, maybe add a note For back-compat: ...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We can use the numbers here. That make the bot happy. But you are right no need to keep backward compatibility with version with bug.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Will do it cleaner here.

Comment thread src/Columns/ColumnArray.cpp Outdated
size_t nested_end = offsetAt(end);
getData().updateHashWithValueRange(nested_begin, nested_end, hash);
hash.update(reinterpret_cast<const char *>(&getOffsets()[begin]), (end - begin) * sizeof(getOffsets()[0]));
/// Relative offsets as raw bytes, see ColumnString::updateHashWithValueRange.

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.

See other comment

CheSema and others added 2 commits June 19, 2026 10:21
…pat note

The unified deduplication hash is not authoritative until new_unified_hash is the
default: under compatible_double_hashes the legacy id (unchanged here) provides
deduplication, so the previously-broken unified hashes do not need to be preserved.
Use the plain SipHash integer update and a clearer comment instead of the raw-byte
overload that was only there for byte-identity.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.20% 85.30% +0.10%
Functions 92.60% 92.60% +0.00%
Branches 77.50% 77.50% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 43/43 (100.00%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@CheSema
CheSema enabled auto-merge June 19, 2026 12:04
@CheSema
CheSema added this pull request to the merge queue Jun 19, 2026
Merged via the queue into master with commit 7a4d256 Jun 19, 2026
163 of 166 checks passed
@CheSema
CheSema deleted the chesema/fix-dedup-columnwise-hash-position branch June 19, 2026 12:21
robot-clickhouse added a commit that referenced this pull request Jun 19, 2026
Cherry pick #107915 to 26.4: Fix position-dependent column-wise insert deduplication hash
robot-clickhouse added a commit that referenced this pull request Jun 19, 2026
robot-clickhouse added a commit that referenced this pull request Jun 19, 2026
Cherry pick #107915 to 26.5: Fix position-dependent column-wise insert deduplication hash
robot-clickhouse added a commit that referenced this pull request Jun 19, 2026
CheSema added a commit that referenced this pull request Jun 19, 2026
Cherry pick #107915 to 26.3: Fix position-dependent column-wise insert deduplication hash
robot-clickhouse added a commit that referenced this pull request Jun 19, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 19, 2026
@CheSema CheSema removed the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 19, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jun 19, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 19, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jun 19, 2026
CheSema added a commit that referenced this pull request Jun 19, 2026
Backport #107915 to 26.4: Fix position-dependent column-wise insert deduplication hash
CheSema added a commit that referenced this pull request Jun 19, 2026
Backport #107915 to 26.5: Fix position-dependent column-wise insert deduplication hash
CheSema added a commit that referenced this pull request Jun 19, 2026
Backport #107915 to 26.3: Fix position-dependent column-wise insert deduplication hash
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…7915

Backport ClickHouse#107915 to 26.4: Fix position-dependent column-wise insert deduplication hash
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…7915

Backport ClickHouse#107915 to 26.3: Fix position-dependent column-wise insert deduplication hash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.2-must-backport v26.3-must-backport v26.4-must-backport v26.5-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants