clickhouse/clickhouse
Query pipeline
This subsystem turns a SQL string into a stream of column chunks. It spans five directories under src/:
| Directory | Stage | Page |
|---|---|---|
src/Parsers/ |
SQL → AST | Parsers |
src/Analyzer/ |
AST → QueryTree |
Analyzer |
src/Planner/ |
QueryTree → QueryPlan |
Planner |
src/Interpreters/ |
DDL, joins, aggregation, context, the legacy interpreter | Interpreters |
src/Processors/ + src/QueryPipeline/ |
The executor | Processors |
graph LR
SQL[SQL string] --> Parsers
Parsers[Parsers<br/>AST] --> Analyzer
Analyzer[Analyzer<br/>QueryTree] --> Planner
Planner[Planner<br/>QueryPlan] --> Pipeline
Pipeline[QueryPipeline<br/>Processor graph] --> Exec
Exec[PipelineExecutor<br/>thread pool] --> Out[Chunk stream]
Interp[Interpreters<br/>DDL + helpers] -.shared services.- Analyzer
Interp -.shared services.- Planner
Interp -.shared services.- PipelineWhy the split
Historically ClickHouse went straight from AST to execution inside InterpreterSelectQuery. That worked but accumulated awkward edge cases in name resolution, subqueries, and view rewrites. In 2022 the project introduced a typed intermediate representation — the QueryTree — and a dedicated Planner. Both paths still exist; the analyzer is the default (enable_analyzer=1) and the legacy interpreter still handles a few corners and DDL queries.
Data exchange
- An
ASTis a pointer-rich tree with no types attached. Seesrc/Parsers/IAST.h. - A
QueryTreeis a typed, semantically-resolved tree. Seesrc/Analyzer/IQueryTreeNode.h. - A
QueryPlanis a tree of logical steps. Seesrc/Processors/QueryPlan/IQueryPlanStep.h. - A
QueryPipelineis a graph of physical processors. Seesrc/QueryPipeline/QueryPipeline.h.
Every transition is in principle independent: you can stop after parsing (EXPLAIN AST), after analysis (EXPLAIN QUERY TREE), after planning (EXPLAIN PLAN), or after pipeline construction (EXPLAIN PIPELINE).
Recommended reading order
Related pages
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.