Skip to content

Allow multiline queries in clickhouse-benchmarks - #99972

Merged
alexey-milovidov merged 8 commits into
ClickHouse:masterfrom
AVMusorin:clickhouse-benchmark-multiline
May 19, 2026
Merged

alexey-milovidov merged 8 commits into
ClickHouse:masterfrom
AVMusorin:clickhouse-benchmark-multiline

Conversation

@AVMusorin

@AVMusorin AVMusorin commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor

Add --queries-format option to clickhouse-benchmark for choosing how the queries on standard input are interpreted.

Before this change, clickhouse-benchmark always read stdin as one tab-escaped query per line. That works for the original use case (a TSV-formatted file produced by ClickHouse itself) but is awkward for hand-written multi-line queries or for replaying a .sql script.

--queries-format has two values:

  • tsv (default) - one tab-escaped query per line; existing behavior, no change for current users.
  • script - parse stdin as a script of multiple queries separated by ; (using the same splitMultipartQuery logic as clickhouse-client). Multi-line queries are allowed. Limitation: INSERT ... FORMAT queries must be on a single line, as in clickhouse-client.

Changelog category (leave one):

  • Improvement

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

Added --queries-format option to clickhouse-benchmark to choose between the default tab-escaped one-query-per-line input (tsv) and parsing standard input as a script of multiple queries separated by ; (script).

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.5.1.836

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Mar 19, 2026
@clickhouse-gh

clickhouse-gh Bot commented Mar 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [fa2cd1f]

Summary: ✅


AI Review

Summary

This PR introduces --queries-format for clickhouse-benchmark, adding a script mode for semicolon-separated SQL input while keeping tsv as default. The main remaining issue is a user-facing help text inconsistency in Benchmark.cpp that can print an invocation form not valid for standalone clickhouse-benchmark installs; this should be fixed before merge.

Findings

⚠️ Majors

  • [programs/benchmark/Benchmark.cpp:980] --help prints hardcoded clickhouse benchmark usage. mainEntryClickHouseBenchmark is shared by both clickhouse benchmark and standalone clickhouse-benchmark, so this can show users a command that does not exist in their installation. Use argv[0]-based usage text (or print both valid invocation forms) to keep help output correct across entrypoints.
Final Verdict

Status: ⚠️ Request changes

Minimum required action:

  • Fix help/usage text generation so it is correct for both clickhouse benchmark and clickhouse-benchmark entrypoints.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Mar 19, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

.

@alexey-milovidov alexey-milovidov self-assigned this Mar 21, 2026
@alexey-milovidov alexey-milovidov added the close in a month if not active This will be closed in case of no information label Mar 24, 2026
Comment thread programs/benchmark/Benchmark.cpp Resolved
@alexey-milovidov alexey-milovidov removed the close in a month if not active This will be closed in case of no information label Apr 23, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

Ok, but the PR description is still wrong, and I'm concerned about the setting name. It implies that without this option, clickhouse-benchmark can't process multiple queries, which is untrue.

@alexey-milovidov

alexey-milovidov commented Apr 23, 2026 •

Copy link
Copy Markdown
Member

Let's name it --queries-format with two possible values: tsv and script.

@alexey-milovidov alexey-milovidov added the close in a month if not active This will be closed in case of no information label May 10, 2026
Address review feedback on PR ClickHouse#99972: rename the previously added
`-m`, `--multiquery` flag to `--queries-format` with two possible
values:

- `tsv` (default) - one tab-escaped query per line (existing behavior)
- `script`        - parse stdin as a script of queries separated by `;`

The new name better reflects that `clickhouse-benchmark` already
supports multiple queries by default, and only the input *format*
changes.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

Renamed --multiquery / -m to --queries-format with two values: tsv (default, unchanged behavior) and script (parse stdin as a script of queries separated by ;), as suggested. Updated docs, tests, and the PR description accordingly.

if (options.contains("help"))
{
std::cout << "Usage: " << argv[0] << " [options] < queries.txt\n";
std::cout << "Usage: clickhouse benchmark [options] < queries.txt\n";

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.

--help now prints a hardcoded clickhouse benchmark command. mainEntryClickHouseBenchmark is used by the standalone clickhouse-benchmark binary too, so this can show users a command that does not exist in their install.

Can we avoid hardcoding here (e.g. use argv[0] like before, or print both invocation forms)?

@alexey-milovidov

Copy link
Copy Markdown
Member

This was fixed by #105146. Let's update the branch.

@alexey-milovidov

Copy link
Copy Markdown
Member

The BuzzHouse failure ([Logical error: Mutation of \Memory` table produced incomplete output](https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=99972&sha=f7959f604f297d728373e5f6ed753d9a0bde5a3c&name_0=PR&name_1=BuzzHouse%20%28amd_tsan%29)) is unrelated to this PR. The same exception (STID: 2380-3043) was observed on master and 8 other PRs in the past day (#99804, #100185, #100586, #104606, #105107, #105161, #105233, plus master) — it originates in StorageMemory::mutateatsrc/Storages/StorageMemory.cpp:317`, not in the code paths touched by this PR.

Addressed reviewer feedback: removed the unnecessary no-fasttest tag from tests/queries/0_stateless/04035_benchmark_multiline.sh (other clickhouse-benchmark stateless tests like 01088_benchmark_query_id.sh and 01600_benchmark_query.sh run without it).

@groeneai, could you investigate the Memory table mutation issue (report) and provide a fix in a separate PR? If a fix is already in progress, please link it here.

@ClickHouse ClickHouse deleted a comment from CLAassistant May 19, 2026
@alexey-milovidov alexey-milovidov removed the close in a month if not active This will be closed in case of no information label May 19, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@groeneai

Copy link
Copy Markdown
Collaborator

@alexey-milovidov — investigated and submitted a fix as #105286.

Reproducer (deterministic, master HEAD):

CREATE TABLE mem (id UInt64, value String) ENGINE = Memory;
INSERT INTO mem VALUES (1, 'a'), (2, 'b');
INSERT INTO mem VALUES (3, 'c'), (4, 'd');
ALTER TABLE mem (APPLY PATCHES);
-- Logical error: 'Mutation of `Memory` table produced incomplete output:
--  block 0 has 0 rows, expected 2'.

Root cause: MutationsInterpreter::prepare short-circuits APPLY_PATCHES /
APPLY_DELETED_MASK without adding a mutation stage
(MutationsInterpreter.cpp:1238-1243).
The resulting pipeline still pulls one output block per input block but each
block has zero rows, then StorageMemory::mutate's partial-column path
(StorageMemory.cpp:323-332)
hits the new LOGICAL_ERROR you added.

Fix: Memory doesn't own patch parts (lightweight updates are a MergeTree
feature) and doesn't maintain _row_exists deletion masks, so both commands are
semantic no-ops for Memory — the post-state ("all patches applied", "deleted
rows removed") is already satisfied. PR #105286 filters them out of
StorageMemory::mutate before constructing the mutation pipeline. A real
UPDATE / DELETE mixed into the same ALTER still executes normally — covered
by the new regression test 04254_memory_apply_patches_no_op along with all
four trigger forms (parenthesised, bare, APPLY DELETED MASK, mixed).

Cross-link to the umbrella tracker for this STID family (originally STID 2380-278c
assertion, now STID 2380-3043 after the throw was added):

This PR should clear the BuzzHouse failure here. Once #105286 merges I'll
verify master + the sibling PRs stay clean for 48h via CIDB.

@alexey-milovidov
alexey-milovidov force-pushed the clickhouse-benchmark-multiline branch from 431c646 to fa2cd1f Compare May 19, 2026 04:28
@clickhouse-gh

clickhouse-gh Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.20% +0.10%
Functions 91.40% 91.40% +0.00%
Branches 76.60% 76.60% +0.00%

Changed lines: 95.65% (44/46) · Uncovered code

Full report · Diff report

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue May 19, 2026
Merged via the queue into ClickHouse:master with commit d25af7f May 19, 2026
165 checks passed
@AVMusorin
AVMusorin deleted the clickhouse-benchmark-multiline branch May 19, 2026 16:09
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 19, 2026
rorylshanks pushed a commit to rorylshanks/ClickHouse that referenced this pull request Jun 13, 2026
`ALTER TABLE <memory_tbl> (APPLY PATCHES)` (and the equivalent
`APPLY DELETED MASK`) used to raise

    Logical error: Mutation of `Memory` table produced incomplete output:
    block 0 has 0 rows, expected N

(`STID: 2380-3043`, surfaced by `BuzzHouse` on master and 8+ unrelated PRs
in a 24h window).

`MutationsInterpreter::prepare` short-circuits both commands without adding
a mutation stage (`MutationsInterpreter.cpp:1238-1243`). On a `Memory` table
the resulting pipeline still pulls one output block per input block, but
each one has zero rows. `StorageMemory::mutate` then walks the partial-column
path and fails the per-block row-count invariant.

`Memory` tables do not own patch parts (lightweight updates are a `MergeTree`
feature) and do not maintain a `_row_exists` deletion mask, so both commands
are semantically no-ops here: the post-state the user is asking for (all
patches applied, all deleted rows physically removed) is already satisfied.
Filter them out before constructing the mutation pipeline; if all commands
are filtered, return immediately. A `UPDATE` or `DELETE` mixed in the same
`ALTER` still executes normally.

CI report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=99972&sha=f7959f604f297d728373e5f6ed753d9a0bde5a3c&name_0=PR&name_1=BuzzHouse%20%28amd_tsan%29
Reported on ClickHouse#99972

Regression test `04254_memory_apply_patches_no_op` exercises:
- parenthesised `(APPLY PATCHES)` (the `BuzzHouse` form)
- bare `APPLY PATCHES`
- `APPLY DELETED MASK`
- mixed `UPDATE ... , APPLY PATCHES SETTINGS mutations_sync = 1`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors 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