# Coprocessor

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

------------------------------------------------------------
Let's take a look at the following diagram. We pushed the SQL calculation down to TiKV. This work is done by TiKV's Coprocessor component, and its workflow is as follows:

1. TiDB Server receives the query statement, analyzes the statement, calculates the physical execution plan, and then breaks down the TiKV Coprocessor request.

2. TiDB Server distributes the Coprocessor request to all relevant TiKVs according to the distribution of the data.

3. After the TiKV Server receives the Coprocessor request, it filters and aggregates the data according to the request operator, and then return it to TiDB.

4. After receiving the return results of all data, TiDB performs secondary aggregation, calculates the final result, and return it to the client.

There are currently 3 types of requests processed by the TiKV Coprocessor:

- DAG: Executes physical operators to calculate intermediate results for SQL, thereby reducing the computation and network overhead of TiDB. This is a task performed by the Coprocessor in most scenario. The physical operators currently pushdown include: TableScan, IndexScan, Selection (column filtering), limit, TopN, Aggregation, etc.

- Analyze: Analyze table data, statistics, and sample table data information, and use it by TiDB's optimizer after persistence.

- CheckSum: Checks table data for consistency check after importing data.