Skip to content

Client: keep pasted multi-line query under a single prompt - #104299

Merged
alexey-milovidov merged 19 commits into
masterfrom
client-paste-newline
Jun 7, 2026
Merged

alexey-milovidov merged 19 commits into
masterfrom
client-paste-newline

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented May 7, 2026 •

Copy link
Copy Markdown
Member

When a multi-line query is pasted into clickhouse-client in a terminal that does not deliver bracketed-paste escape sequences (older terminals, some SSH/tmux setups, certain IDE consoles), every embedded newline arrives as a regular Enter event. The previous behavior committed each partial line and switched to the :-] continuation prompt for the next, so the paste was scattered across several prompts, history was littered with line fragments, and arrow-key navigation across the statement was lost.

This change folds those embedded newlines into the same replxx edit buffer when more bytes are still queued in the TTY (i.e. the paste is in progress), regardless of whether --multiline is set. With replxx in raw mode all paste bytes from a typical paste are buffered by the kernel TTY at once, so a non-blocking poll for pending input is a best-effort signal that distinguishes paste-in-progress from a deliberate Enter press. With bracketed paste enabled this code path is not invoked at all (replxx absorbs embedded newlines internally), so the existing behavior is preserved.

The continuation prompt is intentionally still used in the genuinely interactive cases — backslash extender (SELECT ...\<Enter>) and explicit --multiline mode without queued data — and those are covered by 01293_client_interactive_vertical_multiline.expect.

A deterministic regression test is not feasible: without bracketed paste, the distinction between "paste in progress" and "user pressed Enter quickly" is fundamentally timing-based, and any pty-driven test depends on TTY scheduling that varies across CI runners.

Changelog category (leave one):

  • Improvement

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

In clickhouse-client, when the terminal does not support bracketed paste, embedded newlines from a pasted multi-line query are now folded into the same edit buffer instead of switching to the continuation prompt for every line. The pasted query stays under a single prompt and the arrow keys navigate across its lines. This is a best-effort improvement that relies on the typical TTY-buffered paste behavior.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Note

Medium Risk
Touches interactive line-commit behavior and low-level TTY readiness checks (poll), which can subtly affect when queries are committed across terminals and platforms.

Overview
Keeps pasted multi-line queries under a single prompt/edit buffer in clickhouse-client when bracketed paste is unavailable by treating embedded newlines as NEW_LINE while more input is queued.

Replaces the input-readiness probe in LineReader::hasInputData() from select() to a non-blocking poll() check, and uses hasInputData() in ReplxxLineReader’s Enter/commit handler to decide between inserting a newline vs committing the line.

Reviewed by Cursor Bugbot for commit 42a73ab. Bugbot is set up for automated code reviews on this repo. Configure here.

Version info

  • Merged into: 26.6.1.469

When a multi-line query was pasted into clickhouse-client in a terminal
that did not deliver bracketed-paste escape sequences (older terminals,
some SSH/tmux setups, certain IDE consoles), every embedded newline was
treated as a regular Enter event. The Enter handler called COMMIT_LINE,
so the partial query was returned to the outer continuation loop and
each subsequent line was rendered under the ":-]" continuation prompt.
The paste therefore appeared scattered across several prompts, history
was littered with line fragments, and arrow-key navigation across it was
lost.

Fold those embedded newlines into the same replxx edit buffer when more
bytes are still queued in the TTY (i.e. the paste is in progress),
regardless of whether `--multiline` is set. With replxx in raw mode all
paste bytes are buffered by the kernel TTY at once, so the pending-byte
check via a non-blocking select reliably distinguishes paste-in-progress
from a deliberate Enter press. With bracketed paste enabled this code
path is not invoked at all (replxx absorbs embedded newlines internally),
so existing behavior is preserved.

The continuation prompt is still used in the genuinely interactive
cases - backslash extender and explicit `--multiline` mode without
queued data - and those are covered by the existing tests.
@clickhouse-gh

clickhouse-gh Bot commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [008e9fc]

Summary: ✅


AI Review

Summary

This PR keeps non-bracketed pasted multi-line input in a single replxx edit buffer when queued TTY input suggests a paste is still in progress. The approach is appropriately described as best-effort, but the implementation currently only applies when syntax highlighting is enabled, so a supported display setting still gets the old continuation-prompt behavior.

