Repository navigation
Conversation
When progress is rendered on a different file descriptor than data output (e.g. progress on stderr, data on stdout), there is no need to clear the progress bar before each data block. The clear causes visible flicker when piping because the progress bar is rapidly shown and hidden even though it doesn't interfere with the data output on a separate fd. Skip the progress bar clear in onData() when tty_buf's fd differs from stdout_fd. This preserves the clear when both share the same fd (interactive mode) where it's needed to prevent overlap. Fixes ClickHouse#80056
The previous check compared tty_buf->getFD() with stdout_fd, but in normal interactive mode tty_buf uses stderr_fd (preferred when stderr_is_a_tty) while stdout_fd is a different number — even though both point to the same terminal. This would cause progress and data to overlap in interactive mode (regression). Use stdout_is_a_tty instead: when stdout is a tty, progress and data share the same terminal so clearing is needed. When stdout is piped (not a tty), progress goes to a different terminal and clearing is unnecessary.
When isEmbeeddedClient() is true and stdout_is_a_tty is false, tty_buf still uses stdout_fd — progress and data share the same output stream. The previous check (stdout_is_a_tty only) would skip clearing in this case, causing garbled output. New condition: clear progress when stdout is a tty OR when tty_buf's fd matches stdout_fd (embedded client sharing stdout).
Member
|
Fixed in #93298 |
shevlfs
added a commit
to shevlfs/ClickHouse
that referenced
this pull request
Aug 30, 2026
The client cleared the progress bar (rendered on the terminal via `tty_buf`) before flushing every data block, even when the result was written to a pipe or a file where it cannot interleave with the progress rendering. For fast streaming queries such as `clickhouse --progress -q 'SELECT * FROM system.numbers' | ...` this erased and redrew the bar hundreds of times per second, so the bar was invisible most of the time. Skip the clearing in the pre-flush callback of `std_out_wrapper` when the data cannot interleave with the progress rendering: keep it when stdout is a terminal, when the output goes into a pager, or for a client embedded into the server, where the data and the progress share one stream. Measured with a pty harness (stderr on a pty, stdout piped to /dev/null) on `SELECT * FROM system.numbers LIMIT 30000000`: before, 459 erase sequences for 471 progress redraws in one run; after, 1 erase sequence (the final cleanup) for 465 redraws. When stdout is the terminal, the clearing is preserved: one erase per flushed data block, as before. A similar approach was earlier proposed in PR ClickHouse#98993. Closes: ClickHouse#80056
shevlfs
added a commit
to shevlfs/ClickHouse
that referenced
this pull request
Aug 30, 2026
Follow-up to the previous commit for issue ClickHouse#80056. Skipping the clearing of the progress bar before flushing a data block is only valid when the progress is rendered on a real terminal while the data goes elsewhere. With `--progress err ... 2>&1 | viewer` the progress goes into the same pipe as the data even though stdout is not a terminal, and without the clearing the first row of every flushed block is appended to a stale progress-bar line: 19 garbled lines per 200000 rows (20 blocks) in a harness, versus 0 on master. Extend the condition: skip the clearing only when the progress target is a real terminal (`isatty` on the `tty_buf` descriptor); `initTTYBuffer` runs at startup, so the descriptor is available when the output format is initialized. Why ClickHouse#93298 alone did not fix issue ClickHouse#80056: it moved the clearing into the pre-flush callback of `std_out_wrapper`, so formats that buffer the whole result stopped flickering (`Hash` and `Pretty`: 1 erase sequence per query on master), but formats that flush every block (the streaming formats with `setAutoFlush`) still cleared the bar once per block: 30 erase sequences for a 30-block `TSV` query on master, and 459 erase sequences for 471 progress redraws in a 0.66 s run of `SELECT * FROM system.numbers LIMIT 30000000` with stdout piped to /dev/null. With this fix the same runs show 1 erase sequence (the final cleanup) and a stable bar, while the merged-stream case above, the terminal case (stdout on the terminal), and the pager case keep one clear per flushed block exactly as master does. Also align with the file style (`pager_cmd` instead of `pager_cmd != nullptr`) and improve the test: trap-based cleanup of the generated helper, a 60 s read timeout instead of 300 s, and a third deterministic case pinning the merged-stream `--progress err 2>&1` behavior (the assertions count erase sequences per flushed block, so they do not depend on timing). Related: ClickHouse#80056 Related: ClickHouse#93298 Related: ClickHouse#98993
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.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed progress bar flickering when piping output through another command with
--progressenabled.Documentation entry for user-facing changes
What this PR does
When piping ClickHouse output through another process, the progress bar flickers rapidly:
Root cause
onData()clears the progress bar before every data block output (line 550). When progress is rendered on stderr but data goes to stdout (common when piping), they use different file descriptors and don't visually interfere. The unnecessary clear causes visible flicker as the progress bar is rapidly shown and hidden.The code even has a comment acknowledging this: "If results are written INTO OUTFILE, we can avoid clearing progress to avoid flicker." — the same optimization was missing for the pipe case.
Fix (6 insertions, 1 file)
Skip the progress bar clear in
onData()whentty_buf->getFD() != stdout_fd— meaning progress and data output use different file descriptors. When they share the same fd (interactive mode), the clear is still performed to prevent overlap.Not changed
Other
clearProgressOutputcall sites (onLogData, onEndOfStream, onProfileEvents, etc.) are left untouched because:onLogData: logs go to stderr where progress also lives — clear IS neededFixes #80056
Note
Low Risk
Low-risk client-side UI change that only adjusts when progress output is cleared based on file descriptors; main risk is minor progress rendering regressions in unusual tty/embedded setups.
Overview
Fixes progress bar/table flicker in
ClientBase::onData()by skipping the per-block progress clear when progress output is on a different file descriptor than query results (e.g. progress onstderrwhile data streams tostdoutduring piping).Clearing still happens when
stdoutis a TTY or when the progress buffer sharesstdout_fd(embedded client), preserving overlap protection in interactive/shared-fd scenarios.Written by Cursor Bugbot for commit 1ed7e4f. This will update automatically on new commits. Configure here.