Skip to content

Count the postings and positions read from a text index in the input bytes of automatic parallel replicas - #133839

Draft
nickitat wants to merge 14 commits into
autopr-count-ranges-capfrom
autopr-count-text-index-reads
Draft

nickitat wants to merge 14 commits into
autopr-count-ranges-capfrom
autopr-count-text-index-reads

Conversation

@nickitat

@nickitat nickitat commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Related: #127586
Related: #133777

Changelog category (leave one):

  • Improvement

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

The input bytes automatic parallel replicas measure now include the postings and positions a query reads from a text index, so a query answered mostly by the index is no longer under-priced.


Stacked on #133777 (the limit on the registered ranges), which is stacked on #127586 (the input bytes measured as the compressed blocks the readers load); the base of this PR is the branch of #133777, so the diff shows only the text index reads.

The postings and positions files of a text index are written uncompressed (MergeTreeIndexSubstream::isCompressed), so the compressed-block sink never saw them, and a direct read from the index was priced as almost nothing (on master too: there only the UInt8 virtual columns were priced). A MergeTreeReaderStream of uncompressed data now records the ranges of its file it consumed, closed by every seek and by recordBytesConsumed, and MergeTreeReaderTextIndex registers them per file in registerReadRanges, in the ReadRangesRegistry the other readers share, each range once. Like the other readers, it registers them by ReadRangesRegistry::Batch, and stops collecting them once the registry reached automatic_parallel_replicas_max_counted_ranges.

Not counted: the files the index analysis reads itself (the sparse index, the dictionary and the postings it loads), and the posting lists served from the text index postings cache.

05871_autopr_input_bytes_text_index_postings: a hasPhrase query over 1000000 rows reads 6562 bytes of positions. The statistics record 1949 input bytes without the change and 40826 with it.

🤖 Generated with Claude Code


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

nickitat and others added 2 commits November 23, 2026 17:27
…ut bytes

The postings and positions files of a text index are not compressed, so the compressed-block sink never sees them and an
index-dominated read was priced as almost nothing. A stream of uncompressed data now records the ranges of its file it
consumed, closed by every seek and by every flush, and the text index reader counts them per file with the compressed
blocks of the other readers, each range once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t bytes

`05871_autopr_input_bytes_text_index_postings`: a `hasPhrase` query over 1000000 rows reads 6562 bytes of positions. The
statistics recorded 1949 input bytes before the previous commit and 40826 after it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added the comp-text-index Full-text search: inverted/text index in MergeTree (tokenizers, posting lists, GIN-style index bu... label Nov 23, 2026
…dex-reads

# Conflicts:
#	src/Storages/MergeTree/MergeTreeReaderStream.cpp
#	src/Storages/MergeTree/MergeTreeReaderStream.h
#	src/Storages/MergeTree/MergeTreeReaderTextIndex.h
nickitat and others added 2 commits November 23, 2026 21:42
… the limit

The text index reader registers the ranges of its postings and positions files in one `ReadRangesRegistry::Batch`, like
the other readers, and once the registry stopped, detaches the sinks of its streams and drops what it collected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nickitat
nickitat changed the base branch from fix-stats-for-string-filters to autopr-count-ranges-cap November 23, 2026 21:50
@nickitat
nickitat added this pull request to stack #133889 November 23, 2026 21:51
@nickitat
nickitat removed this pull request from stack #133889 November 23, 2026 21:54
@nickitat
nickitat added this pull request to stack #133890 November 23, 2026 21:54
@nickitat nickitat added the ci-force-all Do not skip any jobs when running label Nov 23, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6f8e1b2]

Summary: ❌

job_name test_name status info comment
Integration tests (arm_binary, 4/5) FAIL
test_storage_rabbitmq/test.py::test_rabbitmq_handle_error_mode_stream FAIL cidb

AI Review

Summary

The PR includes text-index postings and positions in the input-byte statistics used by automatic parallel replicas. Reviewed head 6f8e1b2362dce2c9eb685ae3f348f93d394ed276. One previously reported Major remains: distinct index and column files can share a statistics key, causing undercounting. No new inline findings.

Findings

