Repository navigation
Fix position-dependent column-wise insert deduplication hash - #107915
Conversation
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]>
|
Workflow [PR], commit [97d614e] Summary: ❌
AI ReviewSummaryThis PR makes the unified insert deduplication hash position-independent for variable-length Final VerdictStatus: ✅ Approve |
… 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]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…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
left a comment
There was a problem hiding this comment.
LGTM, just a few comments about the comments.
| 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. |
There was a problem hiding this comment.
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: ...
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Will do it cleaner here.
| 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. |
…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]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 43/43 (100.00%) | Lost baseline coverage: none · Uncovered code |
Cherry pick #107915 to 26.4: Fix position-dependent column-wise insert deduplication hash
Cherry pick #107915 to 26.5: Fix position-dependent column-wise insert deduplication hash
Cherry pick #107915 to 26.3: Fix position-dependent column-wise insert deduplication hash
Backport #107915 to 26.4: Fix position-dependent column-wise insert deduplication hash
Backport #107915 to 26.5: Fix position-dependent column-wise insert deduplication hash
Backport #107915 to 26.3: Fix position-dependent column-wise insert deduplication hash
…e insert deduplication hash
…7915 Backport ClickHouse#107915 to 26.4: Fix position-dependent column-wise insert deduplication hash
…e insert deduplication hash
…7915 Backport ClickHouse#107915 to 26.3: Fix position-dependent column-wise insert deduplication hash
ColumnString::updateHashWithValueRangeandColumnArray::updateHashWithValueRangehashed 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_hashandcompatible_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 oncenew_unified_hashis the default — and the previously-broken unified hashes are not worth preserving.Tests (both fail before the fix, pass after):
Stringblocks located at different offsets (gtest_async_inserts);new_unified_hashwithStringandArraycolumns (test_migration_deduplication_hash).Related: #95409
Related: #107886
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed insert deduplication computing wrong hashes for
StringandArraycolumns with the server settinginsert_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
26.6.1.102826.5.3.49,26.4.5.56,26.3.14.46