Skip to content

Accept only MergeTree sources for an incremental refresh - #131814

Merged
alexey-milovidov merged 1 commit into
masterfrom
stream-incremental-refresh-merge-tree-only
Nov 17, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
stream-incremental-refresh-merge-tree-only

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

An incremental refresh of a refreshable materialized view (APPEND INCREMENTAL) resumes from the cursor that the read reports through Context::getStreamingCursor, and only a MergeTree read reports it. The source was required only to support STREAM, which was true just for MergeTree tables. With STREAM support for other engines (the PRs below), a source of such an engine would be read from the beginning on every refresh, appending the same rows again. This PR rejects such sources, and explains in Context.h that StreamingCursor exists only for the incremental refresh and other streaming queries must not rely on it (per the review of the first version).

The engine PRs are based on this commit, and each of them tests the rejection for its engine:

Related: #42990
Related: #131769

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

🤖 Generated with Claude Code


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

Version info

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

An incremental refresh (`APPEND INCREMENTAL`) resumes from the cursor that the
read reports through `Context::getStreamingCursor`, and only a `MergeTree` read
reports it. When other engines support `STREAM`, a source of such an engine
would be read from the beginning on every refresh, appending the same rows again.
Reject it, and explain in `Context.h` that `StreamingCursor` exists only for the
incremental refresh.

Related: #42990
Related: #131769

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [22109b8]

Summary: ✅


AI Review

Summary

Restricts APPEND INCREMENTAL sources to MergeTree engines that report the refresh cursor, and documents the purpose of StreamingCursor. No new actionable findings. The pre-existing cursor rewind when a read ends early remains tracked in ClickHouse/ClickHouse#120081; this engine restriction does not introduce it.

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 Nov 15, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

We will support incremental refresh from Merge, Distributed, as well as from all streaming table engines, would we?

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Because this is one of the goals of #42990 - infinite and consistent consumption from a stream with the possibility to insert into another table of a stream.

@clickhouse-gh clickhouse-gh Bot added the comp-refreshable-materialized-view Refreshable materialized views: scheduled/periodic refresh, refresh state machine, refresh orches... label Nov 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 22109b852 with master d011c6b84 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

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

Job report

@alexey-milovidov
alexey-milovidov marked this pull request as ready for review November 16, 2026 16:41

@clickhouse-gh clickhouse-gh Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review approves this commit, see the AI Review comment.

@alexey-milovidov alexey-milovidov self-assigned this Nov 16, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 16, 2026
alexey-milovidov added a commit that referenced this pull request Nov 16, 2026
A bounded streaming read of a `FileLog` table reports the offsets it read up to
through the holder of an incremental refresh, with the inode of every file
(`{file: {offset, inode}}`), so a `FileLog` table can be the source of an
incremental refresh. A file replaced by another one with the same name or
truncated since the cursor was taken is read from the beginning.

Related: #131814 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Nov 16, 2026
For an incremental refresh from a `Distributed` table, the initiator sets the
internal setting `report_streaming_cursor` for the shards. A shard then creates
the holder of the cursor for the query and sends the cursor its bounded
streaming read advanced to in the new `StreamingCursor` server packet (protocol
version 54497) before `EndOfStream`. The initiator keeps the cursors under the
shard numbers, and fails if a shard does not send one. A local shard, including
the local fallback of a lazy remote shard, reports through a child holder under
the shard number. A streaming read for an incremental refresh of a table that
does not report the cursor is refused by the analyzer, e.g. on a shard.

`MultiplexedConnections` and `HedgedConnections` pass the new packet through;
the native protocol spec describes it.

Related: #131814 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Nov 16, 2026
A bounded streaming read of a `Kafka` table reports the offsets it read up to
through the holder of an incremental refresh, so a `Kafka` table can be the
source of an incremental refresh, which resumes every refresh from them without
a consumer group.

Related: #131814 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Nov 16, 2026
A bounded read of every table of a `Merge` table reports its cursor under the
database and the table through a child holder, so a `Merge` table can be the
source of an incremental refresh. A table that does not report the cursor is
refused on every refresh, as the matching tables may change. The cursor of a
table with dots in the database or the table name is found by the parts of the
name, as the cursor tree splits the keys by dots.

Related: #131814 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Nov 16, 2026
A bounded streaming read of a `NATS` table with `nats_stream` reports the stream
sequence it read up to through the holder of an incremental refresh, so such a
table can be the source of an incremental refresh.

Related: #131814 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Nov 16, 2026
A bounded streaming read of a `RabbitMQ` table with stream queues reports the
offsets it read up to through the holder of an incremental refresh, so such a
table can be the source of an incremental refresh; a message that arrives after
the end of a bounded read is appended by the next refresh.

Related: #131814 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Nov 16, 2026
A streaming read of a `Memory` table accepts a cursor
`{epoch, generation, block_number}`, and a bounded read reports it through the
holder of an incremental refresh, so a `Memory` table can be the source of an
incremental refresh. The epoch is a random number of the server process, as the
generations of the data are numbered anew in every process. A cursor of another
process or of a generation that started empty (`TRUNCATE`) means that all the
blocks are new; a generation that a mutation rewrote cannot be resumed after a
position in a previous one, so the refresh fails.

Related: #131814 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Yes. This PR is in the merge queue as it is (it only refuses the sources that cannot resume yet). The rest is in #132145, which replaces the MergeTree-only check with a capability IStorage::reportsStreamingCursor, plus the engine PRs that implement it, each with a test of incremental refresh:

Null stores nothing, so it stays refused.

Merged via the queue into master with commit 81c9f07 Nov 17, 2026
567 of 570 checks passed
@alexey-milovidov
alexey-milovidov deleted the stream-incremental-refresh-merge-tree-only branch November 17, 2026 02:57
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants