Repository navigation
Stop the Freeform structure search at the query's memory and time limits - #123238
alexey-milovidov merged 8 commits into
Conversation
…imits With `input_format_freeform_max_search_steps = 0`, which any `compatibility` below 26.10 restores, the search for the structure of a wide row of words is exponential and could not be stopped: - its candidates live in standard containers, whose allocations go through the throwing `operator new` and are never refused by the memory tracker (`min_allocation_size_to_throw_on_memory_limit` is 0 by default), so the query passed its `max_memory_usage` and took the server's memory; - nothing in the search polled the query status, so `KILL QUERY` and `max_execution_time` only set a flag nobody read. The stress runner randomizes `compatibility`, and `05258` then hung the server in `Stress test (arm_release)` (`Hung check failed`): 22 GB tracked against a 150 MB limit, `is_cancelled = 1` for 8 minutes. Check `CurrentMemoryTracker::check()` and `QueryStatus::checkTimeLimit()` once per `buildSolutions` call and once per validated candidate. The query status is resolved from the executing thread, so the check also works when the search runs inside a processor while reading rows with an explicit structure. A `false` from `checkTimeLimit` (`timeout_overflow_mode = 'break'`) throws too, because a partial schema has no meaning. Add one case per limit to `05258`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The time-limit cases of `05258` do not cover `KILL QUERY`: with `checkTimeLimitSoft` in place of `checkTimeLimit`, both stay green while a killed search ends with `TIMEOUT_EXCEEDED` instead of `QUERY_WAS_CANCELLED`. The new case starts an unbounded search, waits until it has allocated 10 MB, then runs `KILL QUERY ... SYNC` under a 10 s timeout. On master the KILL does not return and the query keeps growing past its 2 GB `max_memory_usage`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e limit No case of `05258` covers the checkpoint before each candidate's validation: with it deleted, every arm stays green because the checkpoint in `buildSolutions` stops them first. The new case keeps the search within the default bound with a short first row, then makes every one of the 2047 candidates fail only on the last of 100 long rows, so validation takes about 7 s on a debug build. At `max_execution_time` 0.1 the query ends with `TIMEOUT_EXCEEDED`; with the validation checkpoint deleted, and on master, it runs to `BAD_ARGUMENTS` after about 7.3 s. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 3 rounds) plus my own cold review in each round.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261001-105300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261001-103700 |
|
Workflow [PR], commit [cb24b95] Summary: ✅
AI ReviewSummaryThis PR makes the PR Metadata
Findings
|
| Metric | Baseline | Current | Δ |
|---|---|---|---|
| Lines | 88.30% | 88.30% | +0.00% |
| Functions | 91.80% | 91.80% | +0.00% |
| Branches | 79.70% | 79.70% | +0.00% |
Changed lines: Changed C/C++ lines covered: 38/39 (97.44%) · Uncovered code
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 12 s compile time in total, 7 of them have a recent master baseline. |
In the flaky check (8 copies of the test at once, with the thread fuzzer), the extended `05258` took 225-233 s on `amd_asan_ubsan` against the 180 s limit. Master's own cases of `05258` already take 159-172 s there, because each one runs a search of about 4096 steps. So the new cases go to `05315_freeform_structure_search_query_limits`, and `05258` is back to master's version. The memory case was the slowest one (75 s): a row of 24 words needs about 12k steps to fill 50 MB with candidates. A row of 240 words makes every candidate ten times larger, and a 20 MB limit is reached after about 500 steps. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The limits were polled once per candidate, before its validation. One candidate reads up to 100 rows and `input_format_max_bytes_to_read_for_schema_inference` bytes, so with a raised byte budget a single validation could outlast `max_execution_time` and `KILL QUERY`. Measured on a debug build with a one-word first row and 99 rows of 10 MB (budget raised): `max_execution_time = 0.1` fired after 0.73 to 1.43 s, and `KILL QUERY` was noticed 0.79 s after it was issued. With the check in the row loop the query stops at 0.10 s, and within one row of the `KILL`. The check at row 0 also covers the old per-candidate check. The worst-case search of `05315` (2047 candidates, 100 rows each) takes the same time with and without it (7.4 to 7.7 s). A test where one candidate's validation outlasts the time limit needs a sample of several GB, so the existing validation case of `05315` covers the check instead: deleting it turns that case into `BAD_ARGUMENTS`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…break'` In `break` mode `checkTimeLimit` returns false instead of throwing, and the cancellation checker does not cancel the query, so only the search's own check of that result stops it. The DESC time-limit case now runs in that mode; the pipeline and validation cases keep the default `throw`. Ignoring the result makes the case end with `MEMORY_LIMIT_EXCEEDED` after 10 s instead of `TIMEOUT_EXCEEDED`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the `Freeform` limits test `yes | head` prints `yes: standard output: Broken pipe` to stderr, which fails a `.sh` test, so the repeated rows are built without `yes`. The client of the killed query now runs in the background with its output in a file, and the test waits for it at most 60 seconds after `KILL QUERY`, reporting an explicit error and killing the client instead of hanging until the test time limit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Preserve explicit secret masks before formatting nested maps and let the `S3` classifier handle named maps before the generic positional pass. Related: ClickHouse#123238
… memory limit The KILL case of `05315_freeform_structure_search_query_limits` lost a race against the query's own `max_memory_usage = 2000000000` on `Fast test (arm_darwin)` (PR ClickHouse#110102): no client could connect to the server for 8.4 s right after the poll saw the search under way, the search reached its limit and threw `MEMORY_LIMIT_EXCEEDED`, and the KILL then landed on the query while it was freeing its candidates. The KILL is now the poll itself and matches only while `peak_memory_usage` is between 10 MB and 1 GB, so a sent KILL is always seen by the search, and a late one matches nothing instead of racing the limit. The peak, not `memory_usage`: the current usage of a query that failed on its limit falls back through the window while it frees its candidates. An attempt in which the query ended before any KILL could be sent says nothing about KILL and is repeated, at most 3 times. `kill_throw_if_noop = 0` keeps the empty matches off stderr. The client output goes to a file and the client is bounded by `timeout 60`, as in the review change `ba2c2d703b40` of ClickHouse#123238, which never reached master. Related: ClickHouse#110102 Co-Authored-By: Claude Opus 5.5 <[email protected]>
`yes | head` prints `yes: standard output: Broken pipe` to stderr where SIGPIPE is ignored, which fails a `.sh` test. The rows are byte-identical. This is part of the review change `ba2c2d703b40` by Alexey Milovidov on ClickHouse#123238, which never reached master. Co-Authored-By: Alexey Milovidov <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #122447
Related: #122412
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The search for the structure of a
Freeformrow now stops atmax_memory_usage,max_execution_timeandKILL QUERY.Description
Stress test (arm_release)fails withHung check failed, possible deadlock foundon master since #122447 (master report) and on PRs. The stress runner setscompatibilitybelow 26.10 in 20% of runs, which restoresinput_format_freeform_max_search_steps = 0.05258then infers a row of 24 words, a search of about 2^25 steps, and nothing can stop it:max_memory_usage = 150000000until the server runs out of memory.KILL QUERYandmax_execution_timeare ignored (is_cancelled: 1for 8 minutes in CI).The same holds for any query with
input_format_freeform_max_search_steps = 0or an oldercompatibility, including reading rows with an explicit structure, which reruns the search inside a processor.The search now calls
CurrentMemoryTracker::check()andQueryStatus::checkTimeLimit()once per step and once per row checked by a candidate, so it ends withMEMORY_LIMIT_EXCEEDED,TIMEOUT_EXCEEDEDorQUERY_WAS_CANCELLED.Freeformfirst ships in 26.10, so I can also make the compatibility entry keep the bound at 4096 if you prefer. This change is still needed for an explicit= 0.Validation (debug build): on master the CI query is still running after 90 s with
is_cancelled = 1and 7 GB tracked, andKILL QUERY ... SYNCdoes not return; with the fix it ends in 1.6 s withMEMORY_LIMIT_EXCEEDED, andKILL QUERY ... SYNCreturns in 0.17 s. The new test05315_freeform_structure_search_query_limitshas one case per limit (each hangs on master), and one where validating the candidates takes 7 s on master and now stops atmax_execution_time = 0.1; it passes 100 randomized runs. Inference time at the default bound is unchanged (41 vs 40 ms median).🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/123238]
Version info
26.10.1.1260-master(included in26.10and later)