Repository navigation
Follow-ups for CREATE HANDLER: parse limits of the stored query, docs, refactoring - #114883
Conversation
…n tree
The page was written into `docs/en/sql-reference/statements/create/handler.md`,
a path in the legacy Docusaurus tree that `9440ca729a3` ("Docs: remove legacy
Docusaurus documentation") had already deleted, so the only documentation of
`CREATE HANDLER` / `ALTER HANDLER` / `DROP HANDLER` was not published anywhere.
Move it to `docs/reference/statements/create/handler.mdx`, convert the
frontmatter and the internal links to the conventions of that tree, and register
the page in `docs/reference/navigation.json`.
`docs/en/operations/system-tables/handlers.md` was a leftover copy of
`docs/reference/system-tables/handlers.mdx`, which is generated from the system
table registration and therefore lost the hand-written part: restore the
`SHOW HANDLERS` and secret-masking paragraph there and delete the legacy copy.
Also cross-reference the statement from the HTTP interface page, the `DROP`
statement page and the `ALTER` overview, and document that a `URL REGEXP` is
anchored (`RE2::FullMatch`), which was not stated anywhere.
Follow-up to #106231
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`SQLDefinedHandlerFromAST` carried two predicates over `IAST::QueryKind`: whether a query of that kind is rejected under `readonly`, and whether `readonly = 2` still lets it produce side effects. Neither is specific to SQL-defined HTTP handlers - both describe the `readonly` mode itself, mirroring the enforcement in `ContextAccess` and `BackupsWorker` - so they now live in `Interpreters/QueryKindUnderReadonly.h`, and `queryKindRequiresMutatingMethod` is renamed to `isQueryKindRejectedUnderReadonly` after the property it reports. The handler code keeps what is genuinely about HTTP: the refinements for concrete statements (`CREATE TEMPORARY`, `WATCH`, `EXECUTE AS`, temporary-table mutations), the look-through of the `PARALLEL WITH` / `EXECUTE AS` wrappers and the method fences that consume all of it. Follow-up to #106231 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…` to 26.8 The functions were registered with `IntroducedIn` 26.6, the development version at the time they were written; they are released in 26.8. Follow-up to #106231 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…query The query a handler executes is the server's own stored text: it is parsed when the handler is created and re-parsed with no depth, backtracking or size limit whenever it is reloaded, so a handler the server accepted has to stay invokable. The invocation path relaxed `max_parser_depth` and `max_parser_backtracks` for that reason, but it did so before applying the settings the request supplies, and a request names settings freely - so `GET /h?max_parser_depth=1` put the caller's value back and broke the handler again. Relax those two limits after the request settings instead. `max_query_size` has the same problem and is not even limited to a request that asks for it: a stored query longer than its default value is creatable and reloadable, both of which parse without a size limit, but failed on every request. Raise it to fit the query text - not disable it, because `executeQuery` also uses `max_query_size` to decide how much of the request stream to read ahead in search of the query, where `0` would make it read a single byte. Tests `04897_handler_request_parser_limits` (all three limits supplied by the request) and `04898_handler_large_query_invocation` (a stored query longer than the default `max_query_size`), both verified to fail without the fix. Follow-up to #106231 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [ad4b81e] Summary: ✅
AI ReviewSummaryThis PR hardens server-owned SQL parsing for Findings
Final Verdict
|
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes398 object files changed (+72.12 KiB total), 1 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units1485 translation units recompiled, 9817 s compile time in total, 1484 of them have a recent master baseline. |
|
🕵 @groeneai, investigate the unrelated integration-test failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=114883&sha=08ab805c543282daef42d1034e621276cab440c9&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%202%2F6%29. |
|
Investigated. Two corrections to the premise, then what I think is actually fixable. It is not ZooKeeper. The real symptom is a fatal bind failure. The server exited 210 ( Why I cannot name the port, and what I would fix. The line that identifies it was deleted by the test harness. Every test in the module constructs its own Two things worth knowing before deciding: this is deterministic rather than flaky (the retry failed again in about a second, in a freshly pruned environment), yet it is a single occurrence, I would rather not guess at the bind cause. My proposal is to fix the diagnostic loss first, so the next occurrence names the port and errno instead of being unattributable, and I can open that as a separate PR. Say the word if you would prefer I keep digging into the bind itself instead. |
|
🕵 Opened a separate diagnostic fix: #114992. It gives each |
# Conflicts: # src/Server/HTTPHandler.cpp
# Conflicts: # src/Interpreters/DDLTask.cpp # src/Interpreters/executeQuery.cpp # src/Server/HTTPHandler.cpp
# Conflicts: # src/Interpreters/executeQuery.cpp
|
🕵 Merged |
|
🕵 Merged |
…ery` Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s server-owned The Prometheus HTTP API (`/api/v1/query`, `/api/v1/query_range`, `/api/v1/series`, `/api/v1/labels`, `/api/v1/label/.../values`) and remote write execute SQL formatted by the server, but the request context takes arbitrary URL parameters as settings, so `?dialect=kusto` or a small `max_query_size` / `max_parser_depth` made them fail. Pass `QueryFlags::parse_server_owned_query_without_limits` on those `executeQuery` calls, as the HTTP handlers already do for their stored query. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failures: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=114883&sha=3d50bd0f5bc281762223bcfed59f358a2fb984a3&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29 ( |
|
I looked at both.
SELECT f((40 IN (1)).1[4], 38)The first formatting is |
|
The fix for the BuzzHouse |
|
🕵 Thanks @groeneai. Both failures are unrelated to this PR: the |
Conflicts: - `SQLDefinedHandlerFromAST.cpp`: master reworded the comments of `queryKindRequiresMutatingMethod` and `queryKindHasSideEffectsUnderReadonly` for `access_control_improvements.readonly_restricts_set_role`; this PR moved both predicates to `Interpreters/QueryKindUnderReadonly`, so the reworded comments are carried over there. - `ParserCreateHandlerQuery.cpp`: kept the PR's `URL REGEXP` anchoring sentence and master's `SET ROLE` sentence in the `METHODS` clause. - `test_query_api.py`: kept both the PR's test and master's RFC3339 tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged |
…cache Master now parses the SQL generated by the Prometheus protocols as server-owned (ClickHouse#114883). The chunk queries of a split range query are generated SQL too, so they get the same flags. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Follow-ups from #106231 (
CREATE HANDLER).Related: #106231
Requested in review of #106231:
IAST::QueryKindthat describe thereadonlymode - whether a query of that kind is rejected under it, and whetherreadonly = 2still lets it produce side effects - moved out ofSQLDefinedHandlerFromASTintoInterpreters/QueryKindUnderReadonly.h;queryKindRequiresMutatingMethodis renamed toisQueryKindRejectedUnderReadonlyafter the property it reports. The handler code keeps the statement-level refinements and the HTTP-method fences.currentHandlerandcurrentRequestURLwere registered withIntroducedIn26.6 (the development version when they were written); they are released in 26.8.The one unresolved review finding: a request could still lower the parse limits of a handler's query.
HTTPHandler::processQueryrelaxedmax_parser_depth/max_parser_backtracksbefore applying the settings the request supplies, and a request names settings freely - soGET /h?max_parser_depth=1put the caller's value back and broke a handler the server itself had accepted.max_query_sizehad the same hole and did not even need a hostile request: a stored query longer than its default value is creatable and reloadable (both parse without a size limit) but failed on every invocation. The fix went through review iterations and landed as a per-query flag rather than context settings:executeQueryreceivesQueryFlags::parse_server_owned_query_without_limits(set byPredefinedQueryHandler, from whichSQLDefinedQueryHandlerinherits) and liftsmax_parser_depth/max_parser_backtracks/max_query_sizeonly while parsing the stored query text itself. The query context keeps the request's limits, so the request-controlled construction snippets (select/filter/order/page) and everything else are still parsed under the caller's own limits - the request can neither break the server's stored text nor borrow its unlimited parse. The flag propagates throughPARALLEL WITHandEXECUTE ASsubqueries. New tests04897_handler_request_parser_limits(including a?max_parser_depth=1&filter=(((((1)))))case that must keep failing) and04898_handler_large_query_invocation, both verified to fail without the fix.Re-parses of the same stored text (later review iterations): every path that formats the accepted AST back to SQL and parses it again needed the lift too.
run_query_in_backgroundre-parses through a context copy, so the parse mode is carried by the query context as well as byQueryFlags. AnON CLUSTERquery executes from the DDL queue on every host:DDLWorkerparses the entry with the flag. ADistributed/remote()fan-out sends the text to shards: the initiator zeroesmax_parser_depth/max_parser_backtrackson the query context — only after the request-derived construction snippets are parsed under the caller's limits — so the shards receive the lifted limits through the ordinary settings channel, whichTCPHandlerclamps to the receiving node's constraints.query_kindis never trusted for this: a wire-spoofedSECONDARY_QUERYkeeps the request's parser limits (test05043_secondary_query_parser_limits). New tests:05029_handler_on_cluster_parser_limitsand the background /remote()sections of04897_handler_request_parser_limits.The DDL worker's own profile (later review iteration): the
ON CLUSTERpre-parse inDDLTaskBase::parseQueryFromEntryclamped the entry's parser limits against the worker's own profile, whilemakeQueryContextexecutes the entry as the initiator's user whendistributed_ddl_use_initial_user_and_roles = 1. The pre-parse now resolves that user through the newDDLTaskBase::resolveInitiatorUserAndRoles(whichmakeQueryContextuses as well) and takes its settings and constraints, so parsing and execution cannot use different profiles. New integration testtest_distributed_ddl_initiator_user_parser_limits, verified to fail without the fix.Documentation: the
CREATE HANDLERpage was written intodocs/en/sql-reference/statements/create/handler.md- a path in the legacy Docusaurus tree that9440ca729a3had already removed - so the only documentation ofCREATE HANDLER/ALTER HANDLER/DROP HANDLERwas published nowhere. It moves todocs/reference/statements/create/handler.mdx, with the frontmatter and internal links converted to that tree's conventions and the page registered indocs/reference/navigation.json.docs/en/operations/system-tables/handlers.mdwas a leftover copy of the generateddocs/reference/system-tables/handlers.mdxwhose hand-writtenSHOW HANDLERS/ secret-masking paragraph had been lost; that paragraph is restored and the legacy copy deleted. The statement is now cross-referenced from the HTTP interface page, theDROPpage and theALTERoverview, and the anchored (RE2::FullMatch) semantics ofURL REGEXPare documented. With master's move of the SQL statement pages into source, theDROP HANDLERsection is added to theDROPstatement's doc string inParserDropQuery.cpp(the source of truth for the autogenerateddocs/reference/statements/drop.mdx).Verified locally: all 30 SQL-defined-handler stateless tests pass against a server built from this branch (the 31st match of the
handlerfilter,03354_tcp_handler_async_insert_bug, is unrelated and needs a writable/var/lib/clickhouse/user_files), and04844_handler_deep_query_invocationstill passes without the fix, confirming it covered only the session-level limit.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed HTTP handler invocation so request-level
max_parser_depth,max_parser_backtracks, andmax_query_sizeno longer break stored handler queries, and published theCREATE HANDLER,ALTER HANDLER, andDROP HANDLERdocumentation.Workflow [PR]
Sync PR [sync-upstream/pr/114883]
Version info
26.10.1.2242-master(included in26.10and later)