Skip to content

Observe the query time limit while collecting typo-correction hints - #113996

Closed
groeneai wants to merge 8 commits into
ClickHouse:masterfrom
groeneai:typo-correction-nested-type-cancellation
Closed

groeneai wants to merge 8 commits into
ClickHouse:masterfrom
groeneai:typo-correction-nested-type-cancellation

Conversation

@groeneai

@groeneai groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

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 max_execution_time being 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 with is_cancelled: 1 had run 1379 s against max_execution_time: 10, stack top in SerializationObjectPool::getOrCreate under an enumerateStreams recursion, read_rows: 0.

Root cause is in the analyzer, not the serialization pool. An unresolvable identifier takes the typo-correction path, where TypoCorrection::collectCompoundExpressionValidIdentifiers enumerates 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:

  • Return before entering the walk when it cannot contribute: the insert needs prefix plus subcolumn name to have exactly as many parts as the unresolved identifier, and a subcolumn name has at least one part, so once the prefix alone is that long nothing can come out. That holds at every call site, so the hint set is unchanged by construction. collectScopeValidIdentifiers already guards its walk this way.
  • Poll QueryStatus::checkTimeLimit in 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 under timeout_overflow_mode = 'break' and in clickhouse-local, neither of which ever marks the query cancelled. A KILL QUERY still reports its own cause; with no query attached it is a no-op.

Reproduced without the fuzzer: Array(Map(String, Tuple(...))) nested N deep plus SELECT alias.nosuchcol FROM t AS alias. At depth 12 that goes from 44 s to 2.0 s, and under a 1 s limit reports TIMEOUT_EXCEEDED instead of running 116 s. Hints are unchanged over a 15-shape matrix. IDataType and ISerialization are untouched, so other forEachSubcolumn callers 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:

depth 7 9 10 11 12
before 0.75 s 3.21 s 7.58 s 18.09 s 43.97 s
after 0.68 s 0.50 s 0.63 s 1.09 s 2.01 s

At depth 10 with max_execution_time = 1: before 116 s and UNKNOWN_IDENTIFIER, after TIMEOUT_EXCEEDED in 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' returned UNKNOWN_IDENTIFIER after 0.67 s with the limit ignored, and now returns TIMEOUT_EXCEEDED in 0.20 s; clickhouse-local went from 1.92 s with the limit ignored to TIMEOUT_EXCEEDED in 1.26 s. A KILL QUERY at depth 15 reports QUERY_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, nested Tuple): byte-identical before and after, 12 of the 15 carrying a real hint.

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.
@groeneai

groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator Author
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
rounds ran before this was published. Recorded here so a maintainer can see what was challenged and
what the answers were, including one gap I could not close and am disclosing rather than papering
over.

Fixed during review

⚠️ The first version only observed cancellation, so it did not enforce the limit in two documented
modes.
It polled CurrentThread::checkIfNotCancelled(), which reaches only
QueryStatus::throwIfKilled(), so it was a no-op wherever nothing had already latched is_killed:
under timeout_overflow_mode = 'break' (CancellationChecker only calls cancelQuery(TIMEOUT) for
the throw mode) and in clickhouse-local (the deadline watchdog thread starts only in the server).
Both were reproduced. Since the changelog entry claims max_execution_time unqualified, the
predicate was swapped to QueryStatus::checkTimeLimit(), which reads the query's own watch and needs
neither the watchdog nor a prior cancellation. Test arms were added for both modes.

⚠️ A hint assertion pinned an arbitrary tie-break. The fixture was Tuple(aa, bb) against
x.ab: both candidates sit at edit distance 1, so NamePrompter<1> keeps whichever the
unordered_set iteration happened to yield first. Ported the prompter and confirmed the two orders
give different answers, then changed the fixture to Tuple(aa, zz) (distances 1 and 2, both still
inside mistake_factor, so the arm stays a two-candidate test) and confirmed both orders now agree.

⚠️ The test did not pin the analyzer. The whole fix is in the new analyzer, so on an
old-analyzer configuration the walk never runs and 5 of the 7 reference lines asserted work that does
not happen. Pinned enable_analyzer = 1 on the walk-dependent statements, with a negative control:
the unpinned copy fails on an old-analyzer server with both hint lines and both timeout arms
diverging.

⚠️ The max_execution_time note claimed analysis now stops "only" during typo correction. Not
true: ExternalDictionariesLoader and JoinOrderOptimizer::checkLimits also check. The note now
keeps the existing remote-replica example and adds this one, naming both places rather than
implying an exhaustive list.

💡 Sized --max_query_size to the measured statement, corrected the no-fasttest reason, and made
the temp filenames per-run unique so a shared suite tmp directory cannot collide.

Known gap, disclosed

⚠️ One of the two checkpoints is not pinned by a committed test arm. The limit is polled in two
places: on entry to collectCompoundExpressionValidIdentifiers, and inside the walk itself. Every
committed timeout arm uses an aliased table, which issues two collection calls per column, so if the
in-walk poll alone were deleted the first call's walk would run to completion and the second call's
entry poll would report the same TIMEOUT_EXCEEDED with identical output. So the committed arms
prove the limit is observed, but not that it is observed inside the walk.

I could not close this without a worse trade, and I tried. The arm would only be live for a limit
between the entry cost and the walk cost, and both scale with the same doubling substream tree, so
that window's width is fixed (about 5x) while its position moves about 12x between a debug and a
sanitizer build. The windows do not overlap, so no constant works on both, at any fixture depth;
reshaping the fixture does not help either, because the type string and the substream count double
together. Widening it by adding columns backfires, since each extra column re-runs the entry poll. A
limit derived at runtime would work, but it would turn a currently deterministic test (50 randomized
runs, 50 passed) into a timing-dependent one across every sanitizer under concurrent load. Removing
the entry poll would make the arm trivially clean, but that poll bounds real work the in-walk one
does not: parent scopes are walked in turn, each running the per-column loop over up to four
qualifier forms.

What is proven by mutation rather than by argument: with the entry poll deleted and only the in-walk
poll left, the limit is still reported and the exception still propagates out of the
enumerateStreams recursion; deleting the in-walk poll instead moves the reporting threshold from
0.60 s to 0.10 s, which measures its contribution directly. Both checkpoints work. Only a CI arm for
one of them is missing.

Raised and answered, no change

❌ "Arm 1's own margin against its 10 s limit may be thin under a sanitizer." The pruned path
does still pay a process-list lookup and a clock read per call across roughly 113k calls, but the
measured post-fix cost is 0.09 s on debug (0.80 us per call, which is what that operation set costs),
and an ASAN build of the whole test in the same worktree ran 22.4 to 24.8 s, 3 of 3, against the
flaky check's 180 s cap. Raising the limit would only weaken the guard: pre-fix the same arm takes
44 s on debug, 23 s on release and 348 s under ASAN, so it reddens on every build type.

❌ "An analyzer catch could swallow the new exception." Enumerated all 11 catch sites under
src/Analyzer/. Only the two dead-branch constant-folding optimizations swallow unconditionally, and
checkTimeLimit() is a pure function of elapsed time, so once the deadline passes every later call
throws again; the swallow still aborts the expensive walk. Pre-existing and not worsened here.

Validation

Reproduced without the fuzzer and both directions proven: a nested Array(Map(String, Tuple(...)))
plus SELECT alias.nosuchcol went from 44 s to 2.0 s at depth 12, and from 116 s of ignoring a 1 s
limit to reporting TIMEOUT_EXCEEDED. Hints compared byte for byte over 15 type and prefix shapes,
12 of which carry a real hint. Each reference line was checked to fail on a mutant of the change it
covers, with the one exception described under the known gap above. 50 randomized runs, 50 passed. IDataType and ISerialization are untouched, so the other
forEachSubcolumn callers are unaffected by construction.

@groeneai

groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation, per the nine checks I run before opening a PR.

a-i validation
check result
a Deterministic repro Yes. Array(Map(String, Tuple(a T, b T))) nested N deep plus SELECT a1.nosuchcol FROM t AS a1, all returning Code: 47 so the error path is provably reached. Debug: 0.75 / 3.21 / 7.58 / 18.09 / 43.97 s at depth 7, 9, 10, 11, 12, about 2.4x per level. No fuzzer, no merge(), no TSAN. Depth is capped at 12 by the default max_ast_elements, where depth 13 fails Code: 168 TOO_BIG_AST.
b Root cause explained An unresolvable identifier takes the typo-correction path, where TypoCorrection::collectCompoundExpressionValidIdentifiers walks every subcolumn of the candidate column via IDataType::forEachSubcolumn. The substream tree doubles per nesting level and the walk repeats per column, table expression and scope, while the insert can only fire when prefix plus subcolumn name has exactly as many parts as the unresolved identifier. Separately, the walk observed no time limit at all: git grep -rln "checkTimeLimit|CancellationChecker" src/Analyzer/ returns nothing, so a query ran past max_execution_time and past its own cancellation. This corrects the reported reading: the sink is the analyzer, not the serialization pool's mutex.
c Fix matches root cause The early return removes exactly the work whose result the existing parts-count filter already discards, and the poll supplies the missing checkpoint. The poll checks the query's deadline (QueryStatus::checkTimeLimit), not merely whether something already marked it cancelled, because two supported configurations never mark it: timeout_overflow_mode = 'break' (the deadline thread calls checkTimeLimit rather than cancelQuery, and that returns false under break without marking anything) and clickhouse-local (no deadline thread is started at all). Honouring the limit in one mode but not the other would have been a partial fix. No widened bound, no reduced dataset, no skipped test, no guard at the symptom site. IDataType, ISerialization and the serializers are untouched.
d Test intent preserved, new test added New stateless test with seven assertions, each pinned by a mutant. No existing test weakened or removed. 02476_analyzer_identifier_hints, which already asserts hint text on this exact path, passes 3 of 3 in isolation on the fix. The hint assertion deliberately avoids two equidistant candidates, whose winner would otherwise depend on hash iteration order. Every statement that depends on the walk pins enable_analyzer = 1, since only the new analyzer collects hints this way: on a server whose default profile sets allow_experimental_analyzer = 0 the pinned test passes 3 of 3, while the unpinned form fails there with five of the seven reference lines diverging, so the pin is demonstrably what keeps the assertions non-vacuous.
e Demonstrated in both directions On real servers, with every arm asserting SELECT lower(buildId()) against readelf -n before any verdict. Depth 12, two-part identifier, max_execution_time = 0.001: break mode ran to Code: 47 in 0.67 s ignoring the limit before, and reports Code: 159 TIMEOUT_EXCEEDED in 0.20 s after; clickhouse-local took 1.92 s and Code: 47 before, and reports Code: 159 in 1.26 s after; the default throw mode on a server is byte-unchanged at Code: 159 in 0.19 s. Depth 10 against the pre-fix snapshot: Code: 47 after 115.86 / 116.11 / 116.41 s with the limit ignored, versus Code: 159 after 1.20 / 1.28 / 1.25 s, 3 of 3. Without a limit the query still returns the correct UNKNOWN_IDENTIFIER, and KILL QUERY still reports QUERY_WAS_CANCELLED, 8 of 8, never a timeout.
f General across code paths The early return and the poll both live in the callee, so all seven call sites are covered without editing any: four in collectTableExpressionValidIdentifiers (prefixes of 1, 2, 2 and 3 parts), two in collectScopeValidIdentifiers (1 part each) and IdentifierResolver.cpp (1 part). The other six IDataType::forEachSubcolumn callers are unaffected by construction, since no shared file changed. The deadline predicate follows five existing in-tree users of the same pattern (FunctionVariantAdaptor.cpp, FunctionStringReplace.h, geohashesInBox.cpp, FunctionBaseXXConversion.h, arrayFold.cpp).
g General across inputs Two matrices, both byte-identical before and after: 15 shapes covering all four prefix lengths plus JSON, Array(Tuple), Map, Nullable, Variant, LowCardinality, nested Tuple and an alias expression, with 12 of the 15 carrying a real hint so the matrix is not vacuous; and 11 type wrappers including LowCardinality(Nullable) and a three-level nested Tuple, 8 carrying a real hint. Boundary shapes covered: one-part, four-part and over-long identifiers; no limit, throw mode, break mode, and KILL QUERY.
h Backward compatible No new or changed setting, no default change and no serialization format change, so no SettingsChangesHistory.cpp entry is owed. The throw-mode and KILL QUERY messages are byte-unchanged, which the arms and matrices above assert; the only new message is on the break path, which previously produced no timeout at all, so nothing that worked before behaves differently. The max_execution_time documentation asserted that a query can never stop during analysis, so one sentence of it is amended.
i Invariants and contracts preserved The process list entry is resolved from the executing thread rather than captured, and a null entry keeps the previous behaviour exactly, so contexts without one are unaffected. It is resolved once per call rather than once per substream, so it does not cost back what the early return saves. checkTimeLimit calls throwProperExceptionIfNeeded first, so the previous coverage is a strict subset of the new coverage and no exception type changes. A throw from the callback unwinds through enumerateStreams, whose EnumerateStreamsSettings is a local in IDataType::forEachSubcolumn and dies with the frame, so no shared state is left inconsistent. The throw escapes a path that was already about to throw UNKNOWN_IDENTIFIER; the single site that catches that code, QueryAnalyzer.cpp for table-function arguments, matches on UNKNOWN_IDENTIFIER specifically and rethrows anything else.

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.

mutant verdict reddens
shipped fix OK nothing
revert the early return only FAIL the vacuous-walk assertion, and nothing else
revert both deadline checks FAIL all three limit assertions and the KILL QUERY one
check cancellation only, not the deadline FAIL exactly the break-mode and clickhouse-local assertions
skip the walk unconditionally FAIL the alias-expression hint, and nothing else
replace either side of the comparison with a constant OK nothing, by construction

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 no-random-settings opt-out.

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 long, no-flaky-check or no-random-* tag.

@groeneai

groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator Author

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 max_execution_time and past its own cancellation. The fix returns early where the walk provably cannot contribute a hint, and polls QueryStatus::checkTimeLimit in the walk that remains. The only other file is a one-sentence amendment to the max_execution_time doc string.

@PedroTadim PedroTadim self-assigned this Aug 9, 2026
@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Aug 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [21ed70f]

Summary: ❌

job_name test_name status info comment
AST fuzzer (amd_debug, targeted) FAIL
Logical error: Reading from materialized CTE 'A' before its materialization completed - DelayedPortsProcessor gate is missing in the query plan (STID: 2467-2c2d) FAIL cidb
Stress test (amd_tsan) FAIL
Hung check failed, possible deadlock found FAIL cidb

AI Review

Summary

This PR adds max_execution_time polling to the analyzer's typo-correction subcolumn walk, skips walks that cannot contribute any hint, updates the max_execution_time setting note, and adds a targeted stateless regression test. I did not find a correctness, compatibility, or evidence gap in the current diff after checking the touched analyzer paths, the existing PR discussion, and the current all-green CI for PR #113996.

Final Verdict

✅ No findings.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.70% 86.70% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 79.00% 79.00% +0.00%

