Repository navigation
Add coverage tests for four untested MergeTree and index branches - #114305
alexey-milovidov merged 5 commits into
Conversation
Re-files four of the seven MergeTree/index coverage tests from the batch zlareb1 asked to have re-opened on ClickHouse#101781. Tests only, no production code. Each test pins one guard that no existing test observes: * 04489_part_starting_offset_in_subquery: a _part_starting_offset + _part_offset predicate written as IN must still prune marks. Existing tests cover equality (03443_part_starting_offset) and ranges (04408_lazy_materialization_part_offset_prewhere), never IN. Both IN shapes are kept because they take different index search algorithms (binary search for the subquery-backed set, generic exclusion search for the literal list) and each reddens independently. The max_rows_to_read bound is measured (read_rows = 2), not guessed. Adopted from ClickHouse#101750. * 04489_virtual_row_disabled_with_final: SELECT ... FINAL must not lose rows when the read-in-order virtual row is enabled. The adopted query never reached the guard, because an outer count() eliminates the subquery's ORDER BY and no sorting step is built, so setVirtualRowConversions is never called; instrumentation measured zero calls. Adding LIMIT builds the read-in-order plan. Adopted from ClickHouse#103984. * 04489_aggregation_in_order_limit_with_ties: LIMIT n WITH TIES must not be pushed into aggregation-in-order, which would truncate the tie group. The EXPLAIN PIPELINE row is a liveness pin: the multi-stream FinishAggregatingInOrderTransform enforces the limit per finalized batch and can overshoot into the whole tie group even with a broken guard, so without that row the test can pass on a broken build. Adopted from ClickHouse#108884. * 04401_low_cardinality_fixed_string_partition_pruning gains two rows for a String literal too long for a LowCardinality(FixedString) key: no pruning condition may be built, and the result stays correct. This extends the existing test for the same fix rather than adding a near-duplicate file with a near-duplicate fixture. Adopted from ClickHouse#108815. Each test was adopted only after it was proven to observe its branch: a regression was injected at the cited line, the binary rebuilt, and the test required to fail; then reverted, rebuilt, and required to pass, with the Build ID required to move on both transitions. Every arm carries a positive control proving the mutation landed and a negative control proving it did not disable the surrounding machinery. Validated with 200 runs under randomized settings (the CI default) and 200 with randomization off, no failures, run 8-way concurrently so no no-parallel tag is needed. Three tests from the same batch are not filed. ClickHouse#101724's assertion is satisfied by a type error raised at the value-type gate in MergeTreeIndexBloomFilterText, upstream of the guard it claims to cover, so it would hold identically with that guard deleted or the index absent. ClickHouse#103889's disk combination is already exercised end to end by tests/integration/test_attach_backup_from_s3_plain. ClickHouse#103893 duplicates 03203_count_with_non_deterministic_function, which converges on the same nullptr in splitFilterNodeForAllowedInputs, asserts an exact count instead of a range, and runs both analyzers.
Review round 1. Three assertions were only meaningful on a local, in-order plan but did not say so, and would silently stop observing their guard in CI profiles this PR runs in. 04489_virtual_row_disabled_with_final asserted row values only, which stay correct whenever the virtual row is never attempted - the vacuous state this test was already measured to be in once before its shape was repaired. It now asserts, as a pair, that the in-order FINAL read carries no virtual row conversion while the same fixture without FINAL does build one. Deleting the FINAL guard flips the FINAL row and leaves the control row alone. The settings sit on the EXPLAIN statement rather than the inner subquery because the test runner passes randomized settings as client options, and optimize_read_in_order=0 arriving that way overrides a SETTINGS clause attached to a subquery. Measured: with the clause on the subquery the assertion silently reports the wrong answer under that option. 04489_aggregation_in_order_limit_with_ties asserts a local pipeline shape and 04489_part_starting_offset_in_subquery bounds max_rows_to_read, which is accounted per reading node. Both pin enable_parallel_replicas=0, following 04234_aggregation_in_order_limit_pushdown's narrow setting rather than a no-parallel-replicas tag that would skip the files. Under the ParallelReplicas job's server profile the offset test failed 2 of 30 runs before the pin and 0 of 40 after; the WITH TIES oracle still reddens with the pin present. 04401's header said the test asserts the optimization is preserved; it now also mentions the bail-out its appended rows cover.
The three existing rows print 1/100/100 whether the push-down pass matched this plan or never ran at all, because limit_hint is not printed by AggregatingStep::describeActions and does not change the transform's name. Add a plain-LIMIT control on the same GROUP BY (a, b) / ORDER BY a prefix shape and observe read_rows on and off, following the oracle shape of 04234_aggregation_in_order_limit_pushdown. Verified with a mutation that breaks hasPrefix for a proper prefix: the new row flips while the three existing rows stay unchanged. Anchor the first conjunct of the pipeline assertion. FinishAggregating- InOrderTransform contains AggregatingInOrderTransform as a substring, so the unanchored LIKE was satisfied by the multi-stream shape and only the second conjunct rejected it.
Internal second-model review (3 rounds, all findings resolved)Reviewed independently of the author across three rounds. Every finding below is closed.
💡 Nits, resolved: the pipeline assertion's first conjunct was not independently One reviewer nit was disagreed with evidence: the Every oracle was mutation-tested with positive and negative controls, and the Build ID was |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20260811-040900 |
|
cc @vdimir, could you review this? Tests only: four coverage tests for guards that had none, each pinned so it fails when the guard stops being reached rather than only when results change (two of the four originally passed without reaching their guard at all). |
|
Workflow [PR], commit [2b6c5be] Summary: ✅ AI ReviewSummaryThis PR adds four stateless coverage tests around MergeTree/index behaviors and fixes one previously reported blind spot in Findings
Final VerdictChanges needed. |
…w_disabled_with_final The three runtime assertions attached their SETTINGS clause to an inner subquery. clickhouse-test injects randomized settings as client options with --allow_repeated_settings, and a client option beats a subquery-level SETTINGS clause, so a randomized optimize_read_in_order = 0 disabled the read-in-order path while the counts stayed correct: the executed query no longer observed the guard the test exists for. Measured with the FINAL guard removed at ReadFromMergeTree.cpp:3323. Under --optimize_read_in_order 0 the old first row printed the expected 8192/16384 (blind), while the new form still prints 0/0. Both settings are randomized by the runner (clickhouse-test:1517 and :1683). enable_parallel_replicas = 0 is pinned for the same reason: with parallel replicas on and parallel_replicas_local_plan = 0 the non-FINAL probe is served by ReadFromRemoteParallelReplicas instead of the local read. Validation on the restored build: 120 runs across the default, --no-random-settings and forced optimize_read_in_order=0 / read_in_order_use_virtual_row=0 profiles, plus 100 runs in the faithful ParallelReplicas + LLVM-coverage profile, 0 failures. Reported by clickhouse-gh[bot] on ClickHouse#114305.
|
Confirmed by measurement and fixed in c11b082. I removed the
So the first runtime row did stop observing the guard in exactly that state. Both settings are randomized by the runner ( All three runtime assertions now carry their settings on the outermost statement. I also took the Validation on the restored build: 120 runs across the default, One measurement that did not become a change: a forced parallel-replicas profile flips 04401's four pre-existing master rows, but that profile is harsher than the job it models (the real job passes |
Build profile diff (arm_release)No arm_release build profile data for commit 2b6c5be - the build was skipped, reused from cache, or predates profile upload. |
CI finish ledger - c11b082Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
All five rows are one event, and none of them can come from this PR. This PR adds four stateless test files and nothing else: no The stack is the known set-index family: On the Cross-PR breadth of this signature in Stress jobs over 30 days: 234 rows across 165 distinct PRs, plus Session id: cron:our-pr-ci-monitor:20260811-200000 |
| SELECT countIf(replaceAll(explain, ' ', '') ILIKE '%ReadType:InOrder%') > 0 | ||
| AND countIf(explain ILIKE '%Virtual row conversions%') > 0 | ||
| FROM (EXPLAIN actions = 1 | ||
| SELECT count() FROM (SELECT x FROM t_vrow_select_final ORDER BY x LIMIT 20000) | ||
| SETTINGS optimize_read_in_order = 1, read_in_order_use_virtual_row = 1, enable_parallel_replicas = 0); |
There was a problem hiding this comment.
The positive control here is still vulnerable to one randomized plan shape. This file only disables random MergeTree settings, so read_in_order_two_level_merge_threshold and read_in_order_use_virtual_row_per_block can still come from the runner. When the threshold is low enough for two parts and read_in_order_use_virtual_row_per_block = 0, ReadFromMergeTree inserts the preliminary MergingSortedTransform (ReadFromMergeTree.cpp:1485-1489, ReadFromMergeTree.cpp:1683-1717), and that merge consumes the virtual rows before they reach the downstream sorter. EXPLAIN actions still prints Virtual row conversions because virtual_row_conversion is set on the read step, so this goes green again without proving the path that the FINAL guard is protecting. Please pin either read_in_order_use_virtual_row_per_block = 1 or read_in_order_two_level_merge_threshold to a value that suppresses the preliminary merge on the non-FINAL controls.
There was a problem hiding this comment.
Measured this rather than reasoning about it, and it does not reproduce. Two of the three premises hold, the conclusion does not.
Right: read_in_order_two_level_merge_threshold is runner-randomized (tests/clickhouse-test:1522, randint(0, 100)), and the plan assertion is indeed insensitive to it (1 1 at both the default and at threshold=1).
Three measurements against it:
-
read_in_order_use_virtual_row_per_blockis not randomized: 0 hits intests/clickhouse-test, against passing positive controls forread_in_order_two_level_merge_thresholdandread_in_order_use_virtual_row, and it is absent from everytests/configprofile. Its default is alreadyfalse(Settings.cpp:4199), soper_block = 0is the default state, not a random excursion, and pinning= 1would move the control off the default path. -
The preliminary merge never fires in this fixture.
need_preliminary_mergedoes become true (2 parts > 1,ReadFromMergeTree.cpp:1485), but the insertion is guarded bypipe.numOutputPorts() > 1inmerge_streams(:1714), applied per-pipe at:1745-1746. Each part's pipe has one output port, so noMergingSortedTransformis added insideReadFromMergeTree.EXPLAIN PIPELINEatthreshold=0andthreshold=1shows the only merge is the downstream(Sorting)step, with bothVirtualRowTransforms below it under(ReadFromMergeTree). Invariant acrossmax_threads1/4/16. -
per_blockcannot affect the FINAL arm anyway: the guard at:3323returns beforevirtual_row_conversionis assigned, so it is null on a FINAL query and line 1488's early-out is unreachable there.
Both-directions oracle, mutation = dropping isQueryWithFinal() || from the guard, Build ID verified moving on each transition (base 6595c1a5, mutated 92277a40):
| binary | configurations | result |
|---|---|---|
| mutated | threshold {0,1,2,53,100} x per_block {0,1} |
10/10 red |
| mutated | neither setting forced | red |
| mutated | threshold {0,1,100} x max_threads {1,2,8} x max_block_size {8192,69848} |
18/18 red |
| base | threshold {0,1,100} x per_block {0,1} |
6/6 green |
29 mutated configurations, no vacuous state. clickhouse-test on the mutated build also failed on its own, having drawn --read_in_order_two_level_merge_threshold 53.
Evaluated the two suggested pins separately rather than as a pair. No change made. Source is byte-identical to the published head.
CI finish ledger - 2b6c5beCI is fully finished on this head and there are no failing checks. 176 check-runs, 0 incomplete This supersedes the earlier ledger covering
Session id: cron:our-pr-ci-monitor:20260812-153000 |
Related: #101781
Related: #101750
Related: #103984
Related: #108884
Related: #108815
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Re-files four of the seven MergeTree/index coverage tests @ zlareb1 asked me to pick up on
#101781. Tests only, no production code. Each pins a guard no existing test observes:
04489_part_starting_offset_in_subquery- a_part_starting_offset + _part_offsetpredicate written as
IN(subquery and literal list) must still prune marks. Existingtests cover equality and ranges. (Add test: No test for _part_starting_offset + _part_offset IN subquery (query-then-fetch) or range conditions #101750)
04489_virtual_row_disabled_with_final-SELECT ... FINALmust not lose rows when theread-in-order virtual row is enabled. (Add test: FINAL-disable guard for virtual row optimization untested with
SELECT FROM ... FINAL#103984)04489_aggregation_in_order_limit_with_ties-LIMIT n WITH TIESmust not be pushedinto aggregation-in-order, which would truncate the tie group. (Add test:
LIMIT ... WITH TIESguard inoptimizeLimitForAggregationInOrderis untested #108884)04401_low_cardinality_fixed_string_partition_pruninggains two rows for aStringliteral too long for a
LowCardinality(FixedString)key: no pruning condition may bebuilt, and the result stays correct. Extends my existing test instead of adding a
near-duplicate file. (Add test: Non-fitting
Stringliteral vsLowCardinality(FixedString)functional key: NULL-found bail-out (KeyCondition.cpp:2054) untested #108815)I adopted each test only after proving it observes its branch: inject a regression at the
cited line, rebuild, require the test to fail, then revert and require it to pass. All four
reddened, each with a positive and a negative control.
04489_virtual_row_disabled_with_finalinitially did not: instrumentation showed the guard was never reached, because the outer
count()eliminated the subquery'sORDER BYand the plan had no sorting step. I repairedthe query shape so the read-in-order plan is built; it then reddens. Validation: 200
randomized runs and 200 with randomization off, no failures, also run 8-way concurrently.
I am not filing the other three: #101724's oracle is satisfied by a type error raised
upstream of the guard it claims to cover, so it would pass with that guard deleted;
#103889's disk combination is already exercised by
tests/integration/test_attach_backup_from_s3_plain/test.py; #103893 duplicates03203_count_with_non_deterministic_function.sql, which is the guard's own regression testand asserts more precisely. I am posting these reasons on those PRs.
Version info
26.8.1.1283(included in26.8and later)