# Modules Related to SQL Reads and Writes

![left](./student-guide/diagram/ModulesSupportSQLOperations_aa_002_20220509.png)

------------------------------------------------------------
The thread pool module related to SQL read/write is introduced below. As for the SQL reads and writes process, we will introduce it in detail in "Lesson 05 TiDB Database SQL Execution Flow". Here we explain the role of the relevant module.

1. Executor module
Execution begins according to the tree execution plan generated by Compile, and each layer calls the methods of the next layer to obtain the results.

2. DistSql module
  In order to avoid complex logic coupling with SQL layer, TiDB abstracts a unified distributed query interface layer, DistSQL module.
      The DistSQL module is a layer of abstraction between TiDB Server and Coprocessor. It encapsulates the lower Coprocessor request and provides a simple select method for the upper layer. Performs a single-table calculation task. The top-level SQL statement may contain complex operators such as JOIN and SUBQUERY, involving many tables, while DistSQL only involves data from a single table. A DistSQL request involves multiple Regions, and we want to execute a Coprocessor request once for each Region involved.

3. TiKV Client Module
It is mainly responsible for sending reads and writes requests to the TiKV module. The first type is raw KV request, which is a simple request to obtain a single row of data, such as an equivalent query based on a primary key index or a unique index. The second type is Coprocessor Request, which requires that the computation also be pushed down to TiKV's Coprocessor framework, such as filtering, aggregation, or column projection, etc.

4. Transaction module
The processing of transaction is mainly done in this module, including two-stage commit, pessimistic lock/optimistic optimistic locking management, etc.

5. KV module
Including all transaction-related request to TiKV is done by this KV module, for example, kv get and batch get.

6. PD Client Module
This module is responsible for all PD-related request.