Changed lines: Changed C/C++ lines covered: 20/21 (95.24%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 9, 2026
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.
@clickhouse-gh

clickhouse-gh Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 21ed70f85 with master 3cf74b5e9 (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
Binary Master PR Δ
programs/clickhouse-stripped 691.01 MiB 688.02 MiB -2.99 MiB (-0.43%)

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 units

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

Job report

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.
@groeneai

groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator Author

cbe01fb fixes the flaky-check failure in all four sanitizer jobs. Two problems, both in the test.

The first assertion could not detect a regression. It asserted UNKNOWN_IDENTIFIER for a one-part identifier under max_execution_time = 10. Before this fix the walk ignored the limit, so it returned UNKNOWN_IDENTIFIER too, just slowly: pre-fix and post-fix builds give identical output in all 8 cells at depths 10/12 under limits 10 s/300 s. On the flaky-check hosts the assumed inequality inverted (elapsed 10000.069 ms; 12 rows at 12.2-13.7 s where the query costs 1.4 s locally). Removed.

The rest was cost. CREATE TABLE walks the same tree via ColumnsDescription::addSubcolumns, which this fix does not bound: 51-62 s per fixture in CI vs 0.9 s locally. Runtime was 132 s debug, 223 s ASan, 374 s MSan (client receive timeout), 600 s TSan (runner kill), against a 180 s cap. Nesting 12 to 10 cuts the type string 155,615 to 38,879 bytes. Depth 10 is the floor: at 9 the walk is too short for the KILL QUERY arm to land (3 of 5). Now 20 of 20 in 2.1 s, and still fails 3 of 3 pre-fix, reddening all four remaining lines.

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, max_memory_usage matches on both sides in 8 of 8 cells, and the guard is hint-set-preserving by construction, so no output oracle exists; a timing arm needs guarded < limit < unguarded, and the loaded host moves the guarded side to 12-14 s while depth 13 hits MEMORY_LIMIT_EXCEEDED. The timeout and KILL QUERY arms still pin the behaviour the changelog claims. Happy to add a C++ unit test over the enumeration hook if you want that guard covered; it is performance-only, so it is not reachable from SQL.

@groeneai

groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - cbe01fb

Both reds trace to one trunk bug outside this change. Of 175 jobs, 2 failed and 152 were dropped.

Check / test Reason Owner / fixing PR
Fast test / 00980_merge_alter_settings TOO_MANY_PARTS on an insert into an empty table with parts_to_throw_insert = 1 #113045 (external, open)
Finish Workflow / Post Hooks cascade of the above: the three Bugfix validation jobs that would have validated the fix list fast_test in needs, so they were dropped one second after the Fast test failure and the hook counted passed: none #113045 (external, open)

#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 Skipped, no integration tests updates here and did so on the previous head too, so they are not part of the cascade.

Nothing here is reachable from this change: the diff is four files, none of them 00980, and the Settings.cpp part is a documentation string. The gate already passed on the previous head 61829045e9de183, where Fast test was green, both functional Bugfix validation jobs reported success on 04824_typo_correction_nested_type_cancellation, and Post Hooks was OK. I also re-measured the current test content against a master binary: it reports UNKNOWN_IDENTIFIER in 7.6 s there and TIMEOUT_EXCEEDED in 0.5 s with the fix, 12 runs out of 12 across both overflow modes, so it still discriminates after the last round shrank it.

I am not pushing anything for this, since retriggering would only re-run against the same trunk bug.

PedroTadim and others added 2 commits August 10, 2026 18:00
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.
@groeneai

Copy link
Copy Markdown
Collaborator Author

21ed70f fixes the flaky-check failure. The test was over the 180s per-test budget on all four sanitizer flavours (181-600s in CI).

The cost was the fixture, not the assertions. In the failing job's query_log, CREATE TABLE t_04824 accounted for 157s of the 169s each copy spent: ColumnsDescription walks the same exponential substream tree this PR 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. The one arm that asserts a hint over plain column names still uses a table, with a shallow type.

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 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 a pre-fix master binary the test still fails and reddens all four discriminating lines, so it has not been hollowed out.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 21ed70f

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
AST fuzzer (amd_debug, targeted) / Reading from materialized CTE ... DelayedPortsProcessor gate is missing (STID 2467-2c2d) logical error, targeted fuzzer mutated a query into EXPLAIN ANALYZE over nested materialized CTEs #111194 (mine, open)
Stress test (amd_tsan) / Hung check failed, possible deadlock found cancelled DROP TABLE prometheus stuck 1018s with is_cancelled=1, convoying the database teardown behind the DDL guard a fix task is created (investigating at full effort - fixing PR link to follow on this PR)
Sync - CH Inc sync (private, not actionable by me)

175 jobs, 0 incomplete, 0 dropped, 155 green. Config Workflow and Finish Workflow both
succeeded, so this is a genuine finished run rather than a dropped matrix.

Session id: cron:our-pr-ci-monitor:20260811-043000

@groeneai

Copy link
Copy Markdown
Collaborator Author

Fixing PR for the hung DROP TABLE of a TimeSeries table (waitTableFinallyDropped): #114302 (external, open).

@PedroTadim PedroTadim closed this Aug 12, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

@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 src/Analyzer/Resolve/TypoCorrection.cpp, which is reached from IdentifierResolver and QueryAnalyzer and from nowhere else, so it never runs inside IFunction::executeImpl. The reported hang happens during analysis with read_rows: 0, before any function executes, so checking the cancellation bit once before IFunction::executeImpl does not bound it.

More useful is something I measured after the close, which makes the time-limit check the wrong headline for this defect. On master 068ec6d the walk produces no hints at all on the pathological input, so the entire cost is discarded work:

  • SELECT a.nosuchcolumn FROM (SELECT CAST([], '<10 nested levels of Array(Map(String, Tuple(a, b)))>') AS c) AS a with max_execution_time = 0.001 reports UNKNOWN_IDENTIFIER, ignoring the limit, and prints no Maybe you meant.
  • The cost doubles per nesting level: 0.55, 0.83, 1.50, 2.98, 6.01 seconds at depths 10 to 14.
  • Control: a shallow case on the same binary still prints Maybe you meant: ['x.aa'], so the absence above is the walk contributing nothing rather than hints being disabled.

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.

@groeneai groeneai added the groeneai-origin-request PR origin: a maintainer pinged or directed groeneai label Aug 19, 2026
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 groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants