Skip to content

fix: split SQL over 128 KiB across several multipart query fields - #506

Draft
ch-language-clients-rust wants to merge 1 commit into
ClickHouse:mainfrom
ch-language-clients-rust:fix/501-split-query-form-fields
Draft

ch-language-clients-rust wants to merge 1 commit into
ClickHouse:mainfrom
ch-language-clients-rust:fix/501-split-query-form-fields

Conversation

@ch-language-clients-rust

Copy link
Copy Markdown

Summary

Fixes #501.

Since #455, a query with at least one Query::param() sends its SQL as the query field of a multipart/form-data body. ClickHouse rejects any form field longer than http_max_field_value_size (128 KiB by default) with HTML Form Exception: Field value too long, so a parameterized query with more than 128 KiB of SQL failed. In 0.15.2 the SQL was the raw request body and had no such limit.

For a multipart body, the server joins the values of all query fields in order, without a separator (DynamicQueryHandler::getQuery). The client now sends the SQL as query fields of at most 128 KiB each, split on character boundaries. A query of up to 128 KiB still produces exactly one field, so its request does not change. ClickHouse/clickhouse-cs#701 takes the same approach.

The server has joined query fields this way since at least 19.14, and the loop is in every LTS release since. I checked it against 23.8, 26.7, 26.10 and head (26.11). The new integration test runs against head in CI, so a change on the server side would show up there.

Not changed: a single parameter value over 128 KiB still fails. That is not a regression, because the server applies the same limit to URL query-string values, so 0.15.2 failed on it too. A value can't be split across repeated param_<name> fields either. The Query::param docs now state the limit, and that only the server's default settings profile can raise it. A per-query or per-user http_max_field_value_size has no effect, because the server parses the form with its global settings.

Checklist

  • Unit and integration tests covering the common scenarios were added
  • A human-readable description of the changes was provided so that we can include it in CHANGELOG later

Candidate CHANGELOG entry

 * Parameterized queries (`Query::param()`) whose SQL text is larger than 128 KiB
   no longer fail with `HTML Form Exception: Field value too long`. The SQL is now
   sent as several `query` form fields of at most 128 KiB each, which the server
   joins. A single parameter value is still limited by the server's
   `http_max_field_value_size` (128 KiB by default).

🤖 Generated with Claude Code

Since ClickHouse#455, a query with parameters sends its SQL as the `query` field
of a `multipart/form-data` body. ClickHouse rejects any form field
longer than `http_max_field_value_size` (128 KiB by default) with
"HTML Form Exception: Field value too long", so a parameterized query
with more SQL text than that failed.

The server joins the values of all `query` fields in order, without a
separator (`DynamicQueryHandler::getQuery`). Send the SQL as fields of
at most 128 KiB each, split on character boundaries. A query that fits
still produces one field.

`Query::param` now documents that each parameter value is still
limited to `http_max_field_value_size`.

Fixes ClickHouse#501

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CLAassistant

CLAassistant commented Oct 30, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parameterized queries larger than 128 KiB fail since 0.15.3

2 participants