DBDB.io The Encyclopedia of Database Systems · Est. 2017
Database of Databases

Database Entry

TiDB


TiDB is an open source distributed scalable Hybrid Transactional and Analytical Processing (HTAP) database built by PingCAP. The goal of TiDB is to serve as a one-stop solution for both OLTP (Online Transactional Processing) and OLAP (Online Analytical Processing).[01]

Source Code
https://github.com/pingcap/tidb[02]
Developer
Country of Origin
CN
Start Year
2016 [15]
Project Types
Commercial, Open Source
Written in
Go
Supported Languages
C, C++, Cocoa, D, Eiffel, Erlang, Go, Haskell, Java, Lua, Ocaml, Perl, PHP, Python, Ruby, Scheme, SQL, Tcl
Derived From
TiKV
Compatible With
MySQL
Operating System
Linux
License
Apache v2

Database Entry

TiDB


TiDB is an open source distributed scalable Hybrid Transactional and Analytical Processing (HTAP) database built by PingCAP. The goal of TiDB is to serve as a one-stop solution for both OLTP (Online Transactional Processing) and OLAP (Online Analytical Processing).[01]

History[04]


TiDB is inspired by the design of Google F1 and Google Spanner, and it supports features like infinite horizontal scalability, strong consistency, and high availability.

Checkpoints[05]


TiDB provides consistent checkpoint without blocking. Users can start a transaction and dump all the data from any table. TiDB also provides a way to get consistent data from history versions. The tidb_snapshot system variable is introduced to support reading history data.

Concurrency Control[06]


The history versions of data are kept because each update / removal creates a new version of the data object instead of updating / removing the data object in-place. But not all the versions are kept. If the versions are older than a specific time, they will be removed completely to reduce the storage occupancy and the performance overhead caused by too many history versions. In TiDB, Garbage Collection (GC) runs periodically to remove the obsolete data versions. GC is triggered in the following way: There is a gc_worker goroutine running in the background of each TiDB server. In a cluster with multiple TiDB servers, one of the gc_worker goroutines will be automatically selected to be the leader. The leader is responsible for maintaining the GC state and sends GC commands to each TiKV region leader.

Data Model[07]


TiDB uses TiKV as the underlying data storage engine, which uses the Key-Value model and can be seen as a huge distributed ordered Map that is of high performance and reliability.

Indexes[08]


TiDB uses TiKV, an open source distributed transactional key-value store, to implement the index. Logically, TiKV could be used as a giant ordered map. For a single instance of TiKV, TiDB uses RocksDB as the embedded Key-Value engine. RocksDB uses LSM-tree as its storage data structure.

Isolation Levels[09]


TiDB uses the Percolator transaction model. A global read timestamp is obtained when the transaction is started, and a global commit timestamp is obtained when the transaction is committed. The execution order of transactions is confirmed based on the timestamps. Repeatable Read is the default transaction isolation level in TiDB.

Joins[10]


TiDB’s SQL layer currently supports 3 types of distributed join: hash join, sort merge join (when the optimizer thinks even the smallest table is too large to fit in memory and the predicates contain indexed columns, the optimizer would choose sort merge join) and index lookup join.

Logging[11]


TiDB uses the Raft consensus algorithm for replication, so it has Raft log. And TiDB also provides binlog to export data from the TiDB cluster.

Query Compilation


Query Execution


In most cases, TiDB processes data tuple by tuple. But in some cases, TiDB uses vectorized execution.

Query Interface[12]


SQL

TiDB supports SQL and MySQL dialect.

Storage Architecture[08]


Any durable storage engine stores data on disk and TiKV is no exception. But TiKV doesn’t write data to disk directly. Instead, it stores data in RocksDB and then RocksDB is responsible for the data storage. The reason is that it costs a lot to develop a standalone storage engine, especially a high-performance standalone engine.

Storage Model[08]


TiDB stores its data in the distributed key-value storage engine, TiKV.

Stored Procedures[13]


System Architecture[14]


The TiDB cluster has three components: the TiDB server, the PD server, and the TiKV server.
- The TiDB server is stateless. It does not store data and it is for computing only. TiDB is horizontally scalable and provides the unified interface to the outside through the load balancing components such as Linux Virtual Server (LVS), HAProxy, or F5.
- The Placement Driver (PD) server is the managing component of the entire cluster.
- The TiKV server is responsible for storing data. From an external view, TiKV is a distributed transactional Key-Value storage engine. Region is the basic unit to store data. Each Region stores the data for a particular Key Range which is a left-closed and right-open interval from StartKey to EndKey. There are multiple Regions in each TiKV node. TiKV uses the Raft protocol for replication to ensure the data consistency and disaster recovery. The replicas of the same Region on different nodes compose a Raft Group. The load balancing of the data among different TiKV nodes are scheduled by PD. Region is also the basic unit for scheduling the load balance.

Views[13]


Derivative Systems
PR PranaDB

Citations

15 sources
  1. Database for AI Agents | TiDB Distributed SQL | TiDB pingcap.com
  2. GitHub - pingcap/tidb: TiDB is built for agentic workloads that grow unpredictably, with ACID guarantees and native support for transactions, analytics, and vector search. No data silos. No noisy neighbors. No infrastructure ceiling. · GitHub github.com
  3. https://www.pingcap.com/docs pingcap.com Dead — Check Archive
  4. https://www.pingcap.com/docs/overview#tidb-introduction pingcap.com Dead — Check Archive
  5. https://www.pingcap.com/docs/op-guide/history-read#reading-data-from-history-versions pingcap.com Dead — Check Archive
  6. Rust in TiKV | TiDB pingcap.com
  7. TiDB Internal (I) - Data Storage | TiDB pingcap.com
  8. TiDB Internal (I) - Data Storage | TiDB pingcap.com
  9. https://www.pingcap.com/docs/sql/transaction-isolation#tidb-transaction-isolation-levels pingcap.com Dead — Check Archive
  10. Free e-Learning | Introduction to TiDB pingcap.com
  11. https://www.pingcap.com/docs/tools/tidb-binlog-kafka#tidb-binlog-user-guide pingcap.com Dead — Check Archive
  12. https://www.pingcap.com/docs/sql/mysql-compatibility#compatibility-with-mysql pingcap.com Dead — Check Archive
  13. https://www.pingcap.com/docs/sql/mysql-compatibility#unsupported-features pingcap.com Dead — Check Archive
  14. https://www.pingcap.com/docs/overview#tidb-architecture pingcap.com Dead — Check Archive
  15. https://www.pingcap.com/docs/releases/rc1 pingcap.com Dead — Check Archive
Revision #9 Last Updated: