# DML Statement Process Overview
![`smart`](DMLStatementWritesProcessOverview_aa_006_20220512.png)

----------------------------------------------------------------
The writing data process of DML statements can be described as:

1. TiDB server receives an SQL request from the client program.

2. TiDB server asynchronously gets the start_ts of the SQL statement, which is the TSO when the SQL statement starts.

3. TiDB server parses and compiles SQL statement and generates the execution plan.

4. TiDB server queries the metadata of tables and the location information of the regions, then execute the statement.

5. TiKV server receives a query request from TiDB server, executes it and filters data before returning the result to TiDB server.

6. TiDB server organizes the received results.

7. TiDB server performs two-phase commit to modify data and persist it, while obtaining the TSO at the time of commit, i.e. commit_ts.

8. The TiDB server returns the write data result to the client.

The fourth step can be further expanded to:

1. Get the metadata of the table to be queried.

2. Generate key range information, and get the Region information for each key range.

3. TiDB server concurrently sends query requests to the TiKV server where the Region is located according to the location information of the Region.

We can see that steps 1 ~ 6 are consistent with the process of reading data.

This diagram is a simplified process, which will be explained in the following sections.



