Repository navigation
Conversation
An unresolved compound identifier sends typo correction into `collectCompoundExpressionValidIdentifiers`, which enumerates every subcolumn of every candidate column so it can offer a suggestion. The substream tree of a nested type doubles per nesting level, so on a deeply nested column that enumeration is exponential, and nothing along the way looked at whether the query had been cancelled: a query already marked cancelled kept running to completion, which is how one was seen 1379 s past a `max_execution_time` of 10. Two independent problems, so two changes. Most of that work is provably useless. The walk's insert requires the prefix and the subcolumn name together to have exactly as many parts as the unresolved identifier, and a subcolumn name always has at least one part, so once the prefix alone is that long no suggestion can come out of the walk at all. Return before entering it. That holds at every call site (prefixes of one, two and three parts), so the hint set is unchanged by construction rather than by approximation. `collectScopeValidIdentifiers` already guards its own walk this way; its sibling did not. The remainder still has to be interruptible, so poll `CurrentThread::checkIfNotCancelled`, which throws the query's real cancellation cause and is a no-op when no query is attached. The poll also runs before the early return, so cancellation does not depend on entering an expensive walk. Measured on a debug build, `Array(Map(String, Tuple(...)))` nested twelve deep: a one-part identifier went from 44 s to 0.09 s, a two-part one from 44 s to 2.0 s, and a two-part identifier with a 1 ms limit now reports `TIMEOUT_EXCEEDED` instead of running for 116 s and reporting `UNKNOWN_IDENTIFIER`. Pre-fix the same shape took 348 s under a sanitizer. Only this file changes, so the other `IDataType::forEachSubcolumn` callers are untouched.
The poll added in the previous commit called `CurrentThread::checkIfNotCancelled`, which reaches only `QueryStatus::throwIfKilled` and so does nothing until something else has already marked the query killed. Two supported configurations never do that, so the limit stayed unenforced in both. Under `timeout_overflow_mode = 'break'` the deadline thread calls `checkTimeLimit` instead of `cancelQuery`, and `checkTimeLimit` returns false in that mode rather than marking anything, so nothing was ever latched. And clickhouse-local starts no deadline thread at all, so no timeout fires there for either mode. Measured on a debug build against a type nested twelve deep and a 1 ms limit: `break` mode ran to `UNKNOWN_IDENTIFIER` in 0.67 s, and clickhouse-local in 1.92 s, both ignoring the limit, while the default `throw` mode on a server already reported `TIMEOUT_EXCEEDED`. Poll `QueryStatus::checkTimeLimit` instead. It computes elapsed time from the query's own watch and reads limits populated in the constructor, so it needs neither the deadline thread nor a prior cancellation, and the process list entry it comes from is created on the shared query path that clickhouse-local uses too. It calls `throwProperExceptionIfNeeded` first, so `KILL QUERY` and `throw`-mode timeouts still throw exactly what they threw before; the false return that `break` mode produces becomes a throw, because a half-collected suggestion list is a wrong hint rather than a shorter one, following the five existing callers of this pattern. The status is resolved once per call rather than per substream, so it does not cost back what the early return saves. `max_execution_time` documented that a query can never stop during analysis, which this makes untrue for one path, so the note now says so. The test gains the two arms this covers and one that pins `KILL QUERY` still reporting its own cause. Its hint arm no longer relies on the winner of two equidistant candidates, which depended on hash iteration order.
Only the new analyzer collects hints by walking subcolumns: the old analyzer answers from required column names in TreeRewriter and never runs the walk. So on an old-analyzer configuration five of the test's seven assertions checked work that does not happen, and the test failed deterministically there. Every statement that depends on the walk now pins enable_analyzer = 1. Verified on a server whose default profile sets allow_experimental_analyzer = 0: the pinned test passes, the unpinned form fails with five reference lines diverging. Two follow-ups in the same area: The max_execution_time note claimed analysis can stop only while collecting typo-correction hints. It cannot claim exclusivity: the dictionary-load wait in ExternalDictionariesLoader and the plan-time join-order enumeration in JoinOrderOptimizer::checkLimits already poll the deadline. The note now says a few designated checkpoints rather than enumerating them, since an enumeration would rot. This edits only the setting's documentation string, so no SettingsChangesHistory entry is owed. The two temporary filenames carried no per-run discriminator. That is safe under the default runner, which gives each test its own tmp directory, but not when --database is passed, where CLICKHOUSE_TMP is the shared suite directory; the stress job passes it. Both now embed CLICKHOUSE_TEST_UNIQUE_NAME.
The branch was 383 commits behind master, and the only conflicting path was the max_execution_time docstring. Master independently rewrote the same three lines in b382dfb, which arrived through ClickHouse#112689, so both texts describe the same mechanism and neither side can be taken wholesale. Master's wording is the better shape: it says most of query analysis rather than counting checkpoints, and it names a concrete place where the deadline is observed instead of leaving the reader to guess. Its example, the wait for a connection to a remote replica in ConnectionEstablisher, still exists at the master tip. The resolution keeps that framing and that example and adds this PR's checkpoint as a second one, so the note stays accurate without reasserting the exclusivity earlier rounds removed and without an enumeration that would rot as more callers start polling. No source file changes: TypoCorrection.cpp and both test files are byte-identical across the rebase. The edit stays inside the R"(...)" docstring, so no SettingsChangesHistory entry is owed, and the generated docs mirror is left to docs_autogen_nightly.py.
Internal second-model review (5 rounds, 0 open blockers, 1 disclosed test-coverage gap)An independent reviewer read the change cold, and a second model re-reviewed each revision. Five Fixed during review
💡 Sized Known gap, disclosed
I could not close this without a worse trade, and I tried. The arm would only be live for a limit What is proven by mutation rather than by argument: with the entry poll deleted and only the in-walk Raised and answered, no change❌ "Arm 1's own margin against its 10 s limit may be thin under a sanitizer." The pruned path ❌ "An analyzer ValidationReproduced without the fuzzer and both directions proven: a nested |
|
Pre-PR validation, per the nine checks I run before opening a PR. a-i validation
Mutation matrix. Every arm a separate build with its Build ID asserted against the running server; the restored tree rebuilt byte-exactly back to the shipping Build ID, which is what proves the arms were genuinely different binaries.
The last row is not a coverage gap. The walk inserts only when prefix plus subcolumn parts equals the unresolved identifier's parts, and the guard skips only when the prefix alone is already that long, in which case prefix plus at least one part strictly exceeds it. So a constant on either side changes how much work is skipped and never which hints come out, at every one of the seven call sites. Non-regression. Analyzer, hint, identifier, subcolumn and timeout slice, 223 tests: 197 OK, 16 FAIL, 6 SKIPPED. All 16 re-run in isolation against both the fixed and the unfixed binary, with identical verdicts each time, 13 FAIL and 3 OK, so the set difference is zero regressions. The 13 are environmental: they need ZooKeeper, real cluster replicas, object storage, or parallel replicas. 50 of 50 randomized runs of the new test passed at 4.4 to 4.9 s each, with the runner's own tag parser confirming the test carries no Runtime. The new test measures 3.8 to 6.3 s on a debug build and 22.4 to 24.8 s under ASAN and UBSAN, against the flaky check's 180 s cap, so it carries no |
|
cc @vdimir @yakov-olkhovskiy, could you review this? An unresolvable identifier sends typo correction into an enumeration of every subcolumn of every candidate column, which doubles per nesting level and polled no time limit, so a query on a deeply nested type kept analyzing for minutes past |
|
Workflow [PR], commit [21ed70f] Summary: ❌
AI ReviewSummaryThis PR adds Final Verdict✅ No findings. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 20/21 (95.24%) · Uncovered code |
Style check's analyzer-wording rule (ci/jobs/scripts/check_style/various_checks.sh) rejects "new analyzer": the analyzer has been the default since 24.3. The failing sub-check was the only one of 13 that failed, and because Style check is in STYLE_AND_FAST_TESTS the failure dropped every dependee job, including both per-arch Bugfix validation jobs, which in turn made the new_tests_check.py post hook report "passed: none" and fail Finish Workflow. Rewording the comment addresses both reds. The change is comment-only: the 47 executable lines of the test are byte-identical (md5 469168095337d666ceddac5efdb4a7c5 before and after), and the test still passes with output matching the committed reference exactly.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units8 translation units recompiled, 23 s compile time in total, 8 of them have a recent master baseline. |
The flaky check failed the test in all four sanitizer jobs on every run. Two separate problems, both in the test rather than the fix. The first assertion was a wall-clock race that could never detect a regression. It ran a one-part identifier under `max_execution_time = 10` and asserted `UNKNOWN_IDENTIFIER`, on the premise that the post-fix cost is far below the limit. Before the fix the walk ignored the limit entirely, so it also reported `UNKNOWN_IDENTIFIER` - just slowly. Measured against a pre-fix master build and the shipped binary at depths 10 and 12 under limits of 10 s and 300 s, all eight cells return the same output, so the arm cannot redden for any limit and only restated that some deadline is larger than some duration. On the flaky check machines the fixture cost enough that 10 s was the smaller of the two, and the assertion inverted: `Timeout exceeded: elapsed 10000.069 ms`. The three remaining timing arms assert `TIMEOUT_EXCEEDED` where the pre-fix binary reports `UNKNOWN_IDENTIFIER`, which is a real discriminator, so removing the first arm loses no coverage. The second problem is cost. `CREATE TABLE` walks the same exponential substream tree through `ColumnsDescription::addSubcolumns`, which this fix does not bound, and that dominated the run: 51-62 s per fixture in CI against 0.9 s locally. The test took 132 s on debug, 223 s under ASan, 374 s under MSan where the client hit its 300 s receive timeout, and 600 s under TSan where the runner killed it - against a 180 s `TEST_MAX_RUN_TIME_IN_SECONDS` cap for the flaky check. Reducing the nesting from 12 to 10 cuts the type string from 155,615 to 38,879 bytes and the fixture cost about 3x while keeping every assertion armed. Depth 10 is the shallowest depth that keeps the `KILL QUERY` arm reliable: the kill has to land inside the walk, and at depth 9 the walk is short enough that it does not, 3 of 5 runs. At depth 10 the test passes 20 of 20 in 2.1 s, down from 3.7 s. Against a pre-fix build it fails 3 of 3, reddening all four remaining reference lines. No source change.
|
The first assertion could not detect a regression. It asserted The rest was cost. Disclosed gap: the early return is no longer pinned by any arm; with it deleted and the checkpoints kept, the test passes 3 of 3. I am not adding an arm, because the only discriminator is elapsed time and that is the defect above. No profile event counts the walk, |
CI finish ledger - cbe01fbBoth reds trace to one trunk bug outside this change. Of 175 jobs, 2 failed and 152 were dropped.
#113045 lists this test and this exact statement among the ones it fixes, so the link is causal rather than same-area. The two integration variants report Nothing here is reachable from this change: the diff is four files, none of them I am not pushing anything for this, since retriggering would only re-run against the same trunk bug. |
…ted-type-cancellation
The flaky check failed the test on all four sanitizer flavours with "Test runs too long (> 180s)". Reading the failing job's query_log, CREATE TABLE t_04824 accounted for 157s of the 169s each copy spent, because ColumnsDescription walks the same exponential substream tree the fix bounds in typo correction, and nothing bounds it there. The type now reaches the walk as a cast inside a subquery, so no column of it is stored and the tree is walked once per assertion instead of twice. The one arm that still needs a table asserts a hint over plain column names, so a shallow type is enough for it. The kill arm keeps a wider type of its own: it has to interrupt the walk while it runs, and once the limit is observed the walk is short. Its readiness poll was an unpaced 500-iteration loop, which spent the budget querying system.processes on the server running the walk it was waiting for; it is now bounded by wall clock with a pause between polls. Measured with the runner's own flaky-check mode, 50 repeats over 8 workers with randomized settings: 150/150 pass, at most 3.84s per copy against the 180s cap, where CI recorded 181-600s. Against a pre-fix master binary the test still fails, reddening all four discriminating lines.
|
The cost was the fixture, not the assertions. In the failing job's The kill arm keeps a wider type of its own, since it has to interrupt the walk while it runs and the walk is short once the limit is observed. Its readiness poll was an unpaced 500-iteration loop querying Measured with the runner's own flaky-check mode, 50 repeats over 8 workers with randomized settings: 150/150 pass, at most 3.84s per copy. Against a pre-fix master binary the test still fails and reddens all four discriminating lines, so it has not been hollowed out. |
CI finish ledger - 21ed70fEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
175 jobs, 0 incomplete, 0 dropped, 155 green. Session id: cron:our-pr-ci-monitor:20260811-043000 |
|
Fixing PR for the hung |
|
@PedroTadim Understood, leaving it closed. One distinction that may not have been visible when this was grouped with the other cancellation PRs: this one is not a per-function cancellation check. It changes only More useful is something I measured after the close, which makes the time-limit check the wrong headline for this defect. On master
The reason is arithmetic. A hint is recorded only when the prefix part count plus the subcolumn part count equals the unresolved identifier's part count, so for a two-part identifier only one-part substreams can ever match and every deeper substream is enumerated and thrown away. So the smaller fix is to stop descending once the prefix is already at least as long as the unresolved identifier. That is a pure algorithmic bound, it involves no cancellation machinery, and it leaves the hints identical. I am not re-authoring on my own. If that shape looks right I will send it as its own PR, and if you would rather it came from elsewhere that is fine too. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
max_execution_timebeing ignored while a query was still being analyzed. Referencing an unresolved column of a deeply nested type sent typo correction into an enumeration of every subcolumn of every candidate column, exponential in the nesting depth and observing no time limit, so the query could keep running for minutes past its limit and after being cancelled.Description
Reported on #86768, in the
Stress test (arm_tsan)hung check (report): a query withis_cancelled: 1had run 1379 s againstmax_execution_time: 10, stack top inSerializationObjectPool::getOrCreateunder anenumerateStreamsrecursion,read_rows: 0.Root cause is in the analyzer, not the serialization pool. An unresolvable identifier takes the typo-correction path, where
TypoCorrection::collectCompoundExpressionValidIdentifiersenumerates every subcolumn of the candidate column looking for a suggestion. That substream tree doubles per nesting level, the walk repeats per column, table expression and scope, and nothing on it observes the time limit.Two changes in
TypoCorrection.cpp:collectScopeValidIdentifiersalready guards its walk this way.QueryStatus::checkTimeLimitin the surviving walk, and before the early return so the limit does not depend on entering it. It reads the query's own watch rather than waiting to be told, so the limit also holds undertimeout_overflow_mode = 'break'and inclickhouse-local, neither of which ever marks the query cancelled. AKILL QUERYstill reports its own cause; with no query attached it is a no-op.Reproduced without the fuzzer:
Array(Map(String, Tuple(...)))nested N deep plusSELECT alias.nosuchcol FROM t AS alias. At depth 12 that goes from 44 s to 2.0 s, and under a 1 s limit reportsTIMEOUT_EXCEEDEDinstead of running 116 s. Hints are unchanged over a 15-shape matrix.IDataTypeandISerializationare untouched, so otherforEachSubcolumncallers are unaffected. Only this carrier is closed, so the note is amended, not dropped.Measurements
Subcolumns enumerated per candidate column: 50, 106, 218, 442 at nesting depth 3, 4, 5, 6.
Debug build,
Array(Map(String, Tuple(a T, b T)))nested N deep,SELECT alias.nosuchcol FROM t AS alias:At depth 10 with
max_execution_time = 1: before 116 s andUNKNOWN_IDENTIFIER, afterTIMEOUT_EXCEEDEDin 1.2 s. A one-part identifier, which no walk can ever answer, went from 44 s to 0.09 s; with a second table expression the same shape went from 35 s to 0.84 s.The two modes that never mark a query cancelled, depth 12 under a 0.001 s limit:
timeout_overflow_mode = 'break'returnedUNKNOWN_IDENTIFIERafter 0.67 s with the limit ignored, and now returnsTIMEOUT_EXCEEDEDin 0.20 s;clickhouse-localwent from 1.92 s with the limit ignored toTIMEOUT_EXCEEDEDin 1.26 s. AKILL QUERYat depth 15 reportsQUERY_WAS_CANCELLED, never a timeout, 8 of 8.Pre-fix the one-part shape took 348 s under a sanitizer build and 23 s on a release build, so the committed test's limits hold on every build type rather than only on debug.
Hint set compared over 15 shapes (bare, alias-qualified, table-qualified and database-qualified prefixes;
Tuple,Nullable,LowCardinality,LowCardinality(Nullable),Array(Tuple),Map,Variant,Dynamic,JSON, nestedTuple): byte-identical before and after, 12 of the 15 carrying a real hint.