⚠️ Majors

  • src/Storages/MergeTree/MergeTreeReaderTextIndex.cpp:704 — Distinct files must have distinct registry identities. The generated keys <part>/skp_idx_idx.postings and <part>/skp_idx_idx.positions collide with the keys used by MergeTreeReaderWide for the typed paths of a column declared as skp_idx_idx JSON(postings UInt64, positions UInt64). A query reading those fields and text index idx merges byte ranges from unrelated files. For example, [0, 1000) from a column and [100, 200) from the index count as 1000 bytes instead of 1100, underestimating the input used to choose parallel replicas. Give index files a namespace disjoint from column-stream keys, and add a focused regression reading both. Existing unresolved thread; no author replies.
Tests
  • ⚠️ The new phrase-search regression passes in the current head's Fast test report, but does not exercise overlapping index/column identities. Add the collision case described above and assert that both files contribute independently.
Final Verdict

Status: ⚠️ Request changes

Separate index-file identities from column-stream keys and cover the collision with a regression test.

LLVM Coverage Report

Measured on commit 6f8e1b2.

Metric Baseline Current Δ
Lines 91.90% 91.90% +0.00%
Functions 92.20% 92.20% +0.00%
Branches 81.60% 81.50% -0.10%

Changed lines: Changed C/C++ lines covered: 168/190 (88.42%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Nov 24, 2026
clickhouse-gh[bot]
clickhouse-gh Bot previously approved these changes Nov 24, 2026
…wStatisticsInputNanoseconds`

Like the other readers, after the timer moved out of `ReadRangesRegistry`. The time of the
fallback reader is counted by its own `registerReadRanges`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
clickhouse-gh[bot]
clickhouse-gh Bot previously approved these changes Nov 24, 2026
return;
if (!file.read_ranges)
file.read_ranges = &read_ranges_registry->getReadRanges(fmt::format(
"{}/{}.{}", data_part_info_for_read->getDataPartStorage()->getFullPath(), index_read_task.index.index->getFileName(), kind));

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.

[Major] Keep text-index identities separate from column-stream keys

The registry is shared with MergeTreeReaderWide, which uses <part>/<stream_name> without the .bin extension as its key. In a wide part containing skp_idx_idx JSON(postings UInt64, positions UInt64) and a text index named idx, the JSON substreams are named skp_idx_idx.postings and skp_idx_idx.positions (see ISerialization::getFileNameForStream). These are exactly the keys constructed here for the separate .pst.idx and .pos.idx index files.

A query that reads those JSON fields while filtering through the text index therefore unions offsets from unrelated files. For example, data ranges [0, 1000) and index ranges [100, 200) are counted as 1000 bytes instead of 1100, underestimating the input used to choose parallel replicas. Please give index keys a namespace that cannot overlap column-stream keys, or use complete file identities consistently across readers, and add a focused regression for the collision.

@clickhouse-gh
clickhouse-gh Bot dismissed stale reviews from themself November 24, 2026 17:48

AI review of a later commit does not approve the PR, see the AI Review comment.

@clickhouse-gh

clickhouse-gh Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 6f8e1b236 with master 2b066904b (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

121 object files changed (+63.13 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/MergeTree/MergeTreeReaderStream.cpp.o 175.88 KiB 232.59 KiB +56.71 KiB (+32.25%)
src/CMakeFiles/dbms.dir/Storages/MergeTree/MergeTreeReadTask.cpp.o 296.85 KiB 257.62 KiB -39.23 KiB (-13.21%)
src/CMakeFiles/dbms.dir/Storages/MergeTree/MergeTreeReaderWide.cpp.o 464.24 KiB 486.77 KiB +22.53 KiB (+4.85%)

716 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

732 translation units recompiled, 5046 s compile time in total, 732 of them have a recent master baseline.

Job report

The plan-based implementation cannot ship a read that uses direct read from a text index, so in the
job with `parallel_replicas_plan_based = 1` automatic parallel replicas skipped the query ("The plan built
with parallel replicas contains no read from the other replicas") and collected no statistics. The
same pin as in `02346_text_index_parallel_replicas`.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=133839&sha=8e1a7e8f7db9f63ef4f978287e88cd3474687071&name_0=PR&name_1=Stateless%20tests%20(arm_binary%2C%20ParallelReplicas%2C%20plan-based%2C%20s3%20storage%2C%20parallel)
Related: #133839
Related: #116360

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch has not been deployed

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

Labels

ci-force-all Do not skip any jobs when running comp-text-index Full-text search: inverted/text index in MergeTree (tokenizers, posting lists, GIN-style index bu... pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant