Skip to content

Make test 00314_sample_factor_virtual_column five times faster under TSan - #124368

Merged
murphy-4o merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-00314-sample-factor-tsan-slow
Oct 7, 2026
Merged

murphy-4o merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-00314-sample-factor-tsan-slow

Conversation

@groeneai

@groeneai groeneai commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

...

Description

Related: #111248

00314_sample_factor_virtual_column failed with Test runs too long (> 180s) (181.76 s) in Stateless tests (amd_tsan, s3 storage, targeted) on #111248. It is slow on master too: over 30 days it took up to 296 s (p50 66 s) in amd_tsan, s3 storage, parallel.

The tables had an explicit index_granularity of 10, and the INSERTs set min_insert_block_size_rows = 0, so every random max_block_size block (down to 8000 rows) became its own compact part with one compressed block per column per 10-row granule: about 600k compressed blocks written and merged, and 600k marks loaded by the SELECTs. The random server codec ZSTD makes each block more expensive under TSan (#122854 is the product-side change for that).

The test now uses granularity 8192 and clamps max_block_size to at least 65409. The data, both queries and the reference are unchanged. sum(_sample_factor) does not depend on the layout (the relative sample size comes from the exact row count, the sampling filter is exact): I measured the same 2997580 over 199910 rows for granularity 10 and 8192 with blocks of 8188, 65409 and 100000 rows. Each table still has at least 10 parts, and the primary key still prunes the sampled range.

With the master TSan binary, 18 concurrent runs on 32 CPUs (the flaky check shape), p50 went from 51 s to 8.3 s with ZSTD(1), 32 s to 7.1 s with LZ4, and 51 s to 9.6 s on S3 (MinIO). 50/50 randomized runs pass on TSan and debug. The clamp is checked in system.query_log: no max_block_size below 65409, while a corrupted clamp line lets lower values through.


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

Version info

  • Merged into: 26.10.1.1715-master (included in 26.10 and later)

The test created its tables with an explicit index_granularity of 10 and
inserted 3M rows with min_insert_block_size_rows = 0, so every random
max_block_size block (down to 8000 rows) became its own compact part with
one compressed block per column per 10-row granule: ~600k compressed blocks
written, decoded and re-encoded again by the background merges, and ~600k
marks loaded by the SELECTs. Under TSan, with the random ZSTD server codec
(a fresh context per block), a run took up to 296 s in the s3 parallel lane
and failed the 180 s limit of the targeted check on PR ClickHouse#111248.

Use the default granularity 8192 and clamp max_block_size to at least 65409.
The asserted sum(_sample_factor) does not depend on granularity or part
layout (exact row count for the relative sample size, exact intHash64
filter): measured identical (2997580 over 199910 rows) for granularity 10
and 8192 and block sizes 8188, 65409 and 100000. TSan, 18 concurrent runs
on 32 CPUs: p50 51 s -> 8.3 s (ZSTD(1)), 32 s -> 7.1 s (LZ4), 51 s -> 9.6 s
(S3 on MinIO).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Oct 7, 2026
@groeneai

groeneai commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 1 finding).

# Sev Finding Verdict Evidence / action
1 ⚠️ The .reference does not detect the granularity or the max_block_size floor being reverted DISAGREE Test runtime is guarded by the runner's per-run 180 s check in the flaky check and targeted jobs, which run every changed test (tests/clickhouse-test:3973-3989); #124000 sped up 01035_avg the same way. A mark-count assertion is not deterministic after background merges (128 to 276 marks for the new layout) and would test storage internals, not _sample_factor. The clamp is checked in system.query_log with a negative control.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-slot-8:20261007-054200

@groeneai

groeneai commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Every run of the old file loads ~572k marks and decodes ~32k compressed blocks; with the master TSan binary, 18 concurrent runs on 32 CPUs, the old file takes 51 s p50 (max 64-70 s) against 8.3-9.6 s for the new one.
b Root cause explained? Yes. Explicit index_granularity 10 plus min_insert_block_size_rows = 0 and a small random max_block_size give hundreds of compact parts with one compressed block per column per 10-row granule (~600k blocks and marks per run); TSan and the random ZSTD server codec make each block expensive.
c Fix matches root cause? Yes. Granularity 8192 and a per-setting clamp on max_block_size remove the per-granule multiplier; no long/no-tsan tag, no wider bound, no smaller data.
d Test intent preserved / new tests added? Yes. Same rows, SAMPLE 100000, queries, 0.001 bound and reference; sum(_sample_factor) measured identical (2997580 over 199910 rows) for granularity 10 and 8192 and blocks of 8188, 65409, 100000 rows; tables still multi-part and PK-pruned.
e Both directions demonstrated? Yes. Same rig, old vs new file: p50 51 s -> 8.3 s (ZSTD(1)), 32 s -> 7.1 s (LZ4), 51 s -> 9.6 s (S3 on MinIO); 0 failures.
f Fix is general across code paths? N/A (test-only change).
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test-only); the clamp keeps the random range 65409..100000, validated in system.query_log with a negative control.
h Backward compatible? (maintainer-approved exception only) N/A (no setting, format or server change).
i Invariants and contracts preserved? Yes. The asserted invariant holds identically for both the Merge table and merge(); no other randomized setting is pinned.

Session id: cron:clickhouse-impl-slot-4:20261007-051300

@clickhouse-gh

clickhouse-gh Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a92d375]

Summary: ✅


AI Review

Summary

This PR narrows the randomized layout of tests/queries/0_stateless/00314_sample_factor_virtual_column.sql so the test no longer explodes under slow builds: it restores index_granularity to 8192 and clamps randomized max_block_size back to the default floor while keeping the sampled queries and oracle unchanged. I checked the runner semantics and the MergeTree old-syntax path, and I did not find a correctness, coverage, or metadata problem in the current patch.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Oct 7, 2026
@murphy-4o
murphy-4o enabled auto-merge October 7, 2026 07:25
@murphy-4o
murphy-4o added this pull request to the merge queue Oct 7, 2026
Merged via the queue into ClickHouse:master with commit 54ff83b Oct 7, 2026
149 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 7, 2026
@clickhouse-gh clickhouse-gh Bot added comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. and removed comp-testing Test content only (no production code). labels Nov 22, 2026
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-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-ci 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