Skip to content

Fix progress bar flicker when the output is redirected - #123549

Merged
alexey-milovidov merged 1 commit into
masterfrom
fix-progress-flicker-piped-output
Oct 3, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
fix-progress-flicker-piped-output

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

When the output of clickhouse-client or clickhouse-local is redirected (e.g. clickhouse-local --progress -q "SELECT * FROM system.numbers" | clickhouse-local ...), the data never mixes with the progress bar on the terminal, but the flush callback of stdout still cleared the progress bar before writing every block, and it was redrawn after the block. As a result, the progress bar flickered and was mostly invisible.

Now the progress bar and the progress table are cleared on flush only if stdout is a terminal or a pager is used. The progress is redrawn in place after every block, as before.

Closes: #80056

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

The progress bar in clickhouse-client and clickhouse-local no longer flickers when the query result is redirected to a pipe or a file.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.10.1.1367-master (included in 26.10 and later)

@mintlify

mintlify Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
ClickHouse-docs 🟢 Ready View Preview Oct 2, 2026, 4:47 PM

@clickhouse-gh

clickhouse-gh Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [12e288f]

Summary: ✅


AI Review

Summary

This PR narrows the clickhouse-client / clickhouse-local flush callback so progress is cleared only when stdout itself is a terminal or a pager is active, and it adds a stateless shell test for redirected output. The regular-file / /dev/null case looks addressed, but the new stdout_is_a_tty gate regresses ordinary pipelines whose reader prints the result back to the same terminal: the progress is no longer cleared before those bytes reach the terminal, so the progress output can interleave with query results again.

Findings

⚠️ Majors

  • [src/Client/ClientBase.cpp:1007] The new output_goes_to_terminal = stdout_is_a_tty || !pager.empty() check treats every pipe as “not shown on the terminal”, but that is not true for common pipelines such as | cat or | tee, or any downstream tool that forwards the query result to the same terminal that tty_buf uses (stderr / /dev/tty). In those cases the flush callback no longer clears the progress before the next block is emitted, so the progress bar / progress table can overlap with forwarded result output again. Keep the clear-on-flush behavior for generic pipes, or narrow the optimization to sinks that provably cannot resurface on the same TTY.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: do not treat generic pipes as terminal-free sinks; either keep clearing for pipe-backed stdout, or narrow the optimization to regular files / similarly non-displayable sinks and cover the intended behavior with a focused pipeline test.

LLVM Coverage Report

Measured on commit 12e288f.

Metric Baseline Current Δ
Lines 88.10% 88.10% +0.00%
Functions 91.80% 91.70% -0.10%
Branches 79.50% 79.50% +0.00%

Changed lines: Changed C/C++ lines covered: 12/12 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Oct 2, 2026
Comment thread src/Storages/StorageDistributed.cpp Resolved
@alesapin

alesapin commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

> This PR currently does much more than the title/body suggest: besides the clickhouse-client progress-bar fix, it adds data-change-aware query-cache / REFRESH ... IF CHANGED plumbing and new modification_hash implementations across several storage engines.

Agree with bot, this PR consists of random unrelated changes.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 This branch was accidentally created on top of #108721, so the PR carried all of its changes. Commit 2ef8490 restores everything except the progress bar fix (src/Client/ClientBase.cpp and test 05317_progress_no_flicker_on_redirected_output) to master. The failed Docs check (Mintlify) and the unresolved AI review threads (RefreshTask.cpp, StorageDistributed.cpp, QueryResultCache.cpp) are about that removed code and belong to #108721.

…minal

When the output of `clickhouse-client` or `clickhouse-local` is redirected
(e.g. piped into another command), the data never mixes with the progress
bar on the terminal, but the progress bar was still cleared before writing
every block and redrawn after it, so it flickered and was mostly invisible.

Clear the progress only if stdout is a terminal or a pager is used.

#80056

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov
alexey-milovidov force-pushed the fix-progress-flicker-piped-output branch from 2ef8490 to 12e288f Compare October 2, 2026 16:03

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Oct 2, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-cli clickhouse-client (interactive CLI) and client library. label Oct 2, 2026
Comment thread src/Client/ClientBase.cpp
/// The data written to stdout can mix with the progress only if it is displayed on the terminal,
/// either directly or through a pager. Otherwise (e.g., stdout is redirected to a pipe or a file),
/// clearing the progress on every flush only makes it flicker.
const bool output_goes_to_terminal = stdout_is_a_tty || !pager.empty();

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.

The new stdout_is_a_tty || !pager.empty() gate treats every pipe as “not shown on the terminal”, but that is not true for common pipelines like clickhouse-client ... | cat / | tee, where the downstream process forwards the query result right back to the same terminal that tty_buf uses (stderr / /dev/tty). In those cases the flush callback no longer clears the progress before the next block is emitted, so the progress bar / progress table can interleave with forwarded result output again.

This optimization seems safe only for sinks that provably cannot resurface on the same TTY (regular files, /dev/null, etc.), not for generic pipes.

@clickhouse-gh

clickhouse-gh Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 12e288f35 with master ca1dbe542 (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, 16 s compile time in total, 7 of them have a recent master baseline.

Job report

@alexey-milovidov

Copy link
Copy Markdown
Member Author

The problem fixed 🎉 🎉 🎉

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 2, 2026
Merged via the queue into master with commit 9477add Oct 3, 2026
149 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-progress-flicker-piped-output branch October 3, 2026 01:09
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 3, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

@alexey-milovidov — ClickGap found the following in this PR:

Close anything that's wrong or already addressed.

valerypetrov added a commit to valerypetrov/ClickHouse that referenced this pull request Oct 3, 2026
…ress

Master's client progress rework (ClickHouse#118536, ClickHouse#123549) moved the CPU, memory
and temp-disk reads of `writeProgress` into one `getProfileSnapshot()` call
under `profile_events_mutex` and added a "waited" meter. The IO rate now
comes from the same snapshot (`ProfileSnapshot::io_rate`), so it is read
together with the other values, and the IO counters are summed next to the
other `INCREMENT` rows in `ClientBase::onProfileEvents`.

The Web UI notebook mode (ClickHouse#115378) moved the resource-meter state from the
tab to the cell, so both `payloadMeter` callbacks now add to
`cell.resources`. Left as merged, the live one would read `tab.resources`,
which no longer exists, and throw on the first result packet. 04548 greps
the new spelling and keeps master's new checks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
valerypetrov added a commit to valerypetrov/ClickHouse that referenced this pull request Oct 3, 2026
…ground-queries

Master's client progress rework (ClickHouse#118536, ClickHouse#123549) replaced the private
`getCPUUsage()` with one `getProfileSnapshot()` for `writeProgress` and added
a "waited" meter. Background jobs still read the current CPU rate, so the
public `getCPUUsage()` is kept beside `getAverageCPUUsage()`, and the
per-host CPU totals keep accumulating next to master's waited sum.

The flush callback now clears the progress only when the output reaches the
terminal (master), and still checks `tty_buf` under `tty_mutex` (this branch),
because a detached job can swap the output while a query runs.

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

This branch was successfully deployed

1 active deployment
staging - docs — 12e288f3 Deployed Oct 2, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-cli clickhouse-client (interactive CLI) and client library. pr-improvement Pull request with some product improvements 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.

Progress bar flickers if a command line tool outputs a lot of data

4 participants