Skip to content

Add coverage for the HASHED_ARRAY SHARDS/UPDATE_FIELD guard and arrayShift* insertManyFrom specializations - #114287

Merged
PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/coverage-dictionaries-columns-batch2-group-b
Aug 12, 2026
Merged

PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/coverage-dictionaries-columns-batch2-group-b

Conversation

@groeneai

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

@ zlareb1 asked me to re-file a batch of closed coverage PRs (his ask). This is the dictionaries/columns group. Related: #103884, #103913, #103920.

Two new tests:

  • 04146_hashed_array_dictionary_shards_update_field pins HashedArrayDictionary.cpp:1265, which rejects SHARDS > 1 on an UPDATE_FIELD source. A textually identical guard at registerHashedDictionary.cpp:89 serves HASHED/SPARSE_HASHED and is covered by 02391_hashed_dictionary_shards; the HASHED_ARRAY copy was not covered.
  • 04201_array_shift_insert_many_from_specializations pins the insertManyFrom overrides of ColumnFixedString, ColumnDecimal, ColumnNullable, ColumnTuple and ColumnMap through arrayShiftRight/arrayShiftLeft. Master's only arrayShift* test uses UInt8/UInt16/String/Array element types, so this call site was untested for these five.

Every assertion was mutation-tested: corrupt the cited line, confirm the test reddens, revert, confirm it passes. That found five defects in the adopted #103913, all fixed here (details below).

I am not re-filing #103920. Its oracle is sound, but isShortCircuit has no layout or arity branch (FunctionsExternalDictionaries.h:356-368) and both regression directions are already pinned, verified by mutation: 02950_dictionary_short_circuit.sql:28 catches losing the - 1, 03009_range_dict_get_or_default.sql:29 catches a revert to the pre-fix set. Reasoning is on that PR.

Validation

Baseline: 7 tests (2 new + 5 controls) pass, rc == 0 and verdict OK per test.

arm mutated reddens stays green
A1/A2 HashedArrayDictionary.cpp:1265, both directions 04146 02391 (the other guard copy)
B1 FunctionsExternalDictionaries.h:361 drops - 1 02950 (DIVISION_BY_ZERO) 03009
B2 same line, pre-fix hardcoded set 03009 02950
P arrayShiftRotate.cpp:213+:219 position -> 0 04201, 02845 dictionary tests
C1 ColumnFixedString.cpp:118 04201 JOIN block, 00436
C2 ColumnDecimal.h:69 04201 others
C3a/C3b ColumnNullable.cpp:320 / :321 disjoint row sets of 04201 each other's control
C4/C5 ColumnTuple.cpp:319 / ColumnMap.cpp:216 04201 02845, 01019

Mutations change each branch's output rather than deleting it: deleting any override falls through to IColumn::insertManyFrom's insertFrom loop and produces identical output, leaving a vacuous test green.

Five defects found in the adopted #103913 and fixed here:

  1. Its JOIN block claimed HashJoin reaches insertManyFrom. It does not: with ColumnFixedString::insertManyFrom corrupted, the JOIN block alone still passes. Cut.
  2. Its Nullable rows passed a non-NULL default, so the null-map line was never exercised.
  3. "No existing test exercises these specializations" was too strong: 01019_array_fill reddens under both ColumnNullable mutations, 02411_legacy_geobase under the ColumnTuple/ColumnMap ones. Only the arrayShift* call site is new.
  4. Two fixtures used the type's own default as the "distinctive" default, so an insert-defaults mutation was invisible.
  5. Every query was single-row, so position was always 0 and an override ignoring it would have passed. Fixtures are now multi-row with per-row defaults.

216 runs green: 50 of each test with randomized settings (the CI default), 50 with --no-random-settings, and 8 concurrent copies over 4 jobs. No no-parallel tag and no settings clamp needed.

Separately, arrayShiftRight([1::Nullable(Int64),2,3], 2, NULL::Nullable(Int64)) returns [0,0,1] rather than NULLs, while arrayResize with the same default returns [1,2,NULL,NULL]. The 2-argument form is correct. Not fixed here.

…ft* insertManyFrom specializations

Re-files the coverage of two closed clickgapai PRs (ClickHouse#103884, ClickHouse#103913) that
@ zlareb1 asked to be re-opened, with the gap claims narrowed to what I could
measure and the oracles mutation-tested.

04146_hashed_array_dictionary_shards_update_field pins
src/Dictionaries/HashedArrayDictionary.cpp:1265, which rejects SHARDS > 1 on an
UPDATE_FIELD source. A textually identical guard at
src/Dictionaries/registerHashedDictionary.cpp:89 serves HASHED/SPARSE_HASHED and
is already covered by 02391_hashed_dictionary_shards; the HASHED_ARRAY copy was
not covered by anything. Mutating :1265 alone reddens the new test while 02391
stays green, which is what attributes the coverage to the right copy. The
complex-key block of the original test is not kept: registerLayout("hashed_array")
and ("complex_key_hashed_array") call the same create_layout lambda and the guard
precedes the DictionaryKeyType branch, so both key forms are one carrier.

04201_array_shift_insert_many_from_specializations pins the insertManyFrom
overrides of ColumnFixedString, ColumnDecimal, ColumnNullable, ColumnTuple and
ColumnMap through the two arrayShiftRotate.cpp call sites. Master's only
arrayShift* test uses UInt8/String/Array element types, so this call site was
untested for these five.

Five defects in the adopted ClickHouse#103913 are fixed here. Its JOIN block claimed
HashJoin reaches insertManyFrom; isolated and re-run with
ColumnFixedString::insertManyFrom corrupted, that block still passes, so it never
reaches the override and is dropped. Its Nullable rows passed a non-NULL default,
leaving the null map unexercised; an explicit NULL default does not reach the null
map at all, so the omitted-default form is asserted alongside, and the two
ColumnNullable carriers now redden disjoint row sets. Its "no existing test
exercises these specializations" claim is false: 01019_array_fill reddens under
both ColumnNullable mutations and 02411_legacy_geobase under the ColumnTuple and
ColumnMap ones, so only the arrayShift* call site is new. Two fixtures used the
type's own default as the distinctive default, hiding an insert-defaults
mutation. Every query was single-row, so insertManyFrom's position argument was
always 0 and an override ignoring it would have passed; the fixtures are
multi-row with per-row defaults, and a mutation hardcoding position = 0 reddens
them.

Mutations change each branch's output rather than deleting it, because deleting
any of these overrides falls through to IColumn::insertManyFrom's insertFrom loop
and produces identical output.

The third PR of the group, ClickHouse#103920, is not re-filed. isShortCircuit has no layout
and no arity branch, and both regression directions at
FunctionsExternalDictionaries.h:361 are already pinned by
02950_dictionary_short_circuit.sql:28 and 03009_range_dict_get_or_default.sql:29.
…ap comment

The guard at src/Dictionaries/HashedArrayDictionary.cpp:1265 rejects
SHARDS > 1 on an UPDATE_FIELD source, so its threshold is 1. The test
bracketed 1 (accepted) against SHARDS 10 (rejected), which left the
2..9 range unpinned: a regression moving the threshold anywhere into
that range kept both assertions green while wrongly admitting those
values. The rejected value now sits on the guard's exact negative
boundary. That is strictly tighter and reaches no other decision,
because the throw precedes the shards > 1 template dispatch at
:1279-1289 and 2 is inside the [1, 128] range check at :1258.

A new mutation arm moving the threshold to shards > 9 reddens the test,
and the matching negative control shows the old SHARDS 10 fixture stays
green under that same mutation, so the tightening is what added the
coverage rather than the test merely reacting to some mutation. The two
existing arms were re-run against the new fixture and still redden this
test while 02391_hashed_dictionary_shards stays green, so attributing
the coverage to this guard copy rather than the identical one at
registerHashedDictionary.cpp:89 still holds.

The null-map comment in
04201_array_shift_insert_many_from_specializations said the omitted
default is the only shape that fills the null map from the default.
ColumnNullable::insertManyFrom always copies the null map from the
default column, so an explicit default contributes FALSE bits and the
omitted form is the only shape contributing TRUE bits. An explicit
Nullable default cannot supply NULL bits at all: the result type is
Array, which is not canBeInsideNullable, so the default is denulled and
its NULL rows are overwritten by insertDefault before executeImpl runs.
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review

Reviewed cold against the resulting tests, then adjudicated with the recorded evidence. Two
rounds: the first found one real liveness gap, which is fixed above; the second returned clean.

❌ SHARDS 10 did not pin the guard's boundary. The guard is shards > 1
(HashedArrayDictionary.cpp:1265), so bracketing 1 (accepted) against 10 (rejected) left every
threshold in 2..9 green: a regression to shards > 5 would have kept the test passing while
wrongly admitting SHARDS 2..5. The mutation matrix had not caught it either, because its arm
moved the threshold to 128, which SHARDS 10 still reddens. Fixed by using SHARDS 2, and a new
arm mutating the guard to shards > 9 now reddens the test while the old fixture provably stayed
green.

⚠️ A comment over-claimed how the null map is filled. ColumnNullable::insertManyFrom
(ColumnNullable.cpp:321) always copies the null map from the default column; an explicit
non-NULL default contributes FALSE bits. The omitted-default form is the only shape that
contributes TRUE bits. Comment reworded.

The review also asked for a dispatch or performance oracle that would fail if a specialized
insertManyFrom silently fell back to IColumn's loop. Not added, and I do not think it should
be: insertManyFrom has no ProfileEvent or any other SQL-observable dispatch surface, and the
specializations are output-equivalent to the fallback, so a fall-through has no user-visible
consequence to assert. That is a performance property and belongs in tests/performance/. It is
also why every arm in the matrix corrupts a value rather than deleting an override: a delete is
invisible in the output and would leave a vacuous test green.

Two claims in my own description were also corrected before posting: the residual at the end cited
a bare NULL where the measurement used NULL::Nullable(Int64) (different code paths - a bare
NULL is Nullable(Nothing), so the row collapses before executeImpl runs), and the element
types already covered by 02845_arrayShiftRotate include UInt16, not just UInt8/String/Array.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation
check result
a deterministic repro N/A (coverage PR). Equivalent: a mutation matrix in which 11/11 arms reproduced the expected redness on the first run after a Build-ID-verified rebuild, and every arm returned to green after revert.
b root cause explained HashedArrayDictionary.cpp:1265 is one of two textually identical hasUpdateField() && shards > 1 guards and only the other (registerHashedDictionary.cpp:89) was covered. The five insertManyFrom overrides were untested at the arrayShift* call site for FixedString / Decimal / Nullable / Tuple / Map.
c fix matches root cause Assertions bind exactly the cited lines. Proven by per-copy attribution (mutating :1265 reddens the new test while 02391 stays green) and per-carrier isolation (ColumnNullable.cpp:320 and :321 redden disjoint row sets).
d test intent preserved / tests added 4 files added; no existing test modified, weakened, retagged or renumbered. git diff against the base is empty for tracked files.
e both directions Every arm fails with the mutation and passes after revert, with the Build ID verified to move and to be restored. Arms A1/A2 mutate the same line in opposite directions and both redden.
f general across code paths Carriers enumerated: the guard's two copies; simple vs complex key proven a single carrier (shared create_layout lambda, guard precedes the key-type branch); ColumnNullable proven two carriers, both asserted; ColumnMap proven a forwarder onto ColumnArray, which has no override. Other callers of the overrides were measured for prior coverage, and the PR's claim is narrowed to what that showed.
g general across inputs 5 element types, 3 rows each, pairwise-distinct per-row defaults none of which equals the type's own default; Nullable asserted in both the explicit-default and omitted-default forms; both arrayShiftRight and arrayShiftLeft call sites; shift values including shift == length.
h backward compatible Test-only. No setting, default, format or SettingsChangesHistory.cpp obligation.
i invariants and contracts No source change. Both tests create and drop every object inside the runner's per-test database, verified by running 8 concurrent copies over 4 jobs.

Mutations change each branch's output rather than deleting it: deleting any of these overrides falls through to IColumn::insertManyFrom's insertFrom loop and yields identical output, so a delete-mutation would leave a vacuous assertion green.

216 runs green: 50 of each test with randomized settings (the CI default), 50 with --no-random-settings, 8 concurrent copies over 4 jobs. No settings clamp and no no-parallel tag are needed.

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @nihalzp, could you review this? It adds two coverage tests: one pinning the HASHED_ARRAY guard that rejects SHARDS > 1 on an UPDATE_FIELD source (only the textually identical HASHED/SPARSE_HASHED copy was covered), and one pinning the insertManyFrom overrides of ColumnFixedString, ColumnDecimal, ColumnNullable, ColumnTuple and ColumnMap through arrayShift*, where multi-row per-row-default fixtures are what make a nonzero position observable.

@nihalzp nihalzp added the can be tested Allows running workflows for external contributors label Aug 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a4471a7]

