# TiDB Server

+ Handling client connections
+ Parse and compiling SQL statements
+ Relational and KV data transformation
+ SQL statements execution
+ Execute online DDL
+ Garbage collection

![right](./student-guide/diagram/TiDBServerSimple_aa_001_20220506.png)

------------------------------------------------------------
We will introduce the main functions and implement principles of TiDB Server in detail. Let us take a brief look at its various functions. TiDB Server itself is only responsible for the SQL computing engine and does not store data, so TiDB Server is stateless. When our system faces a large number of concurrent connections, we can load balance by adding TiDB Server to improve high concurrent processing capabilities.

1. Handling client connections
Users are authenticated by username+password, and the connected users are empowered. These tasks are mainly done by the Protocol Layer module.

2. Parse and compiling SQL statements
After listening to the SQL statement, TiDB Server parses and compiles it. During the compilation process, it optimizes and generates an execution plan. These tasks are done by the Parse and Compile modules.

3. Relational and KV data transformation
Since data is stored on TiKV in the form of key value (KV), there is a big difference between relational data (tables, indexes, and rows) and KV structures. If you want to execute SQL, you must be able to convert between relational data and KV storage.

4. SQL statements execution
According to the compiled execution plan, it is executed on TiKV in batches. The data is read by the Executor module and the DistSq module, and the transaction-related operations are completed by the Transaction module and the KV module.

5. Execution of online DDL
The TiDB database implement the function that DDL operations do not lock tables. It is done by the schema load module, the worker module, and the start job module.

6. Garbage collection
The GC backend module is responsible for recovering data from old versions that have expired, and this part will be explained in the TiKV course.


