Skip to content

Fix max_query_size handling for server-generated DDL queries - #117678

Open
otselnik wants to merge 42 commits into
ClickHouse:masterfrom
otselnik:fix/ddl-worker-max-query-size
Open

otselnik wants to merge 42 commits into
ClickHouse:masterfrom
otselnik:fix/ddl-worker-max-query-size

Conversation

@otselnik

@otselnik otselnik commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Server-generated distributed DDL queries can become significantly larger than the original client query after server-side rewriting, for example when expanding SQL user-defined functions. The DDLWorker then reparses the expanded query using the initiating session's max_query_size and may reject it even though the original query was within the limit.

Bypass max_query_size and non-ClickHouse dialect selection when reparsing contexts marked with isDDLOrOnClusterInternal. Other parser-complexity and AST-size limits remain unchanged because they are separate safety controls. External queries remain subject to max_query_size.

Added functional coverage for:

  • SQL user-defined function expansion in an ON CLUSTER query;
  • an ON CLUSTER query initiated with the clickhouse_json dialect;
  • enforcement of max_query_size for oversized external queries.

Related: #104881

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fixed ON CLUSTER DDL queries failing with Max query size exceeded when server-side rewriting, such as SQL user-defined function expansion, makes the queued query larger than max_query_size.


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

@Algunenano Algunenano added comp-ddl DDL command coordination and execution (ON CLUSTER, DDL queue). can be tested Allows running workflows for external contributors labels Sep 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [341425f]

Summary: ✅


AI Review

Summary

Reviewed #117678 at 341425fba92c07612f90bfa722c7ec3e14b6a689, including all prior discussion. The change fixes size-limit and dialect handling for server-generated DDL, filters parser-only settings from both ON CLUSTER and Replicated database entries, and preserves settings needed during execution. No actionable findings remain. All four added regression tests pass in CI; focused local checks with the PR binary also passed.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 2, 2026
Comment thread src/Interpreters/executeQuery.cpp Resolved
Use the same derived flag for `max_query_size` handling and dialect selection. Add regression coverage for an `ON CLUSTER` query initiated with the `clickhouse_json` dialect.
@clickhouse-gh

clickhouse-gh Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 341425fba with master 0b5613b71 (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

74 translation units recompiled, 661 s compile time in total, 74 of them have a recent master baseline.

Job report

Comment thread src/Interpreters/executeQuery.cpp Resolved
…x-query-size

# Conflicts:
#	src/Interpreters/executeQuery.cpp
Comment thread src/Interpreters/executeQuery.cpp Resolved
Comment thread src/Interpreters/executeQuery.cpp Resolved
Comment thread src/Interpreters/executeQuery.cpp Resolved
Comment thread src/Interpreters/DDLTask.cpp Resolved
Comment thread src/Databases/DatabaseReplicated.cpp Resolved
Mirror the `ON CLUSTER` query-text filtering in `DatabaseReplicated` while keeping the caller AST unchanged. Cover `database` as an initiator-only carrier and preserve semantic settings.

Rename all PR regression tests to the shared `05055_ddl_worker_` prefix while keeping the independent execution environments separate.

Related: ClickHouse#117678 (comment)
Comment thread src/Interpreters/DDLTask.cpp Resolved
Comment thread src/Interpreters/DDLTask.cpp Resolved
Strip all five `LogsQL` parser settings from the settings packet and query
text. Use the common request-dialect guard when selecting the parser for
server-generated queries. Extend the functional queue checks for both
`ON CLUSTER` and `Replicated`.

Related: ClickHouse#117678
Review: ClickHouse#117678 (comment)
Use `ClusterProxy::isInitiatorOnlySettingName` instead of a duplicate list
to prevent divergence from query-text filtering. Add a functional test
that sets `async_insert_select_as_async_insert` in the session, verifies
its absence from the DDL settings packet, and preserves `join_use_nulls`.

Related: ClickHouse#117678
Review: ClickHouse#117678 (comment)
Current master checks parser limits in `DDLTaskBase::parseQueryFromEntry`,
so an over-deep DDL entry no longer reaches `executeQuery`. Keep the DDL
limit assertion and use a secondary query to exercise its exception log
fallback with an unlimited parse text size. Assert that the logged text
is non-empty and bounded by the original `max_query_size`.

Related: ClickHouse#117678
Comment thread src/Interpreters/DDLTask.cpp Resolved
Keep `implicit_select` and `allow_settings_after_format_in_insert` in the
queued query and settings packet because SQL functions parse string arguments
during execution. Check their results for local, `ON CLUSTER`, and `Replicated`
execution with query and session settings.

Address review: ClickHouse#117678 (comment)
…x-query-size

# Conflicts:
#	src/Interpreters/executeDDLQueryOnCluster.cpp
Group parser limits and exception logging in one test, and keep
`ON CLUSTER` and `Replicated` database settings checks separate.
Preserve query/session settings and SQL function execution scenarios.

Validation: three functional tests passed through Praktika with zero
skips; Bash syntax checks and ShellCheck passed.
Merge upstream `master` at 9a348d8.
Include the fix that disables `use_columns_cache` in the text-index
file-opening regression test. Preserve the existing `DDL` parser changes
and their regression coverage.

Related: ClickHouse#127781
Related: ClickHouse#117678
Comment thread src/Interpreters/DDLTask.cpp Resolved
Include the CI log-cluster readiness fix from upstream.

Related: ClickHouse#117678
Share `isInitiatorOnlyDDLSettingName` between query-text and settings-packet
filtering so `parallel_replicas_for_object_storage_tables` remains available
when a `DDL` worker initiates `CREATE ... AS SELECT`.

Add a functional regression comparing stored values for local execution,
`ON CLUSTER`, and a `Replicated` database with a session-only override.

Related: ClickHouse#117678
Review: ClickHouse#117678 (comment)
@maxknv maxknv added the external Author is not a member of the ClickHouse organization label Nov 2, 2026
Comment thread src/Interpreters/DDLTask.cpp Resolved
Keep the canonical names alongside their aliases so both settings packets and SQL text are filtered. Exercise session aliases, explicit query settings and `DEFAULT` in the `ON CLUSTER` and `Replicated` queues.

ClickHouse#117678 (comment)
Preserve unconditional settings capture from master and the parser-only and initiator-only filters in `DDLLogEntry::setSettingsIfRequired`.

This branch has not been deployed

No deployments
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 comp-ddl DDL command coordination and execution (ON CLUSTER, DDL queue). external Author is not a member of the ClickHouse organization pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants