Skip to content

Fix "Too many marks" for text index on an empty merged part - #106867

Merged
CurtizJ merged 2 commits into
ClickHouse:masterfrom
azat:fix-text-index-lwd-empty-part-marks
Jun 23, 2026
Merged

CurtizJ merged 2 commits into
ClickHouse:masterfrom
azat:fix-text-index-lwd-empty-part-marks

Conversation

@azat

@azat azat commented Jun 9, 2026 •

Copy link
Copy Markdown
Member

When a merge produces a part with zero rows (for example when a lightweight delete removes everything), MergeTextIndexesTask::executeStep still wrote a single mark into the text index marks file "for compatibility with other skip indexes". But an empty part reports zero marks, so getMarksCountForSkipIndex returns 0, and reading the marks back (e.g. while prewarming the mark cache on attach with prewarm_mark_cache) failed with Too many marks in file ... skp_idx_idx.cmrk2.

Regular skip indexes gate every mark/granule write on actually having data (calculateAndSerializeSkipIndices only writes inside the per-granule loop, fillSkipIndicesChecksums only serializes a granule when the aggregator is non-empty), so they naturally emit zero marks for an empty part. Make the text index merge task follow the same invariant: skip the mark when the resulting part has no marks, keeping the marks file consistent with getMarksCountForSkipIndex.

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):

Fix "Too many marks" for text index on an empty merged part

CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106808&sha=baf623fcb653414335f6588588111f272d4776ca&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29

Version info

  • Merged into: 26.6.1.1140
  • Backported to: 26.5.4.16, 26.4.5.71, 26.3.16.11

@clickhouse-gh

clickhouse-gh Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7aebe09]

Summary: ✅


AI Review

Summary

This PR fixes text-index mark serialization for merged or mutated parts that end with zero rows. The current code uses the final merged row count (rows_written) instead of the pre-finalization index_granularity, and the added stateless test exercises the attach-time prewarm_mark_cache read that previously raised Too many marks; I found no correctness findings that need inline comments.

Missing context / blind spots
  • ⚠️ CI was still pending for Fast test, Bugfix validation (functional tests), and Build (arm_tidy) when reviewed; completed CI would close execution evidence. No local build* directory was available to run the new stateless test here.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 9, 2026
@CurtizJ CurtizJ self-assigned this Jun 9, 2026
azat and others added 2 commits June 16, 2026 17:21
When a merge produces a part with zero rows (for example when a lightweight
delete removes everything), `MergeTextIndexesTask::executeStep` still wrote a
single mark into the text index marks file "for compatibility with other skip
indexes". But an empty part reports zero marks, so
`getMarksCountForSkipIndex` returns 0, and reading the marks back (e.g. while
prewarming the mark cache on attach with `prewarm_mark_cache`) failed with
`Too many marks in file ... skp_idx_idx.cmrk2`.

Regular skip indexes gate every mark/granule write on actually having data
(`calculateAndSerializeSkipIndices` only writes inside the per-granule loop,
`fillSkipIndicesChecksums` only serializes a granule when the aggregator is
non-empty), so they naturally emit zero marks for an empty part. Make the text
index merge task follow the same invariant: skip the mark when the resulting
part has no marks, keeping the marks file consistent with
`getMarksCountForSkipIndex`.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The previous commit gated the text index mark on
`new_data_part->index_granularity->getMarksCountWithoutFinal()`, but the
`MergeTextIndexStage` runs before `MergeProjectionsStage` finalizes the part,
so at that point `index_granularity` is still empty and the check returned
zero for every part - the compatibility mark was skipped always, not only for
empty parts.

Pass the number of merged rows into `MergeTextIndexesTask` instead
(`rows_written` from the merge / mutation context, which is final by this
stage) and write the mark only when the resulting part is non-empty.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@azat
azat force-pushed the fix-text-index-lwd-empty-part-marks branch from b494b95 to 7aebe09 Compare June 16, 2026 15:36
@clickhouse-gh

clickhouse-gh Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.20% 85.20% +0.00%
Functions 92.30% 92.30% +0.00%
Branches 77.40% 77.40% +0.00%

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

Full report · Diff report

@azat
azat requested a review from CurtizJ June 19, 2026 12:43
@CurtizJ
CurtizJ added this pull request to the merge queue Jun 23, 2026
Merged via the queue into ClickHouse:master with commit 53a62d6 Jun 23, 2026
166 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 23, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment.

TL;DR

Fix "Too many marks" for text index on an empty merged part

ClickGap verified: reproduced it with the script below on 26.5; tested 6 version(s) — 4 affected, 2 clean (see Affects); bisected to a candidate range — a single introducing PR could not be pinned (see Bisect).

Reproduction

-- Run on a server (clickhouse-client). Requires the text index feature flag.
SET enable_full_text_index = 1;   -- older releases: SET allow_experimental_full_text_index = 1;
SET mutations_sync = 2;

DROP TABLE IF EXISTS t_text_idx_empty;
CREATE TABLE t_text_idx_empty
(
    s FixedString(37),
    INDEX idx s TYPE text(tokenizer = array()) GRANULARITY 100000000
)
ENGINE = MergeTree
ORDER BY tuple()
SETTINGS prewarm_mark_cache = true, min_bytes_for_wide_part = 0;

INSERT INTO t_text_idx_empty SELECT toFixedString(toString(number), 37) FROM numbers(5);
INSERT INTO t_text_idx_empty SELECT toFixedString(toString(number + 5), 37) FROM numbers(5);
INSERT INTO t_text_idx_empty SELECT toFixedString(toString(number + 10), 37) FROM numbers(5);

-- Lightweight-delete every row, then merge: the merge produces a zero-row part.
DELETE FROM t_text_idx_empty WHERE 1;
OPTIMIZE TABLE t_text_idx_empty FINAL;

-- Before the fix this throws:
--   Code: 33. DB::Exception: Too many marks in file .../skp_idx_idx.cmrk2,
--   marks expected 0 (bytes size 0). (CANNOT_READ_ALL_DATA)
SYSTEM PREWARM MARK CACHE t_text_idx_empty;
SELECT count() FROM t_text_idx_empty;

Bisect

  • The bisect boundary was rejected — PR Sync private #97830 only modifies metrics, settings history, and MergeTree settings configuration files, with no changes to text index or mark-handling logic that could cause the 'Too many marks' bug. — a coincidental boundary, not the cause; no introducing PR pinned.
  • The source-build bisect converged to Sync private #97830, but it is not the introducer (see above) — not attributing it.

Affects

  • Verified against master build 7ef85344d14a (aarch64)
  • ✓ Fix is on master — this PR's change fixes the bug on master. Branches below still have the bug and need the backport.
  • Reproduces on: 26.5, 26.4, 26.3, 26.2
  • Does NOT reproduce on: master, 26.1
  • Backport needed: 26.5, 26.4, 26.3, 26.2

Suggested next step

The bisect boundary above narrows the search in comp-text-index — treat the candidate range as the starting point; the single introducing PR is unconfirmed.

Component: comp-text-index
Severity: P2

cc fix PR author: @azat
cc fix PR reviewer: @CurtizJ


ClickGap · Finding: phase_d_pr106867

Triage metadata

  • Primary component: comp-text-index
  • Secondary components: comp-testing
  • Component owners (comp-text-index): @CurtizJ @ahmadov

@clickgapai

Copy link
Copy Markdown
Contributor

Hi — this looks like a backport candidate for 26.1, 26.2, 26.3, 26.4, 26.5. I ran this PR's own regression test against each branch's binary and the bug reproduces there (the fix isn't present yet).

@azat
azat deleted the fix-text-index-lwd-empty-part-marks branch June 23, 2026 05:34
@azat azat added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Jun 23, 2026
robot-clickhouse added a commit that referenced this pull request Jun 23, 2026
Cherry pick #106867 to 26.3: Fix "Too many marks" for text index on an empty merged part
robot-clickhouse added a commit that referenced this pull request Jun 23, 2026
robot-clickhouse added a commit that referenced this pull request Jun 23, 2026
Cherry pick #106867 to 26.4: Fix "Too many marks" for text index on an empty merged part
robot-clickhouse added a commit that referenced this pull request Jun 23, 2026
robot-clickhouse added a commit that referenced this pull request Jun 23, 2026
Cherry pick #106867 to 26.5: Fix "Too many marks" for text index on an empty merged part
robot-clickhouse added a commit that referenced this pull request Jun 23, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jun 23, 2026
azat added a commit that referenced this pull request Jun 26, 2026
Backport #106867 to 26.5: Fix "Too many marks" for text index on an empty merged part
azat added a commit that referenced this pull request Jun 26, 2026
Backport #106867 to 26.4: Fix "Too many marks" for text index on an empty merged part
azat added a commit that referenced this pull request Jun 26, 2026
Backport #106867 to 26.3: Fix "Too many marks" for text index on an empty merged part
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jun 26, 2026
@azat azat removed the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jun 26, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jun 26, 2026
@azat azat removed the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jun 29, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jun 29, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…ty-part-marks

Fix "Too many marks" for text index on an empty merged part
bytehalo-infra added a commit to sentioxyz/ClickHouse that referenced this pull request Sep 25, 2026
STOR: text index on an empty merged part -> exc Too many marks.
Effect in the production build a394e92: wrong/failing (the upstream test fails on it and passes on official 26.8.8.8; evidence/fix_ci_20260925/upstream_repro/residual/106867.PROD263.txt).
Upstream patch unchanged, with its test(s): 04326_text_index_empty_part_marks_prewarm.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 Pull request should be backported intentionally. Use this label with great care! 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants