Skip to content

Docs: Add system.statements with embedded statement docs - #115341

Merged
Blargian merged 13 commits into
masterfrom
system-statements
Aug 24, 2026
Merged

Blargian merged 13 commits into
masterfrom
system-statements

Conversation

@rschu1ze

@rschu1ze rschu1ze commented Aug 18, 2026 •

Copy link
Copy Markdown
Member

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

  • adds a class StatementFactory whose only purpose is to store statement documentation,
  • adds a new system table system.statements, and
  • extends existing system table system.documentation.

Existing docs from docs/reference/statements are 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):

  • Improvement

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]

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]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ecf2f15]

Summary: ✅


AI Review

Summary

This PR adds embedded SQL-statement documentation plus the new system.statements table and feeds the same data into system.documentation. The main remaining issue is that the new registry is still not exhaustive for the ALTER VIEW surface, so the feature currently ships an incomplete statement set while presenting it as complete.

Findings

⚠️ Majors

  • [src/Parsers/ParserAlterQuery.cpp:1648] The new statement registry misses existing ALTER VIEW forms. ParserAlterQuery already supports ALTER TABLE ... MODIFY REFRESH and ALTER TABLE ... MODIFY SQL SECURITY, and the docs tree already documents both (docs/reference/statements/alter/view.mdx, docs/reference/statements/create/view.mdx), but neither variant is registered in StatementFactory. That makes system.statements underreport the language surface and the new snapshot test in 04926_system_statements blesses the incomplete set as if it were exhaustive.
    Suggested fix: register both variants alongside ALTER TABLE ... MODIFY QUERY, then update the snapshot/reference to include the new names.
Final Verdict

Changes requested.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.90% 86.90% +0.00%
Functions 91.90% 92.00% +0.10%
Branches 79.30% 79.30% +0.00%

Changed lines: Changed C/C++ lines covered: 2161/2162 (99.95%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Aug 18, 2026
rschu1ze and others added 4 commits August 18, 2026 19:48
`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]>
rschu1ze and others added 3 commits August 18, 2026 21:08
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]>
@rschu1ze
rschu1ze marked this pull request as ready for review August 18, 2026 21:33
Comment thread src/Parsers/ASTQueryWithOnCluster.cpp Resolved
Comment thread src/Parsers/ParserAlterQuery.cpp Resolved

@Blargian Blargian left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Blargian Blargian changed the title [DRAFT] Add system.statements with embedded statement docs Docs: Add system.statements with embedded statement docs Aug 19, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing ecf2f1530 with master 64f260330 (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 702.08 MiB 699.28 MiB -2.80 MiB (-0.40%)

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 sizes

250 object files changed (+709.21 KiB total), 3 added.

Object file Master PR Δ
src/Storages/System/CMakeFiles/clickhouse_storages_system.dir/StorageSystemStatements.cpp.o new 177.32 KiB +177.32 KiB
src/Parsers/CMakeFiles/clickhouse_parsers.dir/ParserAlterQuery.cpp.o 161.96 KiB 211.55 KiB +49.59 KiB (+30.62%)
src/Parsers/CMakeFiles/clickhouse_parsers.dir/StatementFactory.cpp.o new 46.84 KiB +46.84 KiB
src/Parsers/CMakeFiles/clickhouse_parsers.dir/ParserSelectQuery.cpp.o 98.51 KiB 128.35 KiB +29.84 KiB (+30.30%)
src/Parsers/CMakeFiles/clickhouse_parsers.dir/ParserCreateQuery.cpp.o 346.00 KiB 373.43 KiB +27.43 KiB (+7.93%)

737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

1117 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.
The matched translation units cost -517.0 s (-6%) in total before that adjustment.

Job report

@clickhouse-gh

clickhouse-gh Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 34 queries analysed

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
  • StressHouse run: f33cc449-58d6-44c5-a61f-75167c91821c
  • MIRAI run: ae3e9308-367b-404f-b9b7-ba6bef8396b3
  • PR check IDs:
    • clickbench_289289_1787222641
    • clickbench_289300_1787222641
    • clickbench_289307_1787222641
    • tpch_adapted_1_official_289320_1787222641
    • tpch_adapted_1_official_289345_1787222641
    • tpch_adapted_1_official_289359_1787222641

@mintlify

mintlify Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
ClickHouse-docs 🟢 Ready View Preview Aug 22, 2026, 5:46 AM

@Blargian
Blargian added this pull request to the merge queue Aug 24, 2026
Merged via the queue into master with commit 4bc0fc8 Aug 24, 2026
176 checks passed
@Blargian
Blargian deleted the system-statements branch August 24, 2026 11:58
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 24, 2026
vitlibar pushed a commit to vitlibar/ClickHouse that referenced this pull request Aug 24, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

Thanks for implementing! I always wanted this feature.

adds a class StatementFactory

@rschu1ze, Can we accommodate it inside InterpreterFactory?

@rschu1ze

Copy link
Copy Markdown
Member Author

@alexey-milovidov I think yes and I can do it, but let's wait for #115609 first to avoid merge conflicts.

pull Bot pushed a commit to SINHASantos/ClickHouse that referenced this pull request Aug 25, 2026

This branch was successfully deployed

1 active deployment
staging - docs — ecf2f153 Deployed Aug 23, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants