Skip to content

Default insert_deduplication_version to new_unified_hash - #107886

Merged
CheSema merged 23 commits into
masterfrom
chesema/insert-dedup-default-new-unified-hash
Jun 23, 2026
Merged

CheSema merged 23 commits into
masterfrom
chesema/insert-dedup-default-new-unified-hash

Conversation

@CheSema

@CheSema CheSema commented Jun 18, 2026 •

Copy link
Copy Markdown
Member

Advances the second (final) phase of the insert deduplication hash migration introduced by #95409: the default of the server setting insert_deduplication_version changes from compatible_double_hashes to new_unified_hash, so a single unified deduplication hash is used for both sync and async inserts.

Backward-incompatible change to deduplication semantics. The unified hash is computed over the whole inserted block (the source insert, before partition splitting), so insert deduplication now works per insert, not per part/partition. Versus the previous default:

  • A retry of the same insert is still fully deduplicated — idempotency is preserved.
  • Two different inserts that happen to produce an identical part in some partition are no longer cross-deduplicated (the legacy per-part sync hash collided them and silently dropped the second part).
  • Reordered inserts of the same rows are no longer deduplicated (the unified hash is order-sensitive over the source block, matching how async inserts already behaved).
  • Async inserts now use the unified deduplication_hashes directory and the sync deduplication window (replicated_deduplication_window / replicated_deduplication_window_seconds, default 1 hour) instead of the separate async_blocks directory; replicated_deduplication_window_for_async_inserts / …_seconds_for_async_inserts (default 1 week) no longer apply, so the default async-dedup retention window changes from 1 week to 1 hour.

Set insert_deduplication_version = compatible_double_hashes to keep the previous per-part behavior.

Instances upgrading from the previous release default compatible_double_hashes were already writing and checking the unified hash, so for sync inserts this only stops writing the redundant old per-type hash. Async workloads need more care: under compatible_double_hashes an async insert's id stays in async_blocks for the async window (default one week) while its deduplication_hashes id expires after the sync window (default one hour), and new_unified_hash stops checking async_blocks — so before switching async workloads, raise replicated_deduplication_window / replicated_deduplication_window_seconds to the async window and run a full async window, quiesce async inserts for that window, or stay on compatible_double_hashes. Instances upgrading directly from old_separate_hashes should run with compatible_double_hashes for some time (see replicated_deduplication_window / non_replicated_deduplication_window) before relying on the unified hash.

Related: #95409

Changelog category (leave one):

  • Backward Incompatible Change

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

The default of the server setting insert_deduplication_version changes from compatible_double_hashes to new_unified_hash. Insert deduplication now works on the whole inserted block (per insert) rather than per part/partition: a retry of the same insert is still deduplicated, but two different inserts that produce an identical part are no longer cross-deduplicated, and reordered inserts of the same rows are no longer deduplicated. Set insert_deduplication_version = compatible_double_hashes to restore the previous behavior. Async-insert deduplication is also governed by the sync window under new_unified_hash: both whether it is enabled (replicated_deduplication_window) and its retention (replicated_deduplication_window_seconds, default 1 hour) follow the sync settings, so *_for_async_inserts is legacy and applies only to old_separate_hashes / compatible_double_hashes. Instances upgrading directly from a release that defaulted to old_separate_hashes should first run with compatible_double_hashes until the longest relevant deduplication window has elapsed (including replicated_deduplication_window_for_async_inserts, default one week, if async inserts are used) before relying on new_unified_hash. Async workloads switching from compatible_double_hashes should first raise replicated_deduplication_window[_seconds] to the async window (and run a full async window), quiesce async inserts, or stay on compatible_double_hashes, because new_unified_hash no longer checks the longer-lived async_blocks ids.

🤖 Generated with Claude Code

…ied_hash

Advance the second phase of the insert deduplication hash migration. The
default server setting moves from `compatible_double_hashes` to
`new_unified_hash`, so ClickHouse uses a single unified deduplication hash
for both sync and async inserts by default.

Instances upgraded directly from `old_separate_hashes` should still run
with `compatible_double_hashes` for some time (see
`replicated_deduplication_window` / `non_replicated_deduplication_window`)
before relying on the unified hash.

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 [9a5edf2]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_asan_ubsan, flaky check) FAIL
03008_deduplication_cases_from_docs FAIL cidb

AI Review

Summary

This PR flips the default insert_deduplication_version to new_unified_hash, documents the resulting per-insert deduplication semantics and async-window migration caveats, aligns the async deduplication enable gate with the unified sync window, and updates focused functional/integration coverage for the new default and the still-supported compatible_double_hashes path. I did not find any unresolved correctness, migration, or test-coverage issue that needs a new inline comment.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Jun 18, 2026
Comment thread src/Core/ServerSettings.cpp Resolved
Comment thread src/Core/ServerSettings.cpp Resolved
Regenerated reference files for the deduplication tests affected by the
default of insert_deduplication_version moving to new_unified_hash. None
of these tests set the setting explicitly, so they observe the new default:
sync and async inserts now share a single unified deduplication hash, and
the old per-type async self-deduplication no longer applies.

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

CheSema commented Jun 18, 2026

Copy link
Copy Markdown
Member Author

It waits #107915

CheSema and others added 2 commits June 19, 2026 00:46
…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]>
Comment thread src/Core/ServerSettings.cpp Resolved
Comment thread src/Columns/ColumnString.cpp Resolved
CheSema and others added 2 commits June 19, 2026 14:39
01781_merge_tree_deduplication, 03008_deduplication_cases_from_docs and
03008_deduplication_insert_into_partitioned_table now reflect new_unified_hash
behaviour: the non-replicated deduplication window is no longer halved (one id
per insert), and deduplication is per insert, so different inserts that share a
partition's content are not cross-deduplicated. Also update the now-inaccurate
message in 03008_deduplication_insert_into_partitioned_table.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
CheSema and others added 3 commits June 19, 2026 18:38
Flipping the default to new_unified_hash changes the test-server behavior:
deduplication entries are written only to /deduplication_hashes, not /blocks.

- 00953: drop the /blocks cleanup waits (that znode is no longer written) and
  fix the stale comment; keep the /deduplication_hashes waits.
- 01158_zookeeper_log_long: regenerate the reference (the /blocks Create/Check
  operations are gone; only the unified /deduplication_hashes znode remains).
- 03711_deduplication_blocks_part_log: regenerate the reference (each part now
  records the single unified block id instead of the old+unified pair).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
- insert_deduplication_version: reword the stale old_separate_hashes line (no
  longer the recommended default) and state that new_unified_hash keys
  deduplication on the whole inserted block (per insert, not per partition).
- insert_deduplication_token: the note claimed partition-level dedup "the same
  as the checksum"; under the new default the no-token checksum is over the
  whole inserted block, so correct the note accordingly.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Two more tests assumed the legacy /blocks znode (flagged by the AI review):
- 01650_drop_part_and_deduplication_zookeeper_long: reworked to exercise the
  DROP PART + deduplication interaction under per-insert semantics. An identical
  retry is fully deduplicated; DROP PART removes that partition's
  deduplication_hashes entry; a following retry re-creates only the dropped
  partition while the others stay deduplicated. Reference regenerated.
- test_extreme_deduplication: wait on the deduplication_hashes znode (not
  /blocks) for the dedup-window cleanup.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Comment thread src/Core/ServerSettings.cpp Resolved
Three more tests assumed the legacy per-part sync hash:
- 00215_primary_key_order_zookeeper_long: the six reordered inserts of the same
  values no longer collapse (the unified hash is over the source block, like
  async -- order-sensitive), so the reference now has all 18 rows. Regenerated.
- 03711_merge_tree_deduplication_with_disk...append: identical single-row
  re-inserts within the window now deduplicate (the unified content hash catches
  retries the old sync path missed). Regenerated.
- 04005_dedup_cleanup_consistent_across_directories: drop the /blocks cleanup
  waits (only deduplication_hashes is written now) and reword the preamble; its
  dual-directory regression scenario cannot occur with a single directory.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
03008_deduplication.python computed the insert_unique_blocks=False expected
counts from the old per-part hash, where N identical blocks in one insert
collapsed to one. Under new_unified_hash those blocks are kept (distinct source
numbers), so the no-token case now matches the token branch -- collapse the two.
Regenerate the six dedicated per-scenario references with the new counts; all 64
combos pass in insert_several_blocks / mv_generates_several_blocks /
several_mv_into_one_table (replicated and non-replicated).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Comment thread src/Core/ServerSettings.cpp Resolved
Under the new default, async inserts write dedup ids to the unified
deduplication_hashes directory (cleaned by replicated_deduplication_window /
_seconds), not the legacy async_blocks. The *_for_async_inserts window settings
therefore apply only to old_separate_hashes / compatible_double_hashes:
- mark those two settings legacy in their docs,
- note the async behavior in the insert_deduplication_version description,
- adapt 02515_cleanup_async_insert_block_ids to wait on deduplication_hashes under
  the sync window (verified [ OK ]).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added pr-backward-incompatible Pull request with backwards incompatible changes and removed pr-improvement Pull request with some product improvements labels Jun 22, 2026
04005 was reworked for the new default new_unified_hash (single
deduplication_hashes directory), dropping coverage of the dual-directory
cleanup under compatible_double_hashes (legacy blocks + unified
deduplication_hashes cleaned together). compatible_double_hashes is still a
supported migration mode selectable only via a server setting, so move that
invariant to an integration test on node_compatible: sync inserts populate
both directories and the cleanup thread trims them to
replicated_deduplication_window consistently.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
The direct-upgrade guidance for insert_deduplication_version mentioned only the
sync and non-replicated windows. Pre-upgrade async-insert ids live in async_blocks
and expire by replicated_deduplication_window[_seconds]_for_async_inserts (default
one week), which new_unified_hash does not consult. Running compatible_double_hashes
for only the sync window before switching to new_unified_hash could therefore accept
retries of pre-upgrade async inserts as duplicates. Tell users to wait for the
longest relevant window (sync, async, non-replicated) before relying on the unified hash.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@Michicosun Michicosun self-assigned this Jun 22, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 38 queries analysed

This PR only changes insert-side deduplication: it flips the default insert_deduplication_version from compatible_double_hashes to new_unified_hash and updates the ReplicatedMergeTree/SharedMergeTree insert sinks, settings docs, and tests. ClickBench Q4 (-14.8%) and Q15 (-18.3%) are read-only SELECT queries against an already-loaded dataset, so they never exercise the modified insert path. Both flagged improvements are off-path and consistent with run-to-run variance on a smaller source sample (6 runs vs 30), so we downgraded them to not-sure rather than crediting the PR. No real query-execution change is expected from this default flip.

clickbench

⚠️ 2 inconclusive

Flagged queries (2 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 4 not_sure 264 225 -14.8% <0.0001 PR only flips INSERT dedup-version default; Q4 is a read-only SELECT, off-path. ~15% delta is run-to-run variance.
⚠️ 15 not_sure 251 205 -18.3% <0.0001 PR only changes INSERT dedup sink code; Q15 SELECT never touches it. Improvement is noise, not a PR effect.

q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: d1da239b-6bf7-4ac8-b5a8-b42cbdcd59e9
  • MIRAI run: 3f23e447-b108-46dd-8bf1-09f50c0e300d
  • PR check IDs:
    • clickbench_11522_1782244569
    • clickbench_11536_1782244569
    • clickbench_11541_1782244569
    • tpch_adapted_1_official_11548_1782244569
    • tpch_adapted_1_official_11552_1782244569
    • tpch_adapted_1_official_11560_1782244569

…unified_hash

Under the new default insert_deduplication_version=new_unified_hash, deduplication is
keyed by the insert source, so 02434_cancel_insert_when_client_dies (which inserted the
same data through several sources expecting them all to cross-deduplicate) no longer holds
its 500000-row invariant. Split it so each source is exercised by its own test, where
same-source cancelled-and-retried inserts still deduplicate:
- 02434: direct inserts into the table (native / HTTP / HTTP chunked, which share a source id),
- 04365: distributed-table inserts (distributed_foreground_insert for a consistent row count),
- 04366: INSERT SELECT from an uploaded file, with ORDER BY for deterministic block order.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Comment thread src/Core/ServerSettings.cpp Resolved
The direct-upgrade note said pre-upgrade retries "can be accepted as duplicates",
which reads as if deduplication happened. Under new_unified_hash the old blocks /
async_blocks ids are not consulted, so such a retry is accepted as a new insert and
produces duplicate rows. Reword accordingly.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ied_hash

The setting's description still documented the legacy per-created-part checksum,
inconsistent with the default new_unified_hash (whole inserted block, per-insert dedup)
that the async-insert note points users to. Describe the default behavior and mention the
per-created-part hash only for old_separate_hashes / compatible_double_hashes.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Comment thread src/Core/ServerSettings.cpp Resolved
CheSema and others added 2 commits June 22, 2026 23:59
…unified_hash

Like replicated_deduplication_window, the non-replicated setting's description still
referred to per-created-part hash sums. Note that its deduplication granularity follows
insert_deduplication_version the same way (whole inserted block under the default
new_unified_hash, per created part under the legacy versions), as for replicated tables.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Under compatible_double_hashes an async insert's deduplication_hashes id expires at the
sync window while its async_blocks id persists for the async window, so its dedup
effectively spans the async window. Switching to new_unified_hash (which consults only
deduplication_hashes) drops that to the sync window, re-exposing async inserts older than
the sync window. Document the mitigations (raise the sync window, quiesce, or stay
compatible) in the migration note.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Comment thread src/Core/ServerSettings.cpp Resolved
…e_hashes

test_parallel_replicas_protocol builds a 3-replica ReplicatedMergeTree from two old (24.3)
nodes and one new node, each inserting the same data and relying on insert deduplication to
keep a single copy. Under the new default insert_deduplication_version=new_unified_hash the
new node writes only the unified hash and no longer cross-deduplicates with the old replicas'
legacy hash, so the table gets a second copy and sum(a) doubles. Pin the new node to
compatible_double_hashes (the mixed-version migration setting) so it writes the legacy hash
too and deduplicates against the 24.3 replicas.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
CheSema and others added 2 commits June 23, 2026 11:43
04204 Part 2 distinguished the async insert path from the sync path through the
legacy per-source async window (replicated_deduplication_window_for_async_inserts).
Under the new default new_unified_hash both paths share the sync window, so the
parity check holds (6 == 6) even if the Alias sink drops async_insert, and the
regression is no longer caught.

Add an integration test on node_compatible (pinned to compatible_double_hashes)
that replicates the direct-vs-Alias async-window parity, restoring the
discriminating coverage under the legacy window. Note the limitation in 04204.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.30% 85.30% +0.00%
Functions 92.50% 92.50% +0.00%
Branches 77.60% 77.50% -0.10%

Changed lines: Changed C/C++ lines covered by tests: 78/78 (100.00%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 6 line(s) · Uncovered code

Full report · Diff report

@CheSema
CheSema added this pull request to the merge queue Jun 23, 2026
Merged via the queue into master with commit 73aa0f6 Jun 23, 2026
164 of 167 checks passed
@CheSema
CheSema deleted the chesema/insert-dedup-default-new-unified-hash branch June 23, 2026 21:06
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 23, 2026
huldarchen pushed a commit to huldarchen/ClickHouse that referenced this pull request Jul 6, 2026
The `insert_deduplication_version` migration is complete — `new_unified_hash`
became the default in ClickHouse#107886. As the first step of removing the setting and
its alternatives, `DeduplicationInfo` now always computes the unified
deduplication hash.

Drop the `unification_stage` (`InsertDeduplicationVersions`) parameter from
`DeduplicationInfo::create` and `AddDeduplicationInfoTransform`, and remove the
unreachable old per-block hash path (`getBlockHash`). The call sites in
`InterpreterInsertQuery`, `AsynchronousInsertQueue` and `ObjectStorageQueueSource`
no longer read the server setting for this.

No behaviour change under the `new_unified_hash` default: only the
`old_separate_hashes` / `compatible_double_hashes` paths are removed. The setting
and the `InsertDeduplicationVersions` enum remain for now (still used by
`ReplicatedMergeTreeSink` and `ReplicatedMergeTreeRestartingThread`) and are
removed in follow-up commits.
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…edup-default-new-unified-hash

Default insert_deduplication_version to new_unified_hash
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
The `insert_deduplication_version` migration is complete — `new_unified_hash`
became the default in ClickHouse#107886. As the first step of removing the setting and
its alternatives, `DeduplicationInfo` now always computes the unified
deduplication hash.

Drop the `unification_stage` (`InsertDeduplicationVersions`) parameter from
`DeduplicationInfo::create` and `AddDeduplicationInfoTransform`, and remove the
unreachable old per-block hash path (`getBlockHash`). The call sites in
`InterpreterInsertQuery`, `AsynchronousInsertQueue` and `ObjectStorageQueueSource`
no longer read the server setting for this.

No behaviour change under the `new_unified_hash` default: only the
`old_separate_hashes` / `compatible_double_hashes` paths are removed. The setting
and the `InsertDeduplicationVersions` enum remain for now (still used by
`ReplicatedMergeTreeSink` and `ReplicatedMergeTreeRestartingThread`) and are
removed in follow-up commits.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backward-incompatible Pull request with backwards incompatible changes 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.

3 participants