Findings

⚠️ Majors

  • [src/Client/ReplxxLineReader.cpp:383] The new queued-input paste path is gated by highlighter, so clickhouse-client --highlight 0 never takes the new NEW_LINE branch. In that supported mode, non-bracketed pasted newlines still take COMMIT_LINE and fall back to the old :-] continuation loop, while the PR/changelog promises the pasted query stays under one prompt.
    Suggested fix: decouple the paste-in-progress branch from the syntax-highlighting callback, or narrow the user-facing wording to explicitly say this best-effort behavior only applies when syntax highlighting is enabled.
Final Verdict

Status: ⚠️ Request changes

Minimum required action: fix the --highlight 0 behavior gap or narrow the PR/changelog contract so it does not promise the single-prompt behavior in that supported mode.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label May 7, 2026
@alexey-milovidov
alexey-milovidov requested a review from azat May 7, 2026 13:28
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Tested manually.

Old:

milovidov@milovidov-pc:~/work/ClickHouse$ ../ClickHouse1/build/programs/clickhouse
ClickHouse local version 26.4.1.1.

:) SELECT 1,
:-] 2,
:-] 3

SELECT
    1,
    2,
    3

Query id: 1d8fd6b4-c1bf-41a1-85cb-26ea77b13ff0

   ┌─1─┬─2─┬─3─┐
1. │ 1 │ 2 │ 3 │
   └───┴───┴───┘

1 row in set. Elapsed: 0.005 sec. 

:) Bye.

New:

milovidov@milovidov-pc:~/work/ClickHouse$ ../ClickHouse/build/programs/clickhouse
ClickHouse local version 26.5.1.1.

:) SELECT 1,
2,
3

SELECT
    1,
    2,
    3

Query id: 0c83f938-a2b3-473a-b862-251a9e68693b

   ┌─1─┬─2─┬─3─┐
1. │ 1 │ 2 │ 3 │
   └───┴───┴───┘

1 row in set. Elapsed: 0.002 sec. 

:)

The 04209_client_paste_without_bracketed_paste expect script asserted
that no ":-]" prompt appears between pasted lines, but in CI replxx
drains the kernel TTY byte-by-byte fast enough that hasInputData()
returns false during commit_action, so the test caught a case where
the underlying patch is a no-op rather than a regression. The fix
itself remains best-effort - it helps in environments where pasted
bytes stay queued in the TTY between reads, and falls back to the
original ":-]" continuation prompt elsewhere. Without a reliable
signal we cannot turn this into a deterministic test, so remove it.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104299&sha=0841f806b9f75808e51b4b0b89fee605fe70420e
Comment thread src/Client/ReplxxLineReader.cpp Resolved
@alexey-milovidov

Copy link
Copy Markdown
Member Author

The PR currently has no deterministic regression test

Not possible.

@azat azat self-assigned this May 7, 2026
Comment thread src/Client/ReplxxLineReader.cpp Resolved
The previous implementation used `select(1, ...)` which only checks file
descriptor 0, so the paste-detection heuristic worked only when `in_fd`
happened to be `STDIN_FILENO`. Switch to `poll` on the actual `in_fd`
so the check works for any descriptor (e.g. SSH or other transports).

Per #104299 (comment)
@alexey-milovidov

Copy link
Copy Markdown
Member Author

@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104299&sha=4c8770c47ae00af15728dff17dddd34f921076bd&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%29 and provide a fix in a separate PR. If the fix is already in progress, link it here.

The AST fuzzer failure Logical error: AggregateFunctionArray: parameters mismatch between Array wrapper 'A' and nested function 'B' originates in AggregateFunctionCombinatorArray::transformAggregateFunction (the timeSeriesDeltaToGridArray combinator) and is unrelated to this PR, which only modifies src/Client/LineReader.cpp and src/Client/ReplxxLineReader.cpp. It matches the open issue #104459.

Comment thread src/Client/ReplxxLineReader.cpp Resolved
@groeneai

Copy link
Copy Markdown
Collaborator

@alexey-milovidov fix is in PR #104769. Per your directive, the AST fuzzer failure on this PR (AggregateFunctionArray: parameters mismatch in AggregateFunctionCombinatorArray::transformAggregateFunction for timeSeriesDeltaToGridArray) is unrelated to your client/parser changes — it is the chronic issue #104459 / STID 4870 family. PR #104769 fixes it at the wrapper layer (the Array combinator now inherits the nested function's parameters), which avoids the backward-compatibility regression that forced the revert of #103428 (#104672).

@alexey-milovidov

Copy link
Copy Markdown
Member Author

@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104299&sha=af067fba3bc6ebb1b269dff7f023bb2697aa1f94&name_0=PR&name_1=Unit%20tests%20%28tsan%2C%20function_prop_fuzzer%29 and provide a fix in a separate PR. If the fix is already in progress, link it here.

The failing test FunctionsStress.stress exercises non-determinism of caseWithExpression (different result when arguments are made const) and is unrelated to this PR's client paste changes.

@groeneai

Copy link
Copy Markdown
Collaborator

@alexey-milovidov fix posted at #104804. The FunctionsStress.stress divergence (caseWithExpression const vs non-const) is a downstream of a real transform bug: transform's cache->default_column was built via convertFieldToType + insert (Field-level), which loses source-column type info, so FixedString defaults kept trailing zeros and Enum defaults turned into their numeric storage -- diverging from castColumn (which cache->to_column already uses). caseWithExpression picks transform when all WHEN/THEN are const and multiIf otherwise, so the stress test's const-randomization flips between paths and exposes the bug. Fix aligns cache->default_column with cache->to_column; verified locally: all 11 assertions of the new regression test pass, 30 s FunctionsStress.stress run reports 0 broken_determinism. Not related to this PR's client paste changes.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104299&sha=5ef2c1bf4ff0d886602fff8f2ab8f6bdd384abc6&name_0=PR&name_1=Stateless%20tests%20%28amd_llvm_coverage%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29 and provide a fix in a separate PR. If the fix is already in progress, link it here.

The 01710_projection_additional_filters test failure is tracked in #104219 and is unrelated to this PR, which only modifies src/Client/LineReader.cpp and src/Client/ReplxxLineReader.cpp.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104299&sha=5ef2c1bf4ff0d886602fff8f2ab8f6bdd384abc6&name_0=PR&name_1=Stress%20test%20%28arm_tsan%29 and provide a fix in a separate PR. If the fix is already in progress, link it here.

The Logical error: Table has no columns. (STID: 3593-560a) failure originates in DB::ReadFromMerge::createChildrenPlans (src/Storages/StorageMerge.cpp:711) and is tracked in #104740. It is unrelated to this PR, which only modifies src/Client/LineReader.cpp and src/Client/ReplxxLineReader.cpp.

@groeneai

Copy link
Copy Markdown
Collaborator

