Repository navigation
Fix sporadic Values-template failure with synthesized literals - #110637
alexey-milovidov merged 1 commit into
Conversation
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-3:20260716-033400 |
|
cc @alexey-milovidov @Avogar for review. Parser/Values-format fix: a literal synthesized by |
|
Workflow [PR], commit [1a9b25f] Summary: ✅
AI ReviewSummaryThis PR fixes the stale-address Final Verdict✅ No new review findings. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 198/203 (97.54%) · Uncovered code |
CI finish ledger — a5aa67bEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
Session id: cron:our-pr-ci-monitor:20260716-110000 |
|
Good catch — widened to enforce the invariant centrally rather than erasing at each synthesis site. Root of the hazard: the token map is keyed by raw Instead the validity now lives on the object:
Any parser-synthesized literal (Tuple/Array slow path, EXTRACT injects, casts, global vars, Test: extended |
CI finish ledger — b6b50c6Every failure below has an owner (a fixing PR). None is PR-caused (this PR only touches the Values-template literal-token parser path).
Session id: cron:our-pr-ci-monitor:20260716-173000 |
|
Merged master (the branch was 7788 commits behind) and addressed what the merge turned up. Two conflicts, both where master has since reworked this area:
Master also landed Three things changed beyond the merge, from reviewing it:
Known gap, stated plainly: the tests pin WHICH literals carry the bit - each arm reddens under |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 140/144 (97.22%) · Uncovered code |
CI finish ledger — e3f65c7Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task 174 check-runs, 0 incomplete (paginated check-runs API),
Session id: cron:our-pr-ci-monitor:20260802-000000 |
|
Fixed the The job builds a "before" binary from the merge base with only the unit-test files overlaid, so the test has to compile without the fix. Twelve assertions called A compile failure is reported as inconclusive, so the check went red. Report The test now dispatches on the available API with a The negative cases also no longer wait for the allocator to hand out a freed address, they stage the dead span at the literal's own address, so they hold that state deterministically instead of by chance. Verified in both directions on the merge base
So the job now reaches its reproduction path instead of stopping at the build. Non-vacuity re-checked in both directions: forcing The |
|
Correct, and I could not close this before. Now I can, so I did: The blocker I hit in earlier rounds was that I believed template deduction was
The mutation you predicted now reddens. Deleting the guard at
Non-vacuity in the other direction too: removing the The stale entry is staged at the literal's own address rather than waited for, so nothing The file uses only APIs that predate this change, so it still compiles against the merge |
CI finish ledger - a4351e7Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
174 check-runs, 0 incomplete, The test fails on the first Why it is not caused by this pull request, from the job's own server log
The write fan-out for plain Session id: cron:clickhouse-maint-slot-12:20260802-031600 |
Fixing-PR link for the
|
|
@groeneai fix the Fast test failure |
`ConstantExpressionTemplate` looks token spans up in `Expected::literal_token_map`,
which is keyed by raw `ASTLiteral *`. Only literals the parser actually tokenized
from the query are recorded there, but the key is a bare pointer: once a recorded
literal is freed, a literal the parser synthesizes later can be allocated at that
same address and silently inherit the dead entry. The consumer then splices a
placeholder over a span of the query that has nothing to do with that literal, so
a type argument or an aggregate-state name is replaced by the placeholder and the
INSERT fails.
That is the sporadic
Cannot parse string 'sumState' as UInt64: syntax error at begin of string
... While executing ValuesBlockInputFormat
failure of `03443_projection_sparse` and friends: the `'0'` literal synthesized by
`ParserCastOperator` for `0::UInt64` in `initializeAggregation('sumState', 0::UInt64)`
inherited the span of the discarded `'sumState'` string-literal probe. It is
sporadic because it needs the allocator to hand back a freed literal's address.
Add a `has_token_info` bit to `ASTLiteral`, set only by `recordLiteralTokens`, and
have the consumers ignore any map entry for a literal that does not carry it. The
bit is cleared on copy and copy-assignment, and therefore on `clone`, since a copy
lives at an address the map knows nothing about.
Keying the guard on the literal itself rather than on call sites covers every
synthesized literal, not just the two `ExpressionElementParsers` ones: the
`Tuple`/`Array` slow path and the numeric operands injected into the
`plus`/`minus`/`intDiv` chains for `EXTRACT(...)` also build final literals without
recording token info, and `highlightRegexps` reads the same map.
Tests: `gtest_literal_token_map` pins which `ASTLiteral` shapes set and clear the
bit; `gtest_constant_expression_template_token_guard` drives real template deduction
through `ConstantExpressionTemplate::Cache::getFromCacheOrConstruct` after staging a
stale span on a synthesized literal, and reddens if the guard is removed.
a4351e7 to
1a9b25f
Compare
|
@PedroTadim I pushed On the red you saw: it was
The owner is #113045, "Perform the What I did instead of treating a 0.06% trunk flake as a code fix: the head was 3005 This pull request has had no human review since 2026-07-16, and it is what stops the |
CI finish ledger - 1a9b25fCI is fully finished on this head and there are no failing checks.
Session id: cron:our-pr-ci-monitor:20260809-013000 |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a sporadic
Cannot parse string ... as UInt64 ... While executing ValuesBlockInputFormaterror that could occur when inserting values whose expressions contain a numeric cast such asinitializeAggregation('sumState', 0::UInt64).Description
Closes: #111970
Related: #109368
Found while investigating the sporadic failure of
03443_projection_sparsereported on #109368 (CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109368&sha=ea8c0f26f97b5a838442598c846acce74e9b3993&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20parallel%29). The same signature also hit several unrelated PRs, most recently #111589 on 2026-07-26, which is where the tracking issue #111970 comes from.Failing query:
INSERT INTO t_projection_sparse VALUES ('bb', initializeAggregation('sumState', 0::UInt64)), errorCannot parse string 'sumState' as UInt64.Root cause: the literal token map used by
ConstantExpressionTemplate(added in #93974 whenbegin/endwere removed fromASTLiteral) is keyed by rawASTLiteral *pointers, and entries of literals discarded during parser backtracking are never removed. Some parsers synthesize a literal that survives into the AST but is never tokenized, so it has no entry of its own, yet the allocator can hand it a freed address whose stale entry is still in the map. In the failing case the discarded'sumState'string-literal probe, tried byParserCastOperatorbefore it sees there is no::, left the entry that the synthesized0cast value then reused.ConstantExpressionTemplateread the stale span, positioned the placeholder over the'sumState'text, and a later row fed'sumState'into aUInt64placeholder.Fix: enforce the invariant on the object instead of at each synthesis site.
ASTLiteralgets ahas_token_infobit that is set only inrecordLiteralTokens, the single place a literal is tokenized from the query text, and both consumers of the map (ConstantExpressionTemplateand the LIKE/REGEXP highlighting) ignore a literal whose bit is unset. Address reuse is then harmless for every synthesized literal, including theTuple/Arrayslow-path nodes and the numeric operandsEXTRACTinjects intoplus/minus/intDivchains, several of which are built with no access toExpected.The failure is an allocator address-reuse race, so a deterministic SQL reproducer is not possible; a unit test asserts the invariant for the tokenized and the synthesized shapes.
Version info
26.8.1.1048(included in26.8and later)