Skip to content

Bound Compact reads by the requested columns - #119763

Open
rorylshanks wants to merge 17 commits into
ClickHouse:masterfrom
rorylshanks:perf/compact-read-column-boundary
Open

rorylshanks wants to merge 17 commits into
ClickHouse:masterfrom
rorylshanks:perf/compact-read-column-boundary

Conversation

@rorylshanks

@rorylshanks rorylshanks commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

The Compact reader sets its read limit from the last stored column. Selective reads can leave unread response data and force a connection reset. Use the last requested physical column instead, including all its substreams and complete shared compressed blocks. Buffer-size estimation skips this scan to avoid quadratic work.

For a subcolumn request, the limit remains the end of its physical column. This change does not claim to eliminate connection resets for selective JSON or Dynamic paths. Their exact stream sets depend on per-granule deserialization prefixes, which are unavailable when the stream is initialized. The JSON tests check read correctness, not zero connection resets for subcolumns.

Benchmark

The table had 100,000 packed Compact parts. The query read sum(seq) with a partition-range filter. An S3-compatible proxy served local NVMe data. Both 26.8-based Release builds disabled LTO and had limits of 4 CPUs and 16 GiB. The shared host used a Ryzen 9 5950X.

Metadata and statistics refresh, filesystem cache, and uncompressed cache were disabled. Values are medians of three queries with cached marks.

Measurement Before After
1,000 selected parts: wall time 0.386 s 0.342 s
10,000 selected parts: wall time 59.59 s 2.19 s
10,000 selected parts: CPU 20.63 CPU-s 5.57 CPU-s
10,000 selected parts: connection resets 20,092 0

GET count stayed at 20,000 and peak query memory at 32.33 MiB for the larger case. Its baseline exhausted ephemeral ports; connection failures and retry waits amplified the wall-time difference.

The existing benchmark above reads the top-level seq column. The current JSON boundary test uses 16 paths and retains all 16 layout combinations; all 80 output lines match its reference on the CI debug binary.

Changelog category (leave one):

  • Performance Improvement

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

Reduce unnecessary connection resets when reading selected physical columns from Compact parts on object storage.

Closes: #122103


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

@clickhouse-gh clickhouse-gh Bot added the comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. label Sep 13, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Sep 13, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f0fb8d5]

Summary: ❌

job_name test_name status info comment
Integration tests (arm_binary, 2/4) FAIL
test_read_temporary_tables_on_failure/test.py::test_different_versions FAIL cidb
Performance Comparison (arm_release, master_head, iceberg_local, 1/3) FAIL Performance dashboard
Insert historical data FAIL
Check Results FAIL
Performance Comparison (arm_release, master_head, iceberg_local, 2/3) FAIL Performance dashboard
Insert historical data FAIL
Check Results FAIL
Performance Comparison (arm_release, master_head, iceberg_local, 3/3) FAIL Performance dashboard
Insert historical data FAIL
Check Results FAIL
Performance Comparison (arm_release, master_head, iceberg_s3, 1/3) FAIL Performance dashboard
Insert historical data FAIL
Check Results FAIL
Performance Comparison (arm_release, master_head, iceberg_s3, 2/3) FAIL Performance dashboard
Insert historical data FAIL
Check Results FAIL
Performance Comparison (arm_release, master_head, iceberg_s3, 3/3) FAIL Performance dashboard
Insert historical data FAIL
Check Results FAIL

AI Review

Summary

PR #119763 bounds Compact reads by the last requested physical column while preserving complete compressed blocks. The current code addresses the earlier shared-block boundary finding, and the revised fixture now exceeds the actual compression buffer and asserts its layout. The supplied benchmark and completed performance results support the optimization. No actionable findings remain.

Missing context / blind spots
  • ⚠️ CI for head f0fb8d5e2351101d6c995beb253db17e88a81cca is still running. A passing stateless run must confirm the revised split-block fixture. Tests were not run locally because this checkout has no clickhouse binary or configured build.
Final Verdict

Status: ✅ Approve, subject to the normal current-head CI checks.

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Sep 13, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing f0fb8d5e2 with master f1e98b9e5 (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.

Compile time of recompiled translation units

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

Job report

The 16-case template repeatedly times out in flaky checks. One failed debug
run spent 189 seconds in queries, including 131 seconds reading and 51
seconds inserting; dropping tables took only 4 seconds. Reading the 300
dynamic paths without substream marks accounts for most of the read cost.

Use 16 paths with dynamic-path limits of 2 and 32. Keep all 16 combinations
of packed storage, substream marks, per-column compression and dynamic vs
shared JSON paths. Preserve missing-path, `PREWHERE`, full-document and
following-column checks, updating their expected sums.

All 80 output lines match the reference using the exact CI debug binary.
Local time falls from 2.884 to 2.497 seconds; the CI timeout itself remains
subject to verification under the flaky-check workload.

ClickHouse#119763
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119763&sha=089ef83b07d2a142548d4d23b53e6e3a83190e45&name_0=PR
https://github.com/ClickHouse/ClickHouse/pulls/rorylshanks
@clickhouse-gh

clickhouse-gh Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

⚠️ AI verdict: not_sure — inconclusive across 31 queries analysed

Baseline selected using StressHouse version hint 26.9.1.38556; measured build ancestry could not be verified. Measured differences are not attributed to this PR. ⚙️ Latest matching master measurement is 11.1667 days before this PR's first measurement; an intervening master or environment epoch may explain directional differences.

PR verdict: not_sure. 5 measured difference(s) not attributable to this PR. clickbench Q17: The measured difference cannot be attributed to this PR from the available source evidence. clickbench Q33: The measured difference cannot be attributed to this PR from the available source evidence. clickbench Q34: The measured difference cannot be attributed to this PR from the available source evidence. tpch_adapted_1_official Q7: The measured difference cannot be attributed to this PR from the available source evidence. tpch_adapted_1_official Q9: The measured difference cannot be attributed to this PR from the available source evidence.

clickbench

⚠️ 4 inconclusive

Flagged queries (4 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 17 not_sure 239 182 -23.8% <0.0001 The measured difference cannot be attributed to this PR from the available source evidence.
⚠️ 28 not_sure 1047 1102 +5.3% <0.0001
⚠️ 33 not_sure 1142 1050 -8.1% <0.0001 The measured difference cannot be attributed to this PR from the available source evidence.
⚠️ 34 not_sure 1139 1038 -8.8% <0.0001 The measured difference cannot be attributed to this PR from the available source evidence.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

⚠️ 2 inconclusive

Flagged queries (2 of 22)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 7 not_sure 81 60 -25.9% <0.0001 The measured difference cannot be attributed to this PR from the available source evidence.
⚠️ 9 not_sure 98 78 -20.4% <0.0001 The measured difference cannot be attributed to this PR from the available source evidence.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

Debug info
  • StressHouse run: 72561c3c-ad9c-42d4-9422-5d9282022f8f
  • MIRAI run: a0a8a1c3-1913-4d33-a330-3b547b696606
  • PR check IDs:
    • clickbench_604784_1792379250
    • clickbench_604799_1792379250
    • clickbench_604807_1792379249
    • tpch_adapted_1_official_604848_1792379249
    • tpch_adapted_1_official_604870_1792379250
    • tpch_adapted_1_official_604890_1792379250

The limit intentionally includes every substream of the requested physical
column. Exact `JSON` and `Dynamic` path streams require per-granule prefixes
that are not available at stream initialization. Document this scope instead
of claiming the top-level-column optimization eliminates subcolumn resets.
No read behavior changes.

ClickHouse#119763 (comment)
@clickhouse-gh clickhouse-gh Bot added the external Author is not a member of the ClickHouse organization label Sep 14, 2026
@qoega

qoega commented Sep 15, 2026

Copy link
Copy Markdown
Member

That looks great! @rienath maybe you can review this PR? It is completely green

@rienath rienath 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.

We'd need an .xml performance benchmark. I measured locally and saw no speed-up. On parts written before 26.4 (no compress_per_column_in_compact_parts, all columns of a granule share one compressed block) it is a 2x slow-down. The bool threading is not a maintainable design.

The idea behind is good

@rienath rienath self-assigned this Sep 15, 2026
Remember the last right mark in `MergeTreeReaderStream::adjustRightMark`.
Marks and column bounds are immutable for a stream, so repeated reads of
the same range need not scan the shared compressed-block boundary again.
Keep the existing offset-extension and S3 byte-boundary behavior.

Add a 28-query XML benchmark covering shared and per-column compression,
first/middle/last/all-column projections, filtered and full scans, and
packed parts. Run the same XML with local or S3-backed default storage.

Validation: matched local builds, 112 exact-result checks, and five
functional tests on both binaries. CPU-affinity-controlled repeats found
no reproducible old-layout slowdown above 5%; selective S3 gains remained
24-27%. These are local results, not CI confirmation.

Related: ClickHouse#119763
Remove the `include_shared_block` mode from `getRightOffsetOneColumn`.
Keep actual read limits and buffer-size estimates as separate operations,
sharing the included-mark calculation and stripe traversal. Preserve
shared-block completion, multi-granule stripes, and `last_right_mark` reuse.

Related: ClickHouse#119763
Related: ClickHouse#119763 (review)
Performance CI currently runs `compact_read_column_boundary` on local storage, so it cannot measure the reduced remote range over-read and connection reuse this change targets.

Start the existing SeaweedFS fixture for opted-in performance tests and put this benchmark on a dynamic `S3` disk. Install `lsof`, which the fixture uses for its readiness check.

ClickHouse#119763
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Sep 16, 2026
@rorylshanks

rorylshanks commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Hey @rienath Thanks for reviewing! I added a perf test but as this specifically targets S3 disks there was not a repeatable performance improvement with the existing runner. I added seaweedfs to the perf runner but not sure if that's the correct approach to run performance tests with S3-backed disks. What do you think?

Alternatively I could create new shards for the perf test that are specifically for S3 performance tests?

@qoega

qoega commented Sep 16, 2026

Copy link
Copy Markdown
Member

You can check how we run local minio in functional tests. AFAIR we have it there and not only in integration tests.

@rorylshanks

rorylshanks commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Heya @qoega, I checked and re-used the same seaweedfs image and scripts that is used elsewhere in tests. Unfortunately it was not configured in the performance test image though. I added it to the perf test image, but as its a CI change the bot removed the approval to run the tests.

Comment thread ci/jobs/performance_tests.py Resolved
# Conflicts:
#	ci/jobs/performance_tests.py
Profile collection does not start object storage, so benchmarks marked `requires_s3` time out in the PGO and BOLT passes. Reuse the existing XML classification and skip them explicitly.

Related: ClickHouse#119763 (comment)
@rorylshanks

Copy link
Copy Markdown
Contributor Author

🕵 @rienath, current master is merged and the remaining requires_s3 profile-collector concern is addressed in 07d0a9d. The unresolved thread is now resolved. The new workflow needs maintainer approval because this fork PR changes CI files: https://github.com/ClickHouse/ClickHouse/actions/runs/35610910202. Please approve the run and re-review when available.

rorylshanks and others added 2 commits September 26, 2026 10:18
…-column-boundary

# Conflicts:
#	ci/jobs/performance_tests.py
…ed blocks

In parts written with `compress_per_column_in_compact_parts` = false, the
columns of a granule share compressed blocks, so a column boundary is not a
compressed-block boundary and a tighter read limit cannot help. Instead of
scanning forward through every column sharing the block on each
`getRightOffsetOneColumn` call, detect the shared block from the next
column's mark and bound the read by the last column, which is the behavior
for reading all columns. This keeps the cost for such parts the same as
before the change.

Also correct the benchmark comment: the shared-block layout comes from
`compress_per_column_in_compact_parts` = 0, not from parts written before
26.4 (they flushed a compressed block after every column).

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

clickhouse-gh Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Dear @rienath, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

rorylshanks and others added 2 commits October 18, 2026 15:47
…-column-boundary

# Conflicts:
#	ci/jobs/collect_clickhouse_profiles.py
#	ci/jobs/performance_tests.py
With `compress_per_column_in_compact_parts` = false a granule can still span
several compressed blocks, split at `max_compress_block_size`. Instead of
reading up to the end of the granule, stop at the first later column mark
that starts a later compressed block. Cover granules split into small blocks
in `04967_compact_read_column_boundary`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rorylshanks and others added 2 commits November 4, 2026 00:11
…locks

`MergeTreeDataPartWriterCompact` compresses through a `CompressedWriteBuffer` with
the default 1 MiB buffer; `max_compress_block_size` only sizes the outer file buffer.
The previous variant of `04967_compact_read_column_boundary` with
`max_compress_block_size = 64` therefore never split a granule, and the search for a
later column that starts a later block was not exercised.

Replace it with a table whose granules overflow the compression buffer: `a` and `b`
share the first block and `d` starts in a later one. The layout is asserted with
`mergeTreeIndex` before the selective reads.

Related: ClickHouse#119763 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01E5v7QTSR65LdYnQEv9HJVu
@clickhouse-gh clickhouse-gh Bot added comp-part-formats Formats of MergeTree data parts in the public repository, that is how a part is laid out on disk ... and removed comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. labels Nov 19, 2026

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

can be tested Allows running workflows for external contributors comp-part-formats Formats of MergeTree data parts in the public repository, that is how a part is laid out on disk ... external Author is not a member of the ClickHouse organization manual approve Manual approve required to run CI pr-performance Pull request with some performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compact-part column-subset reads over object storage close the HTTP connection after every request

4 participants