Repository navigation
Docs: Add system.statements with embedded statement docs - #115341
Conversation
Introduce `StatementFactory`, a global singleton which stores the name of every SQL statement of ClickHouse along with its syntax, description, examples, parent statement and related statements. It is a much simpler registry than `FunctionFactory`: statements are not objects that can be created, so it stores documentation only. The documentation is expressed with the existing `Documentation` struct, which is already used for database engines, data types and other uniform components of the system. The documentation of a statement is registered by the parser which parses that statement, so that it lives next to the code implementing the syntax it describes. The registration mechanism mirrors `REGISTER_FUNCTION`: a `REGISTER_STATEMENTS` macro fills a static register map, and `registerStatements` runs all the registration functions once at startup, next to `registerFunctions`. `system.statements` exposes the registry with the columns `name`, `syntax`, `description`, `examples`, `parent_statement` and `related_information`. All 99 statements documented under `docs/reference/statements/` are embedded in their respective parsers, one statement per documentation page, with `parent_statement` reproducing the hierarchy of the documentation, e.g. `WHERE` is a part of `SELECT` and `ALTER TABLE ... UPDATE` is a part of `ALTER`. The landing page listing the statements is not a statement, and the pages under `create/dictionary/` document the configuration of dictionaries rather than statements - they are already exposed by `system.dictionary_sources` and `system.dictionary_layouts` - so both are not registered. The documentation page of the new system table is generated from the column comments by `utils/generate-system-tables-docs`, therefore it is not added here. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [ecf2f15] Summary: ✅
AI ReviewSummaryThis PR adds embedded SQL-statement documentation plus the new Findings
Final VerdictChanges requested. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 2161/2162 (99.95%) · Uncovered code |
`StatementFactory` stored a `StatementDocumentation`, which was a `Documentation` plus a `parent` string, and `registerStatement` took the parent as a separate argument. Add a `parent` member to `Documentation` instead (defaulting to an empty string), remove `StatementDocumentation`, and let the registry store `Documentation` directly. The registration sites now set `.parent` in the documentation literal. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Refactor `StatementFactory` to the interface the other documented component factories expose (see `DictionaryFactory`): `getAllRegisteredNames` and `getDocumentation` replace the `getAllStatements` accessor of the internal map. With that interface, statements are collected by `system.documentation` like every other kind of documented component, as the new entity type `Statement`. `system.statements` remains the per-kind table, the same way functions, formats and settings have theirs. The rendered Markdown of a `Documentation` now also names the enclosing component (`**Part of:**`), which for statements is the parent statement, e.g. the `WHERE` clause is a part of `SELECT`. The `Columns` section of the documentation page of `system.documentation` is autogenerated from the column comments, so the new value of the `type` enum is not added to it here. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Replace the `REGISTER_STATEMENTS` macro and the static register map it filled by explicit registration functions, one per parser, in the same way table functions are registered (see `registerTableFunctionRemote`): - `registerStatementSelect`, `registerStatementAlter`, ... are defined in the `.cpp` file of the respective parser, next to the syntax they document, and declared in the new `src/Parsers/registerStatements.h`; - `registerStatements` calls all of them. The registration is now explicit and does not depend on static initializers, which the linker is free to drop. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
6e7e5ee to
b1c19b1
Compare
Every other system table which exposes the related components of the embedded documentation (`system.formats`, `system.table_engines`, `system.data_type_families`, and the others) names that column `related`; `system.statements` was the only exception. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Inline the usage examples of every statement into its description, as Markdown, in the same shape they were rendered in before, and drop the `examples` column of `system.statements`. The description of a statement is now the complete prose documentation of that statement. As a consequence, `system.documentation` renders a statement as the description (including the examples) followed by the sections composed from the structured fields, so the examples now come before the syntax. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Review feedback: #115341 (comment) PR: #115341
Review feedback: #115341 (comment) PR: #115341
Blargian
left a comment
There was a problem hiding this comment.
LGTM. Will follow up with a PR to integrate system.statements, system.dictionary_sources and system.dictionary_layouts into the existing docs pipeline (nightly job to update markdown between AUTOGENERATED tags). That should give us something like 98% of the existing reference docs generated from source. From there I've got something in the works for how we can generate these docs without the need for the markdown copies, and with versioning.
system.statements with embedded statement docssystem.statements with embedded statement docs
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. Object file sizes250 object files changed (+709.21 KiB total), 3 added.
737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units1117 translation units recompiled, 7703 s compile time in total, 1114 of them have a recent master baseline. Median compile-time ratio to the baselines is ×0.94 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
|
Thanks for implementing! I always wanted this feature.
@rschu1ze, Can we accommodate it inside |
|
@alexey-milovidov I think yes and I can do it, but let's wait for #115609 first to avoid merge conflicts. |
This PR was implemented by an ask from the documentation team which likes to generate all reference documentation, including statement documentation, from
system.documentation.This PR
StatementFactorywhose only purpose is to store statement documentation,system.statements, andsystem.documentation.Existing docs from
docs/reference/statementsare copypasted into their respective parser classes. The markdown files will be removed at some later point (the doc generation pipeline needs to be updated).Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The documentation of all SQL statements (e.g. name, syntax, description, examples) can now be retrieved from system table
system.statements.Workflow [PR]
Sync PR [sync-upstream/pr/115341]