Repository navigation
Conversation
makeTextIndexInputStream took a DataPartStoragePtr rather than the owning part, so it could not see the part's loaded checksums and resolved each index substream by probing the filesystem: existsFile(name), on a miss existsFile(sipHash128String(name)), then getFileSize on the survivor. A text index has whole-part granularity, so this ran once per substream per part per query, about 1200 stream constructions and 3600 metadata operations for one count() over a 400-part table. On Cloud keeper-backed metadata each probe is a Keeper round trip on a pipeline-execution thread, the chain ClickHouse#115110 had to wrap in a Keeper component. Add an overload taking const IMergeTreeDataPartInfoForReader &, the abstraction f018a33 migrated this reader layer onto and which every part-holding call site already has, and read the name and the size from its checksums. The branch is on the resolved name rather than on size == 0, because getFileSizeOrZero returns 0 both for "absent from checksums" and for a legitimately empty substream, and the latter is a real state (04654_text_index_merge_with_empty_part): a size-based branch would send exactly the emptied parts back to the filesystem. A stream with no checksums entry is still resolved and sized through the storage, and FILE_DOESNT_EXIST still fires after both attempts fail. The index merge keeps the storage overload, since a segment can be a temporary materialization storage with no part. Measured on a release pair, 8M rows in 400 parts, 16 alternating base/fix blocks: count() with one hasToken needle 12.0 -> 9.0 ms median (-25.0%, 16/16 rounds, system time -42.1%), 8 needles -18.2%, max(ts) with the same predicate and a non-indexed predicate flat, a 250k-row read through the reader path flat; read_rows, result_rows and FileOpen identical across arms. A throw-away build asserted that the name and size from checksums equal the storage's over the whole text-index and skip-index suite: 1580 observations, 0 mismatches, including hashed names, 0-byte substreams still listed in checksums, and packed part storage, whose size comes from the archive index rather than a stat. Tests: 05227_text_index_hashed_stream_name covers a hashed text index stream name and a text index on packed part storage, neither of which any test covered; tests/performance/text_index_count_stream_resolution.xml ships the count shape at 400 parts. Closes: ClickHouse#120672
Internal second-model review (click to expand)An independent cold review, then a second model re-reviewed the diff. Three findings, none needing a code
Residual I concede rather than close, your call. The perf fixture uses a short index name, so a 💡 Duplication. Kept deliberately: 💡 Test size. One case per carrier rather than repetition: full and packed part storage, the count, |
|
Workflow [PR], commit [34f93ff] Summary: ❌
AI ReviewSummaryThis PR switches text-index substream resolution in the Findings
Missing context / blind spots
Final VerdictStatus: Minimum required action: pin LLVM Coverage ReportMeasured on commit 34f93ff.
Changed lines: Changed C/C++ lines covered: 49/52 (94.23%) · Uncovered code |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
The test's two plan-shape probes assert that the text index count rewrite and the reader path are really taken, so that the value assertions below them are not vacuous. Parallel replicas disarm both: optimizeTrivialCountFromTextIndex returns early when Context::canUseParallelReplicasOnInitiator() holds, and with parallel_replicas_local_plan = 0 the read query's plan carries no local part read for EXPLAIN to inspect. The ParallelReplicas stateless flavour enables parallel replicas in the default profile, so `count path taken` read 0 there (deterministic, 3 of 3 reruns), and `read path taken` would have flipped on the runner's 50/50 parallel_replicas_local_plan randomization. Pinning the setting at session level, as many other stateless tests do, keeps every assertion running in that flavour rather than skipping the file with a no-parallel-replicas tag: with the pin the count path is exercised there too, and both mutation arms still redden the test. The plain-name control had the same shape of hole. It relied on its index name being short rather than on the setting, and the runner randomizes max_file_name_length with a 30% weight on 0, which hashes a name of any length when replace_long_file_name_to_hash is also randomized on. Roughly one run in seven compared hashed names against hashed names, so a hashing-specific failure would not have localised. Measured: with the flag off and the threshold at 0 the part keeps skp_idx_idx.*; with the flag on every index file is a sipHash128String name. Co-Authored-By: Claude Opus 5 <[email protected]>
CI finish ledger - 8b14a3dEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
The Session id: cron:our-pr-ci-monitor:20260919-020058 |
|
Pushed I pinned |
CI finish ledger - 8ca613cEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
The lane-conditional failure of Session id: cron:our-pr-ci-monitor:20260919-073140 |
Review asks on ClickHouse#120875: 200 parts instead of 400, and remove the `host = 'host7'` query. Both queries keep the effect. Halving the fixture also moves the `hasAnyTokens` query from 24 ms to 14 ms, i.e. under the harness's --fast-query-seconds boundary of 20 ms, so it is measured with the 30-run fast-query cap instead of 5-7 runs. Measured A/B on this branch's base and head, 3 replicates each, medians and the report's own stat_threshold: 200 parts hasToken 8.1 -> 6.2 ms -23% (30 runs, th 0.13-0.16) 200 parts hasAnyTokens 13.3 -> 11.7 ms -12% (30 runs, th 0.07-0.11) 400 parts hasAnyTokens 24.0 -> 21.1 ms -12% (5-7 runs, th 0.07-0.17) The 400-part `hasAnyTokens` row fell under its own noise threshold in 1 of 3 replicates; the 200-part one cleared it in 3 of 3.
…nchmark query_plan_optimize_count_from_text_index is ANDed with query_plan_direct_read_from_text_index in QueryPlanOptimizationSettings.cpp, so pinning only the child leaves the benchmark depending on the parent gate's default. With the parent off, the two count() queries fall back to Filter + ReadFromMergeTree, which never constructs the text index substream readers this PR changes: the test would keep running and quietly stop measuring the effect it exists for. Measured on this branch's release binary: the settings block as shipped plans ReadFromTextIndexCount, the same block with query_plan_direct_read_from_text_index = 0 plans Filter + ReadFromMergeTree, and the block with the pin plans exactly what the shipped one does on current defaults, so the pin changes no timing. The other text index performance tests, text_index_trivial_count.xml among them, already pin the parent gate.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units12 translation units recompiled, 88 s compile time in total, 12 of them have a recent master baseline. |
…-resolve-streams-from-checksums
CI finish ledger - 964f572Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
The tested tree predates that fix, measured rather than inferred: the failing job's confirmed
Session id: cron:our-pr-ci-monitor:20260919-203235 |
CI finish ledger - 3e48a10Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260920-110135 |
CI finish ledger - 13073eaEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260920-160237 |
Review ask on ClickHouse#120875: a .sql test does not earn its place next to the perf test here. Measured, its premise does not hold. The stateless runner randomizes replace_long_file_name_to_hash, max_file_name_length and min_bytes_for_full_part_storage (tests/clickhouse-test:2098-2100), and max_file_name_length = 0 hashes every substream of a text index whose name is short: an `INDEX idx` text index writes skp_idx_idx.idx, .dct.idx and .pst.idx under three sipHash128 names, and the hasToken answer through the index still matches use_skip_indexes = 0. 146 of the 151 stateless tests that query a text index leave all three settings to the runner, so hashed stream names and packed part storage are already exercised there, rather than being uncovered as the deleted file claimed. Index name length does not select a resolution path in this change either: getStreamNameOrHash probes the plain and the hashed name against the same checksums map, and a part emptied by a mutation never reaches makeTextIndexInputStream (measured with strace earlier in this PR). What the change adds is the checksums lookup itself, which every one of those 151 tests exercises, and sizes cannot disagree with the storage because MergeTreeDataPartChecksum::checkSize already verifies each entry against the call this replaces.
CI finish ledger - 34f93ffEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
Gates (a) to (d): 0 of 176 check runs queued or running, Session id: cron:our-pr-ci-monitor:20260921-140539 |
|
Fixing PR for the Root cause, measured on |
e033cea
Closes: #120672
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A query that reads a
textindex no longer asks the filesystem for each index substream's on-disk name and size once per part; both are now taken from the part's checksums, which already hold them. On an 8M-row table split into 400 parts,SELECT count() FROM logs WHERE hasToken(message, 'needle')drops from a median 12 ms to 9 ms, with 42% less system time.Description
Reported by @ snelheidai in #120672 with a candidate patch. The numbers here are my own re-measurement.
makeTextIndexInputStreamtakes aDataPartStoragePtrrather than the owning part, so it cannot see the loaded checksums and probes the filesystem:existsFile(name), on a missexistsFile(sipHash128String(name)), thengetFileSizeon the survivor. Atextindex has whole-part granularity, so this runs once per substream per part per query, about 1200 stream constructions for onecount()over 400 parts. The skip index construction sitemakeIndexReaderStreamalready reads both facts from checksums.This adds an overload taking
const IMergeTreeDataPartInfoForReader &, which every part-holding call site already has. A stream with no checksums entry is still resolved and sized through the storage, andFILE_DOESNT_EXISTstill fires when neither name resolves. The index merge keeps the storage overload, because a segment can be a temporary storage with no part. Sizes are equal by construction:MergeTreeDataPartChecksum::checkSizealready verifies every checksums entry againststorage.getFileSize, the call this replaces, so a part passing its consistency check cannot disagree, packed storage and encrypted disks included.Two deliberate differences from the patch as filed: the branch is on the resolved name, not on
size == 0, since a legitimately empty substream is 0 bytes and still listed in checksums (04654_text_index_merge_with_empty_part); and atextindex is never bundled intoskp_idx.packed(initSkipIndicesexcludesMergeTreeIndexText), so that identity argument does not apply. The stronger statement holds instead: for a materialized text index the checksums entry always exists, and the storage path is only a fallback.On Cloud keeper-backed metadata these probes are Keeper round trips, the chain #115110 wrapped in a Keeper component; its guards are untouched.
Residual: if checksums list a stream the disk lacks, the failure now surfaces at open rather than here. That needs an already-corrupt part, and the sibling accepts the same.
Validation: release A/B and the size-equality check
Release pair from this branch, Build IDs asserted per server. Fixture: 8M rows in 400 parts,
count asserted after a restart; caches off,
max_threads = 1, warm-ups discarded, timings fromsystem.query_log. 16 alternating base/fix blocks, 128 reps per arm: one block pair cannot clear its ownA/A null here (+-11..17% per block, -0.2% / +1.8% pooled).
count()+ 1hasTokencount()+hasAllTokens, 8 needlesmax(ts)+hasToken(control)System time on the first arm drops 42.1% (5.1 -> 2.9 ms, CI [0.478, 0.600]): the removed
stat/existsFilecalls.
read_rows,result_rowsandProfileEvents['FileOpen']are identical across arms, so the gain movesno rows and opens no files.
An understated size would truncate a read rather than raise an error, so a throw-away build asserted that the
name and size from checksums equal the storage's: 1580 observations, 0 mismatches over
the
text_index full_text skip_index skip_indicessuite and this fixture, covering hashednames, 0-byte substreams still in checksums, and packed storage, whose size comes from the archive index.
No stateless test is added: 142 of the 149 stateless tests that query a text index leave
replace_long_file_name_to_hash,max_file_name_lengthandmin_bytes_for_full_part_storageto the runner(
tests/clickhouse-test:2098-2100), andmax_file_name_length = 0hashes every substream of a short-named textindex, so both shapes are already exercised there.
Workflow [PR]
Sync PR [sync-upstream/pr/120875]
Version info
26.10.1.383-master(included in26.10and later)