Skip to content

Add test: No test for merge handling in readonly MergeTree refresh (refreshDataParts covers parts by Transaction::commit) - #101781

Closed
clickgapai wants to merge 1 commit into
ClickHouse:masterfrom
clickgapai:qa-bot/coverage-pr79033
Closed

clickgapai wants to merge 1 commit into
ClickHouse:masterfrom
clickgapai:qa-bot/coverage-pr79033

Conversation

@clickgapai

Copy link
Copy Markdown
Contributor

Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment.

Retrospective finding from a historical scan of PR #79033 (merged 2025-04-11). Confirmed on current codebase — close with a note if already fixed.

Adds test coverage for 1 untested code path(s), found during automated review of PR #79033.

1. No test for merge handling in readonly MergeTree refresh (refreshDataParts covers parts by Transaction::commit)
src/Storages/MergeTree/MergeTreeData.cpp:2660, src/Storages/MergeTree/MergeTreeData.cpp:2688
Why this test: MergeTreeData::refreshDataParts (MergeTreeData.cpp:2620) loads new parts and adds them via Transaction::commit which calls getActivePartsToReplace to mark old covered parts as Outdated. This merge han
What's unique: PR's test 03362 covers only basic single INSERT + read. This test covers the merge handling path: multiple inserts → writer merge → reader refresh correctly handling covered parts without duplicates.

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):

Not applicable — test-only change.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Found during review of PR #79033.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label May 2, 2026
@zlareb1

zlareb1 commented Aug 10, 2026

Copy link
Copy Markdown
Member

@groeneai can you take this up and open a new PR?

@zlareb1 zlareb1 closed this Aug 10, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

Taking these up. I triaged all 26 of this batch against master 2850e469dcac84b (26.8.1.1) before answering, so the plan below is measured rather than assumed.

All 26 are viable. Every diff is test-only and applies cleanly, and every cited source line still exists on master, so none of them is obsolete by code removal. I am not declining any of this batch.

One test needs a fix before it can be re-filed. #103889 asserts serverError TABLE_IS_READ_ONLY (242), but master throws 774 TABLE_IS_PERMANENTLY_READ_ONLY. Worth flagging how it hides: stdout still matches the committed reference byte-for-byte while the test fails, because the mismatch only appears on stderr. Substituting the 774 name makes it pass. I re-checked every other test's stderr after finding this.

I mutation-tested the oracles rather than trusting a green run. Two examples, both proven to really assert something: #103920's default expression intDiv(1, materialize(0)) throws ILLEGAL_DIVISION on its own, so the test returning 100 genuinely proves the default stayed lazy; #103931's input really reaches the wstart > wend guard (Time overflow in function windowID), with a non-overflowing control still returning a value.

I am keeping the existing test numbers. I had carried forward a note that these all needed renumbering, and that turns out to be wrong: master has 13192 stateless tests across only 3755 distinct numeric prefixes, so shared prefixes are normal, and the only filename rule in CI (check_file_names in ci/jobs/check_style.py) rejects duplicate full filenames case-insensitively, not shared numbers. None of the 26 filenames collides with anything on master.

Two caveats on scope. #101284 needs a real server (it is shard-tagged and uses remote()), so it gets validated under the test runner rather than clickhouse-local. #101781, #103939 and #103935 are concurrency, replication and progress-reporting shapes, so I will not pretend they are simple one-liners.

On packaging: this is the second batch today, 26 here plus 18 from the earlier one, 44 tests total. I am not going to open 44 PRs. I will group them by area (formats/IO, MergeTree/replication, analyzer/planner, functions/types, dictionaries, access) and post the resulting PR links here. If any individual test turns out not to hold up once it is under real CI, I will say so on its own PR with the reason instead of quietly dropping it.

This was referenced Aug 10, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

First of the grouped PRs from this batch: #114260, the functions/types group, covering six of the gaps (#103918, #103922, #103940, #107447, #103885, #103931).

#103897 is declined, with the reason posted on its own PR: the getLeastSupertype mixes it targets are already covered by 04234_transform_const_default_cast.sql:23-26, which reddens on the same mutation.

Each adopted test was mutation-checked rather than taken on trust: I changed the exact line it claims to cover, rebuilt, and required that test to fail while the others stayed green. That found three defects in the originals, including one test that was flaky by construction because its arguments were read in the session timezone, which CI randomizes.

The remaining 19 gaps from this batch are being grouped the same way (formats/IO, MergeTree/replication, analyzer/planner, dictionaries, access); links will follow here.

@groeneai

Copy link
Copy Markdown
Collaborator

Group B of the re-file, covering the dictionaries and columns PRs: #114287

Every assertion was mutation-tested rather than merely run: corrupt the line it claims to pin, confirm the test reddens, revert, confirm it passes. That found five defects in the adopted #103913, which are described in the PR.

@groeneai

Copy link
Copy Markdown
Collaborator

Group D of this batch, the analyzer/views group: #114293, covering three of the five gaps (#103925, #103930, #103914).

Two are declined, each with the reason posted on its own PR rather than left silent. #103923's alias-qualified _table/_database case is already pinned by 04338_merge_distributed_virtual_columns_with_join.sql:37-40, and its only other site is a cache-hit path that deliberately leaves the cached query tree unrewritten, so no assertion can reach it. #101743 would freeze an unresolved semantic: CREATE-time materialized-view validation reads getSampleBlockInsertable() while the runtime sink reads getSampleBlock(), so they disagree about MATERIALIZED columns in the target, and which side is right is an owner-level call rather than something a reference file should settle.

One of the three shrank on inspection: #103930 ships as a single added assertion inside the existing 02884_create_view_with_sql_security_option rather than as a new file, because that test already performs the definer-to-invoker transition and already reads SHOW CREATE TABLE - only the negative check that the definer is gone was missing.

As with group A, each adopted test was mutation-checked rather than taken on trust: I changed the exact line it claims to cover, rebuilt, and required that test to fail while the others stayed green. That also corrected two of my own earlier claims, one about a view carrying no definer to clear, and one about which existing tests reach the ATTACH throw.

Group A was #114260. The remaining groups from this batch are in flight and links will follow here.

@groeneai

Copy link
Copy Markdown
Collaborator

Re-filed as #114296, the MergeTree-refresh / progress / replication group, covering this gap together with #103935 and #103939.

The test here is not the original one. Its count() = 3 oracle passes when the refresh never runs at all, because the pre-merge state is also 3 rows, and an active-part count is no better: Transaction::commit demotes the covered parts itself, upstream of grabOldParts, so the active set is 1 whether or not the retirement half runs. The replacement asserts the part state through _state (Deleting on master, Outdated under the mutation) and drives the refresh synchronously with SYSTEM RESTART DISK instead of waiting on refresh_parts_interval.

Found the same way as in the earlier groups: I mutated the exact line the test claims to cover (MergeTreeData.cpp:3289), rebuilt, and required this test to fail while the four pre-existing refresh_parts_interval tests stayed green.

#101284 from this group is declined, with the reason posted on its own PR.

@groeneai

Copy link
Copy Markdown
Collaborator

Group C of this batch, the MergeTree/index group: #114305, covering four of the seven gaps (#101750, #103984, #108884, #108815).

#108815 is folded into my existing 04401_low_cardinality_fixed_string_partition_pruning rather than a new file, since it is the same fixture one row further along.

Three are declined, each with the reason on its own PR: #101724 (the oracle is satisfied by a type error raised upstream of the guard it claims to cover, so it passes with that guard deleted), #103889 (the disk combination is already exercised by tests/integration/test_attach_backup_from_s3_plain/test.py, and the test also ships the wrong error code), #103893 (duplicates 03203_count_with_non_deterministic_function.sql, which is the guard's own regression test).

Two of the four adopted tests turned out to pass without ever reaching their guard. 04489_virtual_row_disabled_with_final was instrumented and reached its guard zero times: the outer count() eliminated the subquery's ORDER BY, so no read-in-order plan was built at all. The LIMIT ... WITH TIES one asserted counts that are identical whether the push-down pass matched the plan or never ran. Both now carry a paired pin that fails when the guard stops being reached.

