How pingcap/tidb works
TiDB is a distributed SQL database: applications submit SQL to a server, which compiles and executes queries using distributed storage and cluster services. The tree also contains major data-movement products: Dumpling exports data, Lightning imports it, and BR backs up and restores clusters; BR’s stream commands support log-based recovery workflows. The graph follows documented architecture and sampled source where available. Several subsystem connections are documented or indicated by the tree rather than verified from unsampled call sites.
Main entry points: cmd.go BR commands · main.go TiDB server · builder.go Query executors · distsql.go Distributed SQL
Components 21
SQL serving
- TiDB server
cmd/tidb-server/main.go - SQL compiler
pkg/executor/compiler.go
Query execution
- Query executors
pkg/executor/builder.go - Window execution
pkg/executor/windows/pipelined_window.go - Distributed SQL
pkg/distsql/distsql.go
Cluster services
- Domain services
pkg/domain/domain.go - Schema management
pkg/ddl/ddl.go - Storage transitions
pkg/ddl/storage_class_transition.go
Data movement
- Dumpling exporter
dumpling/export/dump.go - Lightning importer
lightning/pkg/importer/import.go - Import service
lightning/pkg/server/lightning.go
Backup and recovery
- BR commands
br/cmd/br/cmd.go - Backup tasks
br/pkg/task/backup.go - Restore tasks
br/pkg/task/restore.go - Log stream
br/pkg/task/stream.go
Other components
- SQL clients
- Placement Director
- TiKV row store
- TiFlash column store
- Object storage
pkg/objstore/storage.go - MySQL-compatible apps
Connections 22
- SQL clients → TiDB server: send SQL
- TiDB server → SQL compiler: compile queries
- SQL compiler → Query executors: build execution
- Query executors → Window execution: run operators
- Query executors → Distributed SQL: dispatch requests
- Distributed SQL → TiKV row store: send requests
- Distributed SQL → TiFlash column store: send requests
- TiDB server → Domain services: use services
- Domain services → Schema management: manage schema
- Schema management → Placement Director: coordinate placement
- Storage transitions → TiFlash column store: observe replicas
- Dumpling exporter → MySQL-compatible apps: read SQL data
- Import service → Lightning importer: run imports
- Lightning importer → TiKV row store: import data
- BR commands → Backup tasks: dispatch backup
- BR commands → Restore tasks: dispatch restore
- BR commands → Log stream: dispatch stream
- Backup tasks → TiKV row store: read data
- Backup tasks → Object storage: write backup
- Restore tasks → Object storage: read backup
- Restore tasks → TiKV row store: restore data
- Log stream → Object storage: store stream data