Repository navigation
Quote identifiers that the parser reads back as literals - #116802
Conversation
`inf`, `infinity`, `nan`, `true` and `false` are valid identifiers, but the
parser reads a bare word of any of those names back as a literal rather than an
identifier: `ParserNumber` hands a bare word to `strtod`, which accepts `inf`,
`infinity` and `nan`, and `true`/`false` are parsed as `Bool` literals.
`writeProbablyQuotedStringImpl` quoted only names that are not valid identifiers
at all, so a reference to a column with such a name was formatted unquoted and
silently turned into a constant. `null` was already rejected by
`isValidIdentifier` for the same reason.
This is not limited to the formatting consistency check of debug builds. A table
with a column named `inf` gets `ORDER BY inf` written to its metadata, and the
next server start fails to load the table, and with it the whole database:
CREATE TABLE t (`inf` Int32, x Int32) ENGINE = MergeTree ORDER BY `inf`;
-- metadata: ATTACH TABLE _ (`inf` Int32, `x` Int32) ENGINE = MergeTree ORDER BY inf
-- next start: Code: 44. DB::Exception: Sorting key cannot contain constants
Found by the AST fuzzer in `AST fuzzer (amd_debug)`, STID `1941-1bfa`, where an
`Identifier_NaN` in the sorting key came back as `Literal_Float64_nan`:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=6e6a2a508889e7e97149298d3490ac139f8ae320&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_debug%29
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [c7626bc] Summary: ✅
AI ReviewSummaryThis PR updates the generic identifier formatter so names that the expression parser reads back as literals ( Missing context / blind spots
Final Verdict✅ No blocking or major findings from code review. LLVM Coverage ReportMeasured on commit c7626bc.
Changed lines: Changed C/C++ lines covered: 12/12 (100.00%) · 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 units8 translation units recompiled, 12 s compile time in total, 8 of them have a recent master baseline. |
…arsed-as-literals
|
@alexey-milovidov — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
Related: #116645
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A column named
inf,infinity,nan,trueorfalsewas formatted without quotes, so a reference to it was read back as a constant instead of a column. A table using such a column in its sorting key had unparseable metadata written for it, and the next server start failed to load the table and with it the whole database.Description
Found by the AST fuzzer on master,
AST fuzzer (amd_debug), STID1941-1bfa:https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=6e6a2a508889e7e97149298d3490ac139f8ae320&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_debug%29
The two ASTs of the round-trip check differ in exactly one node — an identifier in the
sorting key came back as a float literal:
inf,infinity,nan,trueandfalseare valid identifiers, but the parser reads abare word of any of those names back as a literal:
ParserNumberhands a bare word tostrtod, which acceptsinf,infinityandnan, andtrue/falseare parsed asBoolliterals.
writeProbablyQuotedStringImplquoted only names that are not valid identifiersat all, so such a name was formatted unquoted and silently turned into a constant.
nullwas already rejected by
isValidIdentifierfor the same reason; this adds the remainingnames next to the keywords that are already listed there.
This is not limited to the formatting consistency check of debug builds. On a release build
the statement is accepted and the metadata written for the table cannot be parsed back:
The whole database fails to load, not just the table.
Only names that are parsed as a literal are quoted;
infx,nanxandinf_1are leftunquoted, and no function, table engine or data type family has a colliding name.
The test uses
DETACH+ATTACH, which re-reads the metadata file and so exercises thesame path as a server start. It fails before this change with the
Sorting key cannot contain constantserror above.This is the same failure class as #116645 (metadata written in a form the server cannot read
back) but a different trigger, and it is the remaining
Inconsistent AST formattingfailureon master once #116645 lands.
Workflow [PR]
Sync PR [sync-upstream/pr/116802]