Repository navigation
Add inline insert data mode for native protocol - #101034
Conversation
…inline-insert-data` client option Processing many small inserts over the native protocol is suboptimal because the server replies with the table structure and column defaults for every query. This adds: - A setting `send_table_structure_on_insert_with_inline_data` (default true). When disabled, the server will parse inline data in INSERT queries itself instead of sending table structure back to the client. - A `--inline-insert-data` command-line option for `clickhouse-client`. When set, the client sends the data as is in the INSERT query text instead of converting it to blocks in the native format, and routes the query through the ordinary query path (no round-trip for table structure). The server already has the machinery to process inline INSERT data (used by the HTTP interface and async inserts). This change reuses it for the native protocol. #91630 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Workflow [PR], commit [f9e42ee] Summary: ✅ AI ReviewSummaryThis PR adds an inline insert-data mode for the native protocol in ClickHouse Rules
Final Verdict
|
| $CLICKHOUSE_CLIENT --inline-insert-data --query "INSERT INTO test_inline_insert FORMAT JSONEachRow {\"x\": 4, \"y\": \"bar\"}" | ||
|
|
||
| # Test with send_table_structure_on_insert_with_inline_data setting directly | ||
| $CLICKHOUSE_CLIENT --send_table_structure_on_insert_with_inline_data 0 --inline-insert-data --query "INSERT INTO test_inline_insert VALUES (5, 'baz')" |
There was a problem hiding this comment.
This case is labeled as “setting directly”, but it still passes --inline-insert-data, so it doesn’t verify the setting-driven path by itself.
Please add a case that sets --send_table_structure_on_insert_with_inline_data 0 without --inline-insert-data to catch regressions where the setting is ignored.
| Only has an effect in ClickHouse Cloud. Number of granules in stripe of compact part of MergeTree tables to use multibuffer reader, which supports parallel reading and prefetch. In case of reading from remote fs using of multibuffer reader increases number of read request. | ||
| )", 0) \ | ||
| \ | ||
| DECLARE(Bool, send_table_structure_on_insert_with_inline_data, true, R"( |
There was a problem hiding this comment.
I can’t find any server-side read of send_table_structure_on_insert_with_inline_data in this PR (or in the repo), so this new setting appears to be a no-op right now.
That means users who set send_table_structure_on_insert_with_inline_data=0 without --inline-insert-data won’t get the advertised behavior change. Could you either wire this setting into the insert handshake path or defer exposing the setting until it is actually consumed?
…ent-side behavior Address review feedback: - Make `send_table_structure_on_insert_with_inline_data = 0` work without `--inline-insert-data` by checking the setting value in `ClientBase` - Fix test to verify setting-only behavior (without `--inline-insert-data` flag) Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…th_inline_data` setting without `--inline-insert-data` flag Add test cases that use only the `send_table_structure_on_insert_with_inline_data` setting (set to 0) without the `--inline-insert-data` CLI flag, testing JSONEachRow and CSV formats. This verifies the setting-driven path works independently. The setting is already wired client-side at `ClientBase.cpp` line 2382 where `!client_context->getSettingsRef()[Setting::send_table_structure_on_insert_with_inline_data]` is checked to enable inline data mode. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix. |
| inline_insert_data = config().getBool("inline-insert-data", false); | ||
|
|
||
| if (inline_insert_data) | ||
| client_context->setSetting("send_table_structure_on_insert_with_inline_data", false); |
There was a problem hiding this comment.
This introduces a new user-facing setting and CLI flag, but the PR template still has Documentation is written unchecked and no docs changes are included. For a New Feature, please add docs for both send_table_structure_on_insert_with_inline_data and --inline-insert-data (behavior, defaults, limitations, examples).
Address review: add documentation for the new `--inline-insert-data` `clickhouse-client` command-line option in `docs/en/interfaces/client.md`. The setting `send_table_structure_on_insert_with_inline_data` is already documented inline via `DECLARE` in `src/Core/Settings.cpp`, which is the authoritative source used to generate settings documentation.
…ttingsChangesHistory` Master has bumped the version to 26.5; the test `02995_new_settings_history` requires entries for newly added settings to be in the 26.5 block (or later) since the baseline TSVs are generated from `v26.4.1`. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=101034&sha=c1f2cd42c5242d171cd4b8918e345f4911d0d856&name_0=PR&name_1=Fast%20test Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
@groeneai, send a PR fixing this unit test failure. |
|
@alexey-milovidov, the unit test failure on this PR's CI ( This bug is already being fixed by PR #102890 by @Avogar — approved by @nihalzp 8 days ago, awaiting merge. CIDB confirms it's a chronic finding: 30+ unrelated PRs in the last 14 days plus 3 master hits, all firing at Root cause: The outer Reproduced locally on master HEAD with the test input from PR #102890: PR #102890 fixes this with a I'll skip filing a duplicate PR. If you'd prefer a different approach (or want #102890 unblocked), let me know. — Session: cron:clickhouse-ci-task-worker:20260425-181500 |
| $CLICKHOUSE_CLIENT --inline-insert-data --query "INSERT INTO test_inline_insert FORMAT Values (3, 'foo')" | ||
| $CLICKHOUSE_CLIENT --inline-insert-data --query "INSERT INTO test_inline_insert FORMAT JSONEachRow {\"x\": 4, \"y\": \"bar\"}" | ||
|
|
||
| # Test with send_table_structure_on_insert_with_inline_data setting directly (without --inline-insert-data flag) |
There was a problem hiding this comment.
Processing inline insert data with both inlined and external data ... is not supported).
Please add a negative case that pipes stdin into an inline-data insert (with --inline-insert-data and with --send_table_structure_on_insert_with_inline_data 0) and assert the new exception text, similar to 01501_clickhouse_client_INSERT_exception.sh. Without that, this guard can regress silently.
In `ClientBase::processParsedSingleQuery`, both `is_async_insert_with_inlined_data` and `is_inline_insert_data` could be true at the same time. The async branch was checked first, so when the user explicitly requested inline insert data mode (via `--inline-insert-data` or `send_table_structure_on_insert_with_inline_data = 0`) while `async_insert` was enabled, mixing inline data with stdin/`INFILE` produced the "async inserts" rejection message instead of the "inline insert data" one. This made `04064_inline_insert_data` flaky in the AsyncInsert CI shard, where the negative cases grep for the inline-mode message but received the async-mode one. Compute `is_inline_insert_data` first and clear `is_async_insert_with_inlined_data` when it is set, so an explicit user choice for inline mode wins on the client side. CI report: #101034
LLVM Coverage Report
Changed lines: 93.10% (54/58) · Uncovered code |
| $CLICKHOUSE_CLIENT --query "CREATE TABLE test_inline_insert (x UInt64, y String) ENGINE = MergeTree ORDER BY x" | ||
|
|
||
| # Test with --inline-insert-data flag | ||
| $CLICKHOUSE_CLIENT --inline-insert-data --query "INSERT INTO test_inline_insert VALUES (1, 'hello'), (2, 'world')" |
There was a problem hiding this comment.
@groeneai Could you add an INSERT SELECT query to test another corner case? Also, test with async_inserts disabled?
|
@groeneai can you randomize the new setting introduced in this PR? |
Randomizing `send_table_structure_on_insert_with_inline_data` exposed five stateless tests that depend on the legacy "client converts inline data to native blocks" path. The randomization itself is correct and surfaces real behavior differences in the new server-side parsing path (added in ClickHouse#101034); the tests, however, were never written to cover that dimension. Fixes applied per test: * `04027_json_input_format` — change `-- { clientError 117 }` to `-- { error 117 }` (9 occurrences). The test verifies that ambiguous JSON column names are rejected. With the legacy path the client parses and reports the error; with the inline path the server parses and reports the same error. Both paths correctly detect the ambiguity, so accept the error from either side (this is a genuine improvement in test coverage, not a band-aid). * `04045_values_insert_trailing_comment` — pin via `Random settings limits` comment. The inline path has a separate, pre-existing multi-query parsing issue: a trailing SQL comment after VALUES data inside a multi-query stream silently swallows subsequent queries. Keep this test focused on the trailing-comment behavior in the legacy path it was written for. * `03229_async_insert_alter` — pin via `Random settings limits`. The test asserts `data_kind` in `system.asynchronous_insert_log`. The inline path bypasses async insert (`is_async_insert_with_inlined_data` becomes false in `ClientBase`), so log entries change from `Preprocessed` to `Parsed`. Pin the legacy path so the async-insert log assertions remain meaningful. * `01173_transaction_control_queries` — pin via `Random settings limits`. The inline path triggers async insert which interacts badly with transactions (`Async inserts inside transactions are not supported`). The test is about transaction-control semantics, not about which side parses inline data; pin the legacy path so transactions remain testable here. * `00753_system_columns_and_system_tables_long` — pin via `Random settings limits`. The inline path builds the in-memory block with a different layout, so `system.tables` reports different `total_bytes` for the `Memory` engine (e.g. 130 -> 256). Pin the legacy path; this test is about system-table reporting, not block layout. The first fix is the right semantic answer (either side reporting the same error is valid). The four pins are documented technical debt — each behavior delta in the inline path is a candidate follow-up bug for the team to triage. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104640
The randomizer added in this PR exercises `send_table_structure_on_insert_with_inline_data` with both values. With `send_table_structure_on_insert_with_inline_data = 0` (server-parsed inline path), `INSERT INTO TABLE FUNCTION ...` does not apply the column `DEFAULT` / `input_format_null_as_default` for an explicit `NULL` (it becomes 0), so this test fails (reproducible 51/51 in CI, passing 97/97 without the setting). A direct table `INSERT` is unaffected. This contradicts the earlier assumption that the behavior was already correct. Re-pin the test to `send_table_structure_on_insert_with_inline_data = (1, 1)` (the same `Random settings limits` mechanism used by the other affected tests in this PR) so it keeps testing the columns-description behavior it was written for, and track the real server-side bug in ClickHouse#109253. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104640&sha=8ed06ca93081214a31acef155c8df020fd950600&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%2C%202%2F2%29 Related: ClickHouse#101034 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
When the server parses INSERT ... VALUES inline data itself (send_table_structure_on_insert_with_inline_data = 0), an explicit NULL inserted into a non-Nullable column with a DEFAULT was not replaced by the default for INSERT INTO TABLE FUNCTION remote()/file(), producing 0 instead of the declared default. A plain table INSERT and the HTTP protocol apply it correctly. Root cause: getSourceFromInputFormat added AddingDefaultsTransform (which applies input_format_null_as_default during parsing) only when ast_insert_query->table_id was set. table_id is empty for table functions, so the transform was skipped. The synchronous path is the affected one; the asynchronous path adds its own AddingDefaultsTransform. Fix: when table_id is empty, fall back to the resolved destination columns saved in the context by InterpreterInsertQuery (getInsertionTableColumnsDescription), which is populated for table functions too. The input() path is unaffected (still gated by !input_function). Related: ClickHouse#109253 Caused by: ClickHouse#101034 Co-Authored-By: Claude Opus 4.8 <[email protected]>
When the server parses INSERT ... VALUES inline data itself (send_table_structure_on_insert_with_inline_data = 0), an explicit NULL inserted into a non-Nullable column with a DEFAULT was not replaced by the default for INSERT INTO TABLE FUNCTION remote()/file(), producing 0 instead of the declared default. A plain table INSERT and the HTTP protocol apply it correctly. Root cause: getSourceFromInputFormat added AddingDefaultsTransform (which applies input_format_null_as_default during parsing) only when ast_insert_query->table_id was set. table_id is empty for table functions, so the transform was skipped. The synchronous path is the affected one; the asynchronous path adds its own AddingDefaultsTransform. Fix: when table_id is empty, fall back to the resolved destination columns saved in the context by InterpreterInsertQuery (getInsertionTableColumnsDescription), which is populated for table functions too. The input() path is unaffected (still gated by !input_function). Related: ClickHouse#109253 Caused by: ClickHouse#101034 Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ndomize the setting Follow-up to ClickHouse#101034. @PedroTadim asked to: 1. Add an INSERT SELECT corner case to `04064_inline_insert_data.sh`. 2. Add a case with `async_insert` disabled. 3. Randomize the new `send_table_structure_on_insert_with_inline_data` setting so CI exercises both the legacy and the new server-side parsing path. Changes: * `tests/queries/0_stateless/04064_inline_insert_data.sh` and `.reference`: - Two INSERT SELECT cases (with the `--inline-insert-data` flag and with `send_table_structure_on_insert_with_inline_data = 0`). INSERT SELECT queries do not have inline data, so the new inline path is bypassed via the `!insert->select` guard in `is_inline_insert_data`. The cases verify that requesting inline insert data mode does not break SELECT-driven INSERTs. - Two cases with `--async_insert 0` (one via the CLI flag, one via the setting). The user's explicit choice takes precedence over `async_insert` on the client side, so the data is parsed by the server inline regardless of the async insert toggle. * `tests/clickhouse-test`: - Add `send_table_structure_on_insert_with_inline_data` to `SettingsRandomizer.settings` so CI exercises both the legacy "client converts inline data to native blocks" path and the new "server parses inline data" path.
…sert-data-tests-101034-followup Extend 04064_inline_insert_data and randomize send_table_structure_on_insert_with_inline_data (follow-up to ClickHouse#101034)
When the server parses INSERT ... VALUES inline data itself (send_table_structure_on_insert_with_inline_data = 0), an explicit NULL inserted into a non-Nullable column with a DEFAULT was not replaced by the default for INSERT INTO TABLE FUNCTION remote()/file(), producing 0 instead of the declared default. A plain table INSERT and the HTTP protocol apply it correctly. Root cause: getSourceFromInputFormat added AddingDefaultsTransform (which applies input_format_null_as_default during parsing) only when ast_insert_query->table_id was set. table_id is empty for table functions, so the transform was skipped. The synchronous path is the affected one; the asynchronous path adds its own AddingDefaultsTransform. Fix: when table_id is empty, fall back to the resolved destination columns saved in the context by InterpreterInsertQuery (getInsertionTableColumnsDescription), which is populated for table functions too. The input() path is unaffected (still gated by !input_function). Related: ClickHouse#109253 Caused by: ClickHouse#101034 Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ndomize the setting Follow-up to ClickHouse#101034. @PedroTadim asked to: 1. Add an INSERT SELECT corner case to `04064_inline_insert_data.sh`. 2. Add a case with `async_insert` disabled. 3. Randomize the new `send_table_structure_on_insert_with_inline_data` setting so CI exercises both the legacy and the new server-side parsing path. Changes: * `tests/queries/0_stateless/04064_inline_insert_data.sh` and `.reference`: - Two INSERT SELECT cases (with the `--inline-insert-data` flag and with `send_table_structure_on_insert_with_inline_data = 0`). INSERT SELECT queries do not have inline data, so the new inline path is bypassed via the `!insert->select` guard in `is_inline_insert_data`. The cases verify that requesting inline insert data mode does not break SELECT-driven INSERTs. - Two cases with `--async_insert 0` (one via the CLI flag, one via the setting). The user's explicit choice takes precedence over `async_insert` on the client side, so the data is parsed by the server inline regardless of the async insert toggle. * `tests/clickhouse-test`: - Add `send_table_structure_on_insert_with_inline_data` to `SettingsRandomizer.settings` so CI exercises both the legacy "client converts inline data to native blocks" path and the new "server parses inline data" path.
Randomizing `send_table_structure_on_insert_with_inline_data` exposed five stateless tests that depend on the legacy "client converts inline data to native blocks" path. The randomization itself is correct and surfaces real behavior differences in the new server-side parsing path (added in ClickHouse#101034); the tests, however, were never written to cover that dimension. Fixes applied per test: * `04027_json_input_format` — change `-- { clientError 117 }` to `-- { error 117 }` (9 occurrences). The test verifies that ambiguous JSON column names are rejected. With the legacy path the client parses and reports the error; with the inline path the server parses and reports the same error. Both paths correctly detect the ambiguity, so accept the error from either side (this is a genuine improvement in test coverage, not a band-aid). * `04045_values_insert_trailing_comment` — pin via `Random settings limits` comment. The inline path has a separate, pre-existing multi-query parsing issue: a trailing SQL comment after VALUES data inside a multi-query stream silently swallows subsequent queries. Keep this test focused on the trailing-comment behavior in the legacy path it was written for. * `03229_async_insert_alter` — pin via `Random settings limits`. The test asserts `data_kind` in `system.asynchronous_insert_log`. The inline path bypasses async insert (`is_async_insert_with_inlined_data` becomes false in `ClientBase`), so log entries change from `Preprocessed` to `Parsed`. Pin the legacy path so the async-insert log assertions remain meaningful. * `01173_transaction_control_queries` — pin via `Random settings limits`. The inline path triggers async insert which interacts badly with transactions (`Async inserts inside transactions are not supported`). The test is about transaction-control semantics, not about which side parses inline data; pin the legacy path so transactions remain testable here. * `00753_system_columns_and_system_tables_long` — pin via `Random settings limits`. The inline path builds the in-memory block with a different layout, so `system.tables` reports different `total_bytes` for the `Memory` engine (e.g. 130 -> 256). Pin the legacy path; this test is about system-table reporting, not block layout. The first fix is the right semantic answer (either side reporting the same error is valid). The four pins are documented technical debt — each behavior delta in the inline path is a candidate follow-up bug for the team to triage. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104640
The randomizer added in this PR exercises `send_table_structure_on_insert_with_inline_data` with both values. With `send_table_structure_on_insert_with_inline_data = 0` (server-parsed inline path), `INSERT INTO TABLE FUNCTION ...` does not apply the column `DEFAULT` / `input_format_null_as_default` for an explicit `NULL` (it becomes 0), so this test fails (reproducible 51/51 in CI, passing 97/97 without the setting). A direct table `INSERT` is unaffected. This contradicts the earlier assumption that the behavior was already correct. Re-pin the test to `send_table_structure_on_insert_with_inline_data = (1, 1)` (the same `Random settings limits` mechanism used by the other affected tests in this PR) so it keeps testing the columns-description behavior it was written for, and track the real server-side bug in ClickHouse#109253. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104640&sha=8ed06ca93081214a31acef155c8df020fd950600&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%2C%202%2F2%29 Related: ClickHouse#101034 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…sert-data-tests-101034-followup Extend 04064_inline_insert_data and randomize send_table_structure_on_insert_with_inline_data (follow-up to ClickHouse#101034)
Add a setting
send_table_structure_on_insert_with_inline_dataand a--inline-insert-datacommand-line option forclickhouse-clientto allow the server to parse inline INSERT data itself, avoiding the round-trip to send table structure back to the client.This reuses the existing server-side inline data parsing machinery (used by the HTTP interface and async inserts) for the native TCP protocol, which improves performance for many small inserts.
Closes #91630
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Add setting
send_table_structure_on_insert_with_inline_dataand--inline-insert-dataclient option to allow the server to parse inline INSERT data itself over the native protocol, avoiding the round-trip to receive table structure and improving performance for many small inserts.Documentation entry for user-facing changes
New setting
send_table_structure_on_insert_with_inline_data(Bool, defaulttrue): when disabled, the server will parse inline data in INSERT queries itself instead of sending table structure and column defaults back to the client.New
clickhouse-clientoption--inline-insert-data: sends INSERT data as is in the query text instead of converting it to blocks in the native format. Automatically setssend_table_structure_on_insert_with_inline_data = false.Example:
clickhouse-client --inline-insert-data --query "INSERT INTO t VALUES (1, 'hello'), (2, 'world')"Version info
26.5.1.144