Repository navigation
feat: add row-based automatic flushing for native batches - #2193
Open
xuzijie990329-boop wants to merge 3 commits into
Open
xuzijie990329-boop wants to merge 3 commits into
xuzijie990329-boop wants to merge 3 commits into
Conversation
xuzijie990329-boop
requested review from
a team,
kavirajk and
polyglotAI-bot
as code owners
November 30, 2026 11:53
Contributor
AI review gate — AI review passedClean review from: Cursor Bugbot. |
xuzijie990329-boop
force-pushed
the
batch-flush-interval-rows
branch
from
November 30, 2026 12:10
0e56cc8 to
b04416e
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 9a926cf. Configure here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Add an opt-in
driver.WithFlushIntervalRows(n)option for native batches.Large INSERT batches currently buffer all rows before
Send. WideStringandMapcolumns can require several times the input size during column encodingand compression.
MaxCompressionBuffercannot reliably bound this because itssize check runs after a complete column has been encoded.
This change reuses
Batch.Flushto emit a block every N appended rows whilekeeping the INSERT open until
Send. The default is zero, preserving existingbehavior. HTTP batch behavior is unchanged.
This is a row-based, backward-compatible step toward #809. It does not attempt
byte-accurate buffering or change the column encoding pipeline. A single large
value or map can still exceed the intended memory budget.
Related to #809 and #1384.
Compatibility
WithCloseOnFlushis rejected when combined with this option to avoidaccidentally finalizing the INSERT at an interval boundary.
Tests
Map,LowCardinality, andArray(Map)round-trip comparisonsWithReleaseConnectioncompatibilityValidation
go test ./... -run '^$' -count=1passedgo vet ./lib/driverpassedgo test -race -count=1 -v ./tests/issues -run TestBatchFlushIntervalRowsnot yet run locally; requires a running ClickHouse instance
Checklist
Note
Medium Risk
Changes native batch INSERT buffering and connection lifecycle on interval flush; mistakes could affect data integrity or resource handling, though behavior is opt-in and guarded by validation and tests.
Overview
Adds opt-in
driver.WithFlushIntervalRows(n)so nativePrepareBatchinserts canFlushevery N appended rows while the INSERT stays open untilSend, reducing peak memory from buffering wide columns without changing default behavior (0 = disabled; HTTP still ignores flush).PrepareBatchnow validates options up front: negative intervals error, andWithFlushIntervalRowscannot be used withWithCloseOnFlush. The batch stores the interval andAppendcalls a newautoFlushpath that reacquires the connection when needed, arms the same context watchdog used elsewhere, then flushes; failed auto-flush leaves the batch unusable per the new docs.Integration tests in
tests/issues/809_test.gocover multi-block inserts, tail blocks, complex types,WithReleaseConnection, disabled interval, canceled context, and invalid option combinations.Reviewed by Cursor Bugbot for commit 1c181e3. Bugbot is set up for automated code reviews on this repo. Configure here.