Summary: ❌

job_name test_name status info comment
Stress test (amd_tsan) FAIL
Hung check failed, possible deadlock found FAIL cidb IGNORED

AI Review

Summary

This PR adds two focused stateless coverage tests: one for the HASHED_ARRAY UPDATE_FIELD/SHARDS rejection path and one for arrayShift* coverage across several insertManyFrom specializations. I did not find a correctness, safety, or test-quality issue on the current head that warrants a new inline review comment; residual risk is low, with the usual caveat that these are implementation-focused coverage pins rather than broad behavior specifications.

Final Verdict

✅ No findings.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing a4471a7c5 with master c462bd702 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 57b9bc5ef; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 691.29 MiB 688.29 MiB -3.00 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

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

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - a4471a7

CI is fully finished on this head: 175 checks completed, 39 success, 135 skipped (each with a
recorded reason; the high count is expected for a test-only diff), 1 failure. The praktika report
shows 0 dropped jobs, so the run carries real coverage. Every failure below has an owner.

Check / test Reason Owner / fixing PR
Stress test (amd_tsan) / Hung check failed, possible deadlock found deadlock, not PR-caused #113397 (external, open)

I parsed hung_check.log per Row N: block rather than reading the pooled frame list. The root
hung query is a cancelled DROP TABLE prometheus (is_cancelled: 1, elapsed 1030.8 s) parked in
DatabaseCatalog::waitTableFinallyDropped; the two DROP DATABASE ... SYNC queries (982.8 s and
460.4 s) and the DETACH DATABASE (392.7 s) behind it are victims convoyed on the DDL guard, not
separate defects. That table is permanently stuck in the drop queue because a leaked plan graph
still holds a reference to its storage, which is exactly what #113397 fixes. @ vitlibar closed his
own "Fix inner table drop hang" (#114302) today in favour of #113397 after @ azat pointed out that
merely making the DROP cancellable leaves the table in the dropping queue.

Not PR-caused: this PR changes only four stateless test files (two .sql and two .reference),
none of which touch TimeSeries storage or DatabaseCatalog teardown. The signature is
trunk-wide: 156 hits across 132 distinct PRs plus 11 master runs on Stress test (amd_tsan) alone
in the last 30 days.

Session id: cron:our-pr-ci-monitor:20260811-223000

@PedroTadim PedroTadim self-assigned this Aug 12, 2026
@PedroTadim
PedroTadim added this pull request to the merge queue Aug 12, 2026
Merged via the queue into ClickHouse:master with commit 9678956 Aug 12, 2026
178 of 180 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 12, 2026
@groeneai groeneai added the groeneai-origin-request PR origin: a maintainer pinged or directed groeneai label Aug 19, 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 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.

4 participants