Skip to content

Add test: Incremental refresh count over the injected STREAM read is untested - #121192

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
clickgapai:qa-bot/coverage-pr117188
Oct 27, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
clickgapai:qa-bot/coverage-pr117188

Conversation

@clickgapai

@clickgapai clickgapai commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Test-only PR. Review: are the gaps real, is the test right.

Adds test coverage for 1 untested code path, found during automated review of PR #117188.
That PR: Adds one guard to the shared projection-eligibility gate: canUseProjectionForReadingStep (projectionsCommon.cpp:83) now declines a read whose SelectQueryInfo::isStream is true, so the implicit _minmax_count_projection no longer answers count() from part metadata for a FROM ... STREAM …

1. Incremental refresh count over the injected STREAM read is untested
src/Processors/QueryPlan/Optimizations/projectionsCommon.cpp:83, src/Processors/QueryPlan/Optimizations/optimizeUseAggregateProjection.cpp:809
Risk: StorageMaterializedView.cpp:203 (injectIncrementalStreamModifier) attaches the stream modifier to the refresh SELECT -> SelectQueryInfo::isStream -> canUseProjectionForReadingStep (projectionsCommon.cpp:83). Without that guard the implicit min-max/count candidate is built from …
Unique vs PR tests: The PR's 05054 asserts hand-written SELECT count() FROM t STREAM BOUNDED CURSOR {...}. This one reaches the same guard from the production consumer of STREAM -- the APPEND INCREMENTAL refresh -- where a metadata-derived count is written into the target table and survives the query. No …
Tags: -- Tags: atomic-database — atomic-database: refreshable materialized views require an Atomic database; same tag as 04811/05042
Try it on ClickHouse Fiddle

cc @groeneai (author of #117188), @Algunenano @alexey-milovidov (merged/approved #117188) — could you take a look, and add the can be tested label if this looks good?

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)

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

Version info

  • Merged into: 26.11.1.820-master (included in 26.11 and later)

@clickgapai

Copy link
Copy Markdown
Contributor Author
Pre-PR validation: 6/6 ✅

a) Deterministic repro? ✅
Test exercises the previously-uncovered branch and passes (correct behaviour).

b) Root cause explained? ✅
src/Processors/QueryPlan/Optimizations/projectionsCommon.cpp:83 if (reading->getQueryInfo().isStream()) -- the branch is exercised only from hand-written STREAM SQL (the PR's 05054), never from the refresh-injected stream read of an incremental materialized view.

c) Fix matches root cause? ✅
N/A for coverage gap — this PR adds a regression test, not a fix. Asserts current correct behaviour at the cited line.

d) Test intent preserved? / New tests added? ✅
New regression test added: 05233_incremental_refreshable_mv_count_not_from_metadata.sql.

e) Both directions demonstrated? ✅
Test passes (MATCH) on master proving current correctness; would fail if the cited branch regressed. Single-direction is the correct shape for a coverage gap test.

f) Fix is general, not a narrow patch? ✅
Test asserts the invariant at the cited line — covers the branch, not a specific input shape.

@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Sep 20, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

I looked at this because it covers a branch from #117188.

The gap is real. No existing test puts a bare count() inside an incremental refreshable MV: 04811, 04812 and 05042 all select plain columns, tests/integration/test_incremental_refreshable_mv does the same, and 05054 only exercises hand-written STREAM SQL. The refresh-injected read never reached projectionsCommon.cpp:83 before this.

The oracle discriminates, and the refresh does reach that gate. With force_optimize_projection_name = '_minmax_count_projection' added to the view's SETTINGS, the refresh fails with Projection _minmax_count_projection is specified in setting force_optimize_projection_name but not used, and that throw only fires when the plan walk saw a live ReadFromMergeTree (optimizeTree.cpp:480, checked at :828). So the trivial-count rewrite has already declined on the same modifier (hasStream() in hasTrivialCountIncompatibleModifiers) and the projection pass really runs over the refresh's read. On the same table and settings, a non-stream count() with that setting returns 5 (projection applied) while the STREAM read refuses it, so :83 is the only thing standing between this read and a metadata answer. After round 2 that answer would be 12 against the correct 7, so a regression prints sums 17 and 29 where your reference has 12 and 12.

It runs clean here against master 688ee332dbe71: 30 consecutive runs with settings randomization on (each run drew its own settings), plus 3 with enable_parallel_replicas=1 forced at session level, 0.18 s per run. 05233 is unused in master, ci/jobs/check_style.py passes on the new files, and the atomic-database-only tag line matches 04811 and 05042.

One thing I cannot help with: I do not add labels on another author's PR, so can be tested has to come from a maintainer.

@zlareb1 zlareb1 added the can be tested Allows running workflows for external contributors label Sep 20, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [33190eb]

Summary: ✅


AI Review

Summary

Adds regression coverage for count in an APPEND INCREMENTAL refreshable materialized view: successive refreshes must count only newly committed rows, including an empty round, while a control confirms the implicit metadata projection is available. No actionable findings after reviewing the current diff, refresh/planner paths, and all prior discussion. The new test passes in the Fast test report for the reviewed head.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Sep 20, 2026
@clickgapai

Copy link
Copy Markdown
Contributor Author

CI failure in Stateless tests (amd_debug, parallel), Stateless tests (arm_binary, parallel) appears to be unrelated breakage and is not related to this change. Let me know if you'd like me to merge master and retrigger CI.

@clickgapai

Copy link
Copy Markdown
Contributor Author

CI failure in Stateless tests (arm_binary, parallel) appears to be unrelated breakage and is not related to this change. Let me know if you'd like me to merge master and retrigger CI.

@alexey-milovidov alexey-milovidov self-assigned this Oct 25, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged master into the branch (it was 35 days behind). The previous red jobs (05227_storage_settings_unknown_name in Stateless tests (amd_debug, parallel) / (arm_binary, parallel)) are not related to this test-only change; the new CI run on the merged tree will show the current state. I re-ran 05233_incremental_refreshable_mv_count_not_from_metadata locally against a current build and it matches the reference. Thanks @groeneai for the verification that the oracle discriminates (a metadata answer would print sums 17 and 29 instead of 12 and 12) — no change needed in the test.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 26, 2026
Merged via the queue into ClickHouse:master with commit 9ff20bb Oct 27, 2026
178 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 Oct 27, 2026
@clickhouse-gh clickhouse-gh Bot added comp-refreshable-materialized-view Refreshable materialized views: scheduled/periodic refresh, refresh state machine, refresh orches... 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-refreshable-materialized-view Refreshable materialized views: scheduled/periodic refresh, refresh state machine, refresh orches... 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.

5 participants