Skip to content

async insert deduplication with materialized view - #89140

Merged
CheSema merged 3 commits into
masterfrom
chesema-async-insert-dedup
Dec 24, 2025
Merged

CheSema merged 3 commits into
masterfrom
chesema-async-insert-dedup

Conversation

@CheSema

@CheSema CheSema commented Oct 29, 2025 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • New Feature

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

Async insert deduplication now works with dependent materialized views. When collision by block_id occurs, the original block is filtered to remove rows associated with the block_id, and the remaining rows are transformed with all relevant materialized views select queries, this rebuilds original block without conflicting rows.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

@CheSema
CheSema force-pushed the chesema-async-insert-dedup branch 2 times, most recently from 6ff7258 to f96b2b9 Compare October 29, 2025 11:15
@clickhouse-gh

clickhouse-gh Bot commented Oct 29, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ae44682]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_asan, distributed plan, parallel, 2/2) failure
02346_text_index_parallel_replicas FAIL issue
Stateless tests (amd_tsan, s3 storage, sequential, 2/2) failure
Start ClickHouse Server failure
Integration tests (amd_tsan, 2/6) failure
test_storage_s3_queue/test_5.py::test_shutdown_order FAIL
Integration tests (amd_tsan, 4/6) failure
test_restore_db_replica/test.py::test_query_after_restore_db_replica[rename table-with exists table-no restart] FAIL issue
BuzzHouse (amd_debug) failure
Logical error: 'Inconsistent AST formatting: the query: (STID: 1941-1bfa) FAIL issue
Finish Workflow failure
python3 ./ci/jobs/scripts/workflow_hooks/feature_docs.py failure
Stateless tests (arm_asan, targeted) error

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Oct 29, 2025
for (auto & path : conflict_block_ids_paths)
conflict_block_ids.push_back(fs::path(path).filename());

auto deduplicated_block = partition.block_with_partition.deduplication_info->deduplicateBlock(

@CheSema CheSema Oct 29, 2025 •

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.

The main point of this change is here.
DeduplicationInfo rebuilds block by filtering the original block and reapplying all the transformations from the relevant materialized views.

@CheSema
CheSema force-pushed the chesema-async-insert-dedup branch 11 times, most recently from 3c48318 to 59a9004 Compare October 31, 2025 16:38
@CheSema
CheSema force-pushed the chesema-async-insert-dedup branch 13 times, most recently from 8b021f3 to 2d9a6ea Compare November 7, 2025 13:37
@CheSema
CheSema force-pushed the chesema-async-insert-dedup branch 9 times, most recently from e62c9e7 to 404c97c Compare November 28, 2025 12:33
@nourhanahmed96

Copy link
Copy Markdown

@CheSema when are we expecting this to be live please?

@CheSema

CheSema commented Nov 30, 2025 •

Copy link
Copy Markdown
Member Author

Sema Checherinda when are we expecting this to be live please?

It would be merged in master in a week or two: it is a lot of code to review.
After that there would be follow up PRs which changes and/or remove some settings which became redundant.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR implements async insert deduplication with dependent materialized views. When a collision by block_id occurs during async inserts, the system now filters the original block to remove conflicting rows and transforms the remaining data through all relevant materialized views' SELECT queries, effectively rebuilding the original block without duplicates.

Key Changes:

  • Replaced token-based deduplication with a comprehensive DeduplicationInfo class that tracks insert dependencies and handles retry logic
  • Modified async insert processing to support deduplication with materialized views by filtering and retrying conflicting blocks
  • Updated test infrastructure to exclude quorum-based tests from async insert execution

Reviewed changes

Copilot reviewed 96 out of 96 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
src/Interpreters/InsertDeduplication.{h,cpp} New comprehensive deduplication tracking system with retry logic
src/Interpreters/InsertDependenciesBuilder.{h,cpp} Enhanced to support deduplication retry chains for materialized views
src/Storages/MergeTree/ReplicatedMergeTreeSink.{h,cpp} Unified async/sync insert handling with collision detection and retry
src/Storages/MergeTree/MergeTreeSink.{h,cpp} Added collision detection and retry logic for non-replicated tables
src/Processors/Transforms/DeduplicationTokenTransforms.{h,cpp} Simplified token transforms, removed debug-only checking code
src/Storages/MergeTree/EphemeralLockInZooKeeper.{h,cpp} Changed block ID handling from template to vector-based
tests/queries/0_stateless/03735_*.{sql,reference} New tests validating async insert deduplication with materialized views
tests/queries/0_stateless/*_quorum*.sql Added no-async-insert tag to exclude incompatible tests
Comments suppressed due to low confidence (6)

tests/queries/0_stateless/03733_async_insert_not_supported.reference:1

  • Corrected spelling of 'sutable' to 'suitable'
    tests/queries/0_stateless/03733_async_insert_not_supported.sql:1
  • Corrected spelling of 'sutable' to 'suitable'
    src/Storages/MergeTree/ReplicatedMergeTreeSink.cpp:1
  • Corrected spelling of 'tokets' to 'tokens'
    src/Storages/MergeTree/MergeTreeSink.cpp:1
  • Corrected spelling of 'tokets' to 'tokens'
    tests/queries/0_stateless/03720_insert_mem_no_self_deduplication.sql:1
  • Corrected spelling of 'excpect' to 'expect'
    tests/queries/0_stateless/03733_async_insert_not_supported.sql:1
  • Corrected spelling of 'chech' to 'check'

Comment thread src/Interpreters/InsertDeduplication.h Resolved
Comment thread src/Interpreters/Squashing.cpp Resolved
@CheSema CheSema mentioned this pull request Dec 3, 2025
@CheSema

CheSema commented Dec 15, 2025

Copy link
Copy Markdown
Member Author

test_concurrent_ttl_merges --- #92128

test_plain_rewritable_backward_compatibility --- #92129

Comment thread src/Common/CollectionOfDerived.h Resolved
Comment thread src/Interpreters/InsertDeduplication.h Resolved
Comment on lines +14 to +15
std::string partition_id;
DeduplicationInfo::Ptr deduplication_info;

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.

Probably can be simplified

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.

Do not see how, it is convenient to pas them here to the finishDelayedChunk call

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.

I moved deduplication_info out of here, but partition_id is just convenient to be here.

@CheSema

CheSema commented Dec 18, 2025

Copy link
Copy Markdown
Member Author

I have here the issue with the AsynchronousInsertQueue::flush
It has mutex, no concurrent flushes.
When it works, other flushes stopped due to flush_stopped var.

I need to address this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature Pull request with new product feature 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.

5 participants