alexey-milovidov pushed a commit to evillique/ClickHouse that referenced this pull request Aug 12, 2026
Re-files three closed clickgapai coverage PRs (ClickHouse#101781, ClickHouse#103935, ClickHouse#103939) that
@ zlareb1 asked to be reopened. A fourth, ClickHouse#101284, is not included: its mechanism
is already pinned by five existing tests, so it would be a duplicate.

Each branch was mutated, rebuilt and re-run to confirm the test detects it, and
each mutation had to leave the pre-existing tests of the same mechanism green so
that reddening is evidence of incremental coverage rather than of the mechanism
merely being live. Two of the three originals failed that check:

- ClickHouse#101781 asserted count() = 3 after the writer merged. The pre-merge state is
  also 3 rows, so a run in which the refresh never happened is indistinguishable
  from a correct one. An active-part count is no better: refreshDataPartsOnce
  commits the merged part with the same Transaction::commit that demotes the
  parts it covers, upstream of grabOldParts, so the active set is 1 in both
  directions. The test now asserts the part state through the _state virtual
  column, which is Deleting on master and Outdated when grabOldParts is not asked
  to force removal. The refresh is driven by SYSTEM RESTART DISK, which calls the
  same body synchronously, so no sleep is needed, and the writer's merges are
  bracketed by SYSTEM STOP/START MERGES so its own scheduler cannot merge the
  three inserts before the first assertion.

- ClickHouse#103939 asserted count() <= 10 while a REPLACE PARTITION and a mutation raced
  for ten seconds. That passes whenever the race is not won, which is the likely
  outcome; measured against a binary with the guard broken, it still passes. It
  is replaced by a deterministic sequence: the REPLACE is parked inside its own
  intent window on the existing rmt_cancel_removed_parts_check_pause_in_gap
  failpoint, reached from replacePartitionFrom via cancelRemovedPartsCheck while
  the intent is held, and the test then asserts the mutation entry's
  postpone_reason in system.replication_queue. That column is the one the guard
  writes; system.mutations.parts_postpone_reasons carries a different vocabulary
  fed only by the merge-selection path, so polling it would never observe this.

ClickHouse#103935 was sound and is adopted close to as written. Only its cited line was
stale: the override is at AggregatingTransform.cpp:150, not :143.

The coverage gaps were measured against the mechanism rather than the setting
name, which is what the ClickHouse#101284 duplicate turned on. None of the four
refresh_parts_interval tests ever merges, no test asserts read_rows after an
external GROUP BY spills through any observable, and no test contains the intent
guard's message.

no-parallel is on the replication test only, and is earned rather than assumed:
run concurrently with itself the untagged form fails because a second copy
consumes the once-only pause, while the tagged form passes. The other two carry
no such tag and were run concurrently with themselves to confirm it.
pull Bot pushed a commit to Mu-L/ClickHouse that referenced this pull request Aug 12, 2026
Re-files three of five closed clickgapai coverage PRs (103925, 103930, 103914)
that zlareb1 asked to be re-filed via ClickHouse#101781. Two of the five are declined with
the reason posted on their own threads: 101743 (its reference would freeze an
unresolved CREATE-time-vs-runtime MV validation semantic, an owner-level call)
and 103923 (its only site beyond 04338 is the cache-hit copy, which leaves the
cached query tree unrewritten, so it is not observable from SQL).

Each shipped test was falsified rather than taken on trust: the exact line it
claims to cover was mutated, the binary rebuilt with the Build ID asserted to
move, and the test required to fail while neighbouring tests stayed green.

- 04201_attach_table_missing_database pins the UNKNOWN_DATABASE throw in the
  stub-ATTACH block of InterpreterCreateQuery.cpp. No file under tests/ asserts
  UNKNOWN_DATABASE for an ATTACH, and the qualified bare-ATTACH tests on master
  all attach into a database that exists first. The sibling throw on the
  createTable path is uncovered too and stays out of scope here. Because the
  mutation is injected at that throw, only a statement resolving there can
  redden, which is what pins the site. One statement: ATTACH DICTIONARY reaches
  the identical throw before any is_dictionary discrimination.

- 04201_force_null_for_omitted_jsoncolumns pins the force-null check in
  JSONColumnsBlockInputFormatBase. That setting has six independent copies in
  src/ and 03004 covers five, not this one. Two rows rather than eight:
  JSONColumns, JSONCompactColumns and JSONColumnsWithMetadata were measured to
  emit a byte-identical exception from the same base class, so they are one
  dispatch. Negating the type predicate reddens this test while 03004 stays
  green, so the sibling copies are untouched.

- 02884_create_view_with_sql_security_option gains one assertion instead of a
  new file. It already performs the definer-to-invoker transition and reads
  SHOW CREATE TABLE; only the negative check that the definer is gone was
  missing. The pattern needs the equals sign, since a bare DEFINER also matches
  SQL SECURITY DEFINER. Leaving the definer uncleared flips that assertion from
  0 to 1 and changes nothing else in the file, while its existing
  SQL SECURITY INVOKER row stays 1 and so serves as the did-the-ALTER-run
  control.

The ATTACH reference is empty, which is correct for a serverError-only test, and
was verified on stderr: a stray newline or a wrong error code both fail. The
02884 reference line was placed by running the test and rebuilding the file from
its output, not by hand. The ATTACH test is scoped to CLICKHOUSE_DATABASE_1
rather than a server-global database name so it is safe to run against itself.

Both new tests passed 50 runs with randomized settings and 50 with
--no-random-settings, plus four concurrent copies of themselves and a joint run
with 03004, 04126, 04010, 04141 and 02884, so neither needs no-parallel.
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants