Skip to content

UNIQUE KEY: read - #123008

Merged
murphy-4o merged 18 commits into
masterfrom
unique-key/stack-test/read
Oct 18, 2026
Merged

murphy-4o merged 18 commits into
masterfrom
unique-key/stack-test/read

Conversation

@murphy-4o

@murphy-4o murphy-4o commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Part of #103486

A SELECT on a UNIQUE KEY table now skips the rows its delete bitmaps kill: the query pins one bitmap
snapshot, index analysis drops granules whose rows are all dead, the reader filters the rest by
_part_offset, and count() subtracts dead rows.

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Workflow [PR]
Sync PR [sync-upstream/pr/123008]

Version info

  • Merged into: 26.11.1.145-master (included in 26.11 and later)

…snapshot, and show the bitmaps in system.parts

- ReadSnapshot pins one snapshot per query (MergeTreeData::createStorageSnapshot), held by
  shared_ptr in SnapshotData, and memoizes each part's bitmap for every reader.
- ReadFromMergeTree drops fully dead granules after index analysis, forces _part_offset while a
  bitmap is non-empty, and gives lazy materialization a snapshot without the bitmaps.
- The read pool hands each task its bitmap (MergeTreeReadTask); MergeTreeSelectProcessor applies
  it; getReadTaskColumns keeps _part_offset after PREWHERE.
- count() subtracts dead rows (StorageMergeTree::totalRows*, ReadSnapshot::liveRows).
- system.parts.unique_key_bitmap_versions, and the PINNED_BY_DELETE_BITMAP removal-state text.
- UniqueKeyBitmapGranulesSkipped and UniqueKeyBitmapRowsSkipped ProfileEvents.
- Tests: the Insert cases that read an overwrite back through SELECT: 04105 cases 1-3, 04107,
  04168 case 2. Read's own 04163 and 04670 make dead rows with DELETE and land with Delete.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@murphy-4o
murphy-4o added this pull request to stack #123004 September 30, 2026 06:23
@clickhouse-gh

clickhouse-gh Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [93fad15]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_binary, s3 storage, DBReplicated, sequential) FAIL
03821_drop_workload_during_query_race FAIL cidb IGNORED

AI Review

Summary

This PR makes UNIQUE KEY reads pin a consistent part/bitmap snapshot, discard deleted rows before PREWHERE, prune fully deleted granules, and subtract deleted rows from metadata counts. Reviewed head: 93fad158234422646d475533fcc3ca3133fbc37a. Two previously reported wrong-result paths remain: minmax top-k and vector-index candidate selection run before bitmap filtering. Their proposed fix, #124799, is open and absent from this head. No additional findings.

Findings

❌ Blockers

  • Minmax top-k must rank live candidates. src/Processors/QueryPlan/ReadFromMergeTree.cpp:2832: partHasStaleTopKIndex ignores unique-key bitmaps, so getTopKMarks can discard the live winners before this pruning runs. With one row per mark, insert (k,v) = (1,0),(2,10), then overwrite key 1 with (1,100). ORDER BY v LIMIT 1 with use_skip_indexes_for_top_k=1, use_skip_indexes_on_data_read=0, and use_top_k_dynamic_filtering=0 can return no row instead of (2,10). Disable fixed-size minmax selection for these tables or make it bitmap-aware. Existing thread; reopened because the claimed fix is absent from the reviewed code.

  • Vector candidate budgets must exclude bitmap-deleted neighbours. src/Storages/MergeTree/MergeTreeReadPoolBase.cpp:452: the vector-index eligibility check at MergeTreeDataSelectExecutor.cpp:1274 ignores unique-key bitmaps. Filtering candidates here cannot retrieve live neighbours excluded from the shortlist. For keys 1,2 with vectors [0,0],[1,0] in one granule, overwrite key 1 with [100,0]. Nearest-neighbour search against [0,0], LIMIT 1, vector_search_with_rescoring=0, and vector_search_index_fetch_multiplier=1 can return the distant replacement instead of key 2. Disable vector-index selection for these tables or make selection bitmap-aware. [dismissed by author -- https://github.com/UNIQUE KEY: read #123008#discussion_r4300855293] The author deferred the guard to the separate open PR; the current head still permits this wrong result. The thread remains closed and receives no duplicate comment.

Tests
  • ⚠️ Include focused stateless regressions comparing minmax top-k enabled/disabled and vector-index search/full-scan results after overwrites. Cover a partially deleted granule so whole-granule pruning cannot mask the defect. The regressions proposed in the separate PR are not present here.
Missing context / blind spots
  • ⚠️ No local build or server binary was available, so the failure cases above were traced through source rather than executed locally. Run the focused regressions against this head to validate the outputs. The published Praktika report reports no failed tests.
Final Verdict

Status: ❌ Block. Incorporate the minmax and vector-index guards from #124799 into the reviewed stack, with the focused regressions, before merging this read layer.

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. labels Sep 30, 2026
murphy-4o and others added 2 commits September 30, 2026 15:50
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 93fad1582 with master 0a3052562 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

27 object files changed (+130.80 KiB total), 1 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/MergeTree/UniqueKey/DeleteBitmapSnapshot.cpp.o new 86.73 KiB +86.73 KiB
src/CMakeFiles/dbms.dir/Storages/MergeTree/MergeTreeData.cpp.o 4.27 MiB 4.29 MiB +18.99 KiB (+0.43%)

719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

287 translation units recompiled, 2926 s compile time in total, 286 of them have a recent master baseline.

Translation units without a recent master baseline:

  • src/Storages/MergeTree/UniqueKey/DeleteBitmapSnapshot.cpp: 7.7 s
Symbol sizes
Binary Symbol Master PR Δ
programs/clickhouse-keeper ProfileEvents::global_counters_storage 13.31 MiB 13.38 MiB +64.00 KiB (+0.47%)
programs/clickhouse ProfileEvents::global_counters_storage 13.31 MiB 13.38 MiB +64.00 KiB (+0.47%)

Job report

murphy-4o and others added 2 commits September 30, 2026 21:35
The read snapshot carries its reader's tid, and the storage snapshot and the trivial counts filter
parts at that csn and tid: a UNIQUE KEY commit publishes its part Active before its commit point,
so an overwritten key read twice while it committed. 04196 pauses an INSERT between the two.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Comment thread src/Storages/StorageMergeTree.cpp Resolved
@murphy-4o
murphy-4o marked this pull request as ready for review October 1, 2026 03:50
murphy-4o and others added 5 commits October 4, 2026 09:19
…nFilter, simpler dead-granule pruning

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…x, so clang-tidy sees the write

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	src/Storages/MergeTree/MergeTreeReaderIndex.cpp
@alesapin
alesapin self-requested a review October 16, 2026 12:09
Base automatically changed from unique-key/stack-test/insert to master October 16, 2026 13:04

@alesapin alesapin 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, but let's rename ReadSnapshot

void TransactionManager::tryFinalizeUnknownStateTransactions()
{
/// Test-only: keeps the undetermined state observable; returning, not pausing, leaves `loadEntries` running.
fiu_do_on(FailPoints::transaction_hold_unknown_state, { return; });

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.

It will return from the scope of lambda inside failpoint, not from tryFinalizeUnknownStateTransactions. Basically it's noop.

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.

#define fiu_do_on(name, action) \
        do { \
                if (atomic_load_explicit(&has_any_failpoint_been_registered, memory_order_relaxed)) [[unlikely]] { \
                        if (fiu_fail(name)) [[unlikely]] { \
                                action; \
                        } \
                } \
        } while (0)

it's not a lambda, but just the loop body ?

murphy-4o and others added 3 commits October 17, 2026 09:23
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@murphy-4o
murphy-4o added this pull request to the merge queue Oct 18, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 18, 2026
@murphy-4o
murphy-4o added this pull request to the merge queue Oct 18, 2026
Merged via the queue into master with commit c8d67a8 Oct 18, 2026
350 of 353 checks passed
@murphy-4o
murphy-4o deleted the unique-key/stack-test/read branch October 18, 2026 03:58
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 18, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

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

Baseline selected using StressHouse version hint 26.11.1.42530; measured build ancestry could not be verified. Measured differences are not attributed to this PR. ⚙️ Master level shift inside the baseline window (~2026-10-18 01:11:42): 2 queries have too few matching-era checks to re-baseline.

no significant changes detected. K_source=6 K_base=23 flagged=0/65

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 3cfaa934-7e9b-4970-93d6-c2bc1d2857ea
  • MIRAI run: 3f2a2af6-7be2-416b-a808-92b5475dde80
  • PR check IDs:
    • clickbench_352499_1792296091
    • clickbench_352505_1792296091
    • clickbench_352519_1792296091
    • tpch_adapted_1_official_352566_1792296091
    • tpch_adapted_1_official_352588_1792296091
    • tpch_adapted_1_official_352609_1792296092

alexey-milovidov added a commit that referenced this pull request Oct 18, 2026
…t-124131-parquet-prewhere-dictionary-replicated

Conflicts with the `Parquet` columns cache (#123008):
- `ReadManager::read`: keep `convertToFullColumnIfReplicated` with the new `getOrFormOutputColumn(row_group, ...)` signature.
- `Reader.cpp`: keep both sets of profile events.
- `05055` and `05339`: keep `AND id < 100000` from this PR and `use_columns_cache = 0` from master.
alexey-milovidov added a commit that referenced this pull request Oct 18, 2026
… written to the columns cache

After merging master, the column read by the last `PREWHERE` step could be both
decoded as a `ColumnReplicated` of dictionary values (`decode_dictionary_as_replicated`)
and written to the columns cache (#123008), which would put a `ColumnReplicated`
into the cache. Skip `decode_dictionary_as_replicated` for such a column, the same
way `string_value_filter` is skipped for it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov pushed a commit to scanhex12/ClickHouse that referenced this pull request Oct 20, 2026
Column comments of system tables are rendered verbatim into the
generated docs pages. The comment added in ClickHouse#123008 named the sidecar
files as 'for_<target>' and '<csn>_for_<target>', so MDX parsed
`<target>` as an unclosed JSX tag and `mint validate` dropped
parts.mdx and dropped_tables_parts.mdx from the build (robot docs
regeneration PR ClickHouse#126475, `Validate docs.json`).

Write the two patterns as inline code, as other system column
comments do for placeholders.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-unique-key Unique key in MergeTree: uniqueness enforced on insert through a key index (SST / dense index), d... and removed comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-unique-key Unique key in MergeTree: uniqueness enforced on insert through a key index (SST / dense index), d... pr-not-for-changelog This PR should not be mentioned in the changelog 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