@alexey-milovidov confirmed — this is the chronic Logical error: 'Table has no columns.' family (STID 3593-560a / 3593-5990, tracked in #104740). Unrelated to this PR's LineReader/ReplxxLineReader changes.

Active fix in flight: #104919 by @azat — "Fix LOGICAL_ERROR 'Table has no columns.' on Merge over a dangling Alias" (OPEN, last updated 2026-05-14). Our earlier attempt (#104790) was closed in favor of azat's approach.

No new fix PR from our side; monitoring #104919.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

@groeneai, check what is with 04043_system_asynchronous_inserts_user_filter. Provide a fix.

@groeneai

Copy link
Copy Markdown
Collaborator

@alexey-milovidov, fixed on master by your own commit c9fe327 (2026-05-25 01:06:58 UTC): re-added no-parallel, set async_insert_use_adaptive_busy_timeout = 0, and added a 30s system.asynchronous_inserts visibility-lag poll.

CIDB: 0 master failures in the 32 hours since c9fe327 landed (down from 4 master failures across 2026-05-22 and 2026-05-23).

This PR's CI hit was on commit 420959d (Stateless tests (amd_debug, distributed plan, s3 storage, parallel), 2026-05-25 06:36:49 UTC), which predates c9fe327. A merge from master will clear it. Three other PRs (#105756, #102192, #103786) failed on the same test in the same window for the same reason (stale branches predating the fix).

Closing my in-flight #105687 as superseded.

Session: cron:clickhouse-ci-task-worker:20260526-024500

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Merged master (was 580 commits / 3 days behind and red) — clean merge, no conflicts. The net diff is unchanged: the single 6-line change in ReplxxLineReader.cpp (the LineReader.cpp select→poll hasInputData change already landed in master independently). Verified ReplxxLineReader.cpp compiles cleanly on the merged tree (ARM, RelWithDebInfo).

The two failures on the previous CI run are unrelated to the client paste changes:

  • AST fuzzer (arm_asan_ubsan) — Logical error: 'Unexpected expression in JOIN ON section. Expected boolean (UInt8), got 'Nothing'' (STID 4699-19f1) originates in HashJoin::validateAdditionalFilterExpression, tracked in open issue Logical Error: Unexpected expression in JOIN ON section. Expected boolean (UInt8), got 'Nothing' #78761.
  • Upgrade check (amd_release) — Error message in clickhouse-server.log: a repeated StorageKafka2 ... Exception during get topic partitions from Kafka: Local: Broker transport failure, an infra/Kafka-broker flaky unrelated to LineReader/ReplxxLineReader.

A fresh CI run on the merge commit should clear both.

Comment thread src/Client/ReplxxLineReader.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 39 queries analysed

This PR changes only the interactive command-line input reader (terminal paste handling); it does not touch any server-side query execution path. The ClickBench Q28 -6.26% "improvement" therefore cannot be caused by this change and is reclassified as inconclusive run-to-run variance. The tpch_adapted_1_official Q4 result stays inconclusive as well, with noisy underlying measurements. No real performance impact is attributable to this PR.

clickbench

⚠️ 1 inconclusive

Flagged queries (1 of 43)
Query Verdict Baseline med (ms) PR med (ms) Change q-value Hint
⚠️ 28 not_sure 7072 6629 -6.3% <0.0001 PR only edits CLI line-reader paste handling; cannot affect server-side Q28 execution. Flagged improvement is run-to-run

q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

⚠️ 1 inconclusive

Flagged queries (1 of 22)
Query Verdict Baseline med (ms) PR med (ms) Change q-value Hint
⚠️ 4 not_sure 2492 1857 -25.5% 0.0190 Already not_sure; noisy measurements (CV ~31%) and a CLI-only diff that does not touch query execution.

q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

Debug info
  • StressHouse run: 90df2e36-d954-49c7-8c4d-e7217823a080
  • MIRAI run: 068fdff8-f0d1-4b59-ab5e-5f4dae3d27e3
  • PR check IDs:
    • clickbench_1511_1780638331
    • clickbench_1517_1780638331
    • clickbench_1525_1780638332
    • tpch_adapted_1_official_1540_1780638331
    • tpch_adapted_1_official_1557_1780638331

@clickhouse-gh

clickhouse-gh Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.50% 84.40% -0.10%
Functions 92.40% 92.30% -0.10%
Branches 77.10% 77.00% -0.10%

Changed lines: Changed C/C++ lines covered by tests: 5/5 (100.00%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@alexey-milovidov
alexey-milovidov disabled auto-merge June 7, 2026 02:52
@alexey-milovidov
alexey-milovidov merged commit 0d7dcda into master Jun 7, 2026
165 of 166 checks passed
@alexey-milovidov
alexey-milovidov deleted the client-paste-newline branch June 7, 2026 02:53
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 7, 2026
pull Bot pushed a commit to sowelswl/ClickHouse that referenced this pull request Jun 7, 2026
…hlight 0

Follow-up to ClickHouse#104299. The paste-folding behavior added there was gated on
the `highlighter` callback being present, so with `clickhouse-client
--highlight 0` the `highlighter` is empty, the condition short-circuited,
and every embedded newline of a non-bracketed paste still took
`COMMIT_LINE` and fell back to the `:-]` continuation loop. That made the
single-prompt promise from the changelog hold only in the default
highlighted mode, even though `--highlight` is a display option.

The `NEW_LINE` action in `replxx` only inserts a newline into the edit
buffer (`insert_character('\n')`) and does not use the lexer, so the paste
case does not actually need the highlighter. Decouple it: the
`hasInputData()` paste path now folds embedded newlines regardless of the
highlighter, while the explicit `--multiline` continuation keeps requiring
the highlighter, preserving the previous behavior.

Related: ClickHouse#104299

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

4 participants