Skip to content

Add regression test for reading Array .size0 subcolumn across granules - #109090

Merged
alexey-milovidov merged 5 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-array-offsets-subcolumn-shared-buffer-merge
Jul 30, 2026
Merged

alexey-milovidov merged 5 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-array-offsets-subcolumn-shared-buffer-merge

Conversation

@groeneai

@groeneai groeneai commented Jul 1, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #107457
Related: #106370

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

Description

Regression test only, no code change. Covers reading an Array .size0 subcolumn together with the full Array column across many granules of a compact part.

MergeTreeReaderCompact::readData has two subcolumn branches. With per-substream marks it reads the subcolumn through its serialization; without them it reads the full column and extracts the subcolumn in memory. Only the second branch appends into a possibly shared column, and it is reachable only for parts written with write_marks_for_substreams_in_compact_parts = 0. That setting defaults to 1, so the first version of this test only exercised the first branch. The test now pins the setting on one table and pins 1 on a second table, so both branches are covered.

The pins are asserted through the effective layout rather than the recorded DDL text: mergeTreeIndex(..., with_marks = true) must report no mark for the a.size0 substream on the first table and a mark on the second, and both parts must be Compact with several 32-row granules. index_granularity_bytes is pinned too, because the runner randomizes it down to 1 KiB, which makes granule sizes vary; it is pinned to a large value rather than 0 because 0 turns off adaptive granularity and a non-adaptive part must be Wide. An explicit per-DDL SETTINGS value wins over the runner's randomization injection (ClientBase::addMergeTreeSettings only adds a randomized value when the DDL does not already set it), so no blanket no-random-merge-tree-settings tag is needed; 50 randomized runs pass.

Scope note: this test does not fail on a revert of the IColumn::mutate change in #107457. In the fallback branch the destination column is uniquely owned on every read (measured: 3750 entries, use_count 1 in all), and IColumn::mutate differs from assumeMutable only above use_count 1. The value here is branch coverage, not a fail-without-fix guard.

Version info

  • Merged into: 26.8.1.405 (included in 26.8 and later)

Reading an Array .size0 subcolumn together with the full Array column across
many granules of a compact part goes through the offsets stream append path in
SerializationArray::deserializeOffsetsBinaryBulk. A background merge that read
offsets across granules while the offsets column was shared with the reader
result could reallocate a buffer another holder still pointed at, surfacing as
a SIGSEGV in the offsets resize under sanitizers.

The compact reader read/build path was made COW-safe upstream, so the offsets
column is now solely owned at the in-place resize. This test guards the Array
variant (the sibling of the String .size case) against regressions: it reads
the .size0 subcolumn and the full array across granules and asserts the sizes
are correct.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

groeneai commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Partial. The original crash (STID 1367-2528, PR #107056, 2026-06-10) is a background-merge timing race that faults only under ASan poisoning; it is not deterministically triggerable from SQL alone (even the String sibling #109020 is not). The offsets-append path this test exercises IS deterministically reached (confirmed via an instrumented use_count() probe: the append fires per-granule, prev_size 16->32->48...).
b Root cause explained? Yes. When an Array .size0 subcolumn is read together with the full Array across granules, SerializationArray::deserializeOffsetsBinaryBulk appends offsets in place (deserializeArraySizesPositionIndependent -> offset_values.resize @ SerializationArray.cpp:176). Before the COW-safe reader fix, the compact reader could hand a shared offsets column into this path, so the in-place realloc freed a buffer another holder still referenced -> SIGSEGV in a merge thread.
c Fix matches root cause? N/A (no code change). The code fix already landed upstream: #107457 made MergeTreeReaderCompact::readData COW-safe (IColumn::mutate instead of assumeMutable()->insertRangeFrom), removing the aliasing source. This PR only adds the missing regression test for the Array variant.
d Test intent preserved / new tests added? Yes — this PR IS the new regression test. It reads the .size0 subcolumn and the full array across granules and asserts sizes are correct (the sibling of #109020's String test 04409).
e Both directions demonstrated? Partial. On current master (fix present) it PASSES: 0/36 mismatches across wide/compact x index_granularity x max_block_size x enable_lazy_columns_replication, ASan clean. The pre-fix "fails" direction is the recorded public CI SIGSEGV (STID 1367-2528). Per the maintainer-approved pattern, this is a regression test demonstrating the bug does not reproduce on HEAD.
f Fix is general across code paths? N/A (regression test only, not a code change).
g Fix generalizes across inputs? N/A (regression test only, not a code change).
h Backward compatible? N/A (regression test only, not a code change).
i Invariants and contracts preserved? N/A (regression test only, not a code change). Test uses a fixed table name within its own per-test database (same convention as sibling tests 04409/03651/03623), so it is parallel-safe; no no-parallel tag.

Verified against master HEAD 2a3a502 with an ASan build.

Session id: cron:clickhouse-worker-slot-3:20260701-190000

@groeneai

groeneai commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

cc @CurtizJ — could you review? Regression-test-only PR adding the Array .size0 cross-granule read test (the sibling of the String .size test in #109020). The code fix for this path already landed in #107457; this guards the Array variant, which had no coverage.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jul 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [82bdf21]

Summary: ✅


AI Review

Summary

This PR turns 04410 into a two-table regression test that now proves both compact-part Array .size0 read branches are exercised: it pins write_marks_for_substreams_in_compact_parts, asserts the effective mergeTreeIndex(..., with_marks = true) layout, and pins the multi-granule compact-part precondition. I did not find any remaining correctness or metadata issues on the current head.

Final Verdict

✅ No new inline findings for the current 82bdf21412e6cd9d18f36567a569f3514f9c7a9c head.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.68% 85.69% +0.01%
Functions 91.46% 91.46% +0.00%
Branches 78.23% 78.26% +0.04%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 82 line(s), 4 function(s) across 35 file(s) · Details

Top files
  • src/Processors/Transforms/BufferedShardByHashTransform.cpp: 7 line(s)
  • src/Columns/ColumnDynamic.cpp: 6 line(s)
  • src/Interpreters/ServerAsynchronousMetrics.cpp: 6 line(s)
  • src/Functions/FunctionsNumericIndexedVector.h: 5 line(s)
  • src/AggregateFunctions/AggregateFunctionSumMap.cpp: 4 line(s), 1 function(s)

Full report

@groeneai

groeneai commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

Done: switched the changelog category to Not for changelog (changelog entry is not required). Agreed the metadata now matches the scope, since this adds new regression coverage rather than fixing CI. Changelog entry stays empty and valid.

@groeneai

groeneai commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - c92d2f0

Every failure below has an owner (a fixing PR). None is PR-caused: this PR is regression-test-only (adds one stateless test) and cannot cause a suite-wide job-wrapper error.

Check / test Reason Owner / fixing PR
Stateless tests (amd_tsan, s3 storage, parallel, 2/2) transient job-level ERROR (exit 125, results: [], no individual test failed) - praktika watchdog timeout-cleanup hang #109096 (ours, open)
Mergeable Check / PR aggregators reflecting the single red leaf above n/a

Session id: cron:our-pr-ci-monitor:20260702-050000

@groeneai

groeneai commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — c92d2f0

Every failure below has an owner. This PR is regression-test-only (2 files: .sql + .reference); the one red test-check is a runner Docker-daemon death at post-run teardown, after the whole suite (including this PR's new test) passed.

Check / test Reason Owner / fixing PR
Stateless tests (amd_tsan, s3 storage, parallel, 2/2) Runner Docker daemon died at post-run teardown (exit 125, docker.sock EOF, grpc context canceled). 5581/5613 assigned tests ran, all OK incl. this PR's test; 0 per-test FAILs in CIDB. #109096 (ours, open)
PR Aggregator, mirrors the tsan/s3 leaf above #109096 (ours, open)
Mergeable Check Aggregator, mirrors the tsan/s3 leaf above #109096 (ours, open)

#109096 root-causes this exact exit-125 signature: a praktika watchdog bug in TeePopen._check_timeout (early-return skips the process-group kill) plus a container-name mismatch that makes docker rm -f a no-op. Not caused by this PR's changes; not a ClickHouse/test bug.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109090&sha=c92d2f0069b7c411648f9b76732fff2e72b1ee0e&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20s3%20storage%2C%20parallel%2C%202%2F2%29

Session id: cron:clickhouse-worker-slot-2:20260702-045900

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog and removed pr-ci labels Jul 28, 2026
groeneai added 3 commits July 29, 2026 03:00
MergeTreeReaderCompact::readData has two subcolumn branches. With per-substream
marks it reads the subcolumn through its serialization; without them it reads the
full column and extracts the subcolumn in memory. Only the second branch appends
into a possibly shared column, and it is reachable only for parts written with
write_marks_for_substreams_in_compact_parts = 0. That setting now defaults to 1,
so the test only exercised the first branch.

Pin the setting explicitly and keep a second table pinned to 1, so both branches
are covered, and assert the part type and the pinned value so the pins cannot
silently stop taking effect. An explicit per-DDL SETTINGS value wins over the
test runner's randomization injection (ClientBase::addMergeTreeSettings only adds
a randomized value when the DDL does not already set it), so no blanket
no-random-merge-tree-settings tag is needed; verified with 50 randomized runs.

Also drop the reference to test 04409_string_size_subcolumn_shared_buffer_merge,
which does not exist: its PR was closed unmerged.
Checking system.tables.engine_full only proves that different setting values were
recorded. The reader selects its branch from the part's mark type, so if writing
ever stopped honouring either pin both tables would exercise the same branch while
every result assertion still passed.

Assert through mergeTreeIndex(..., with_marks = true) instead: the a.size0
substream must have no mark without substream marks and a mark with them.
Both directions verified by mutation.
The test runner randomizes index_granularity_bytes down to 1 KiB, which makes
granule sizes vary and can leave granules with 0 rows, so a read with a large
block no longer reliably spans fixed-size granules. Pin it, and assert the
precondition: several granules, all 32 rows.

Pin it to a large value rather than 0. index_granularity_bytes = 0 turns off
adaptive granularity (MergeTreeData::canUseAdaptiveGranularity), and a
non-adaptive part must be Wide, which would drop the compact-part premise of
this test entirely.

The trailing mark of a part is a sentinel with rows_in_granule = 0, so the
granule assertions count only granules with rows.
@groeneai

groeneai commented Jul 29, 2026 •

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 82bdf21

CI fully finished on this head (no check queued or in progress, the praktika aggregator
completed, and the CIDB ingestion buffer has elapsed). Zero failing checks on this head,
so there is nothing to own.

Session id: cron:our-pr-ci-monitor:20260729-093000

@alexey-milovidov alexey-milovidov self-assigned this Jul 30, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 30, 2026
Merged via the queue into ClickHouse:master with commit d9bc9c0 Jul 30, 2026
179 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 30, 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 pr-not-for-changelog This PR should not be mentioned in the changelog 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