# Query Processing Workflow
![`smart`](TiDBQueryProcessing01_aa_004_20230912.png)
------------------------------------------------------------------------------
In the slide, on the far left, the client sends a SQL statement to the protocol layer of the TiDB server. This layer is responsible for managing the connection between the TiDB Server and the client, receiving SQL statements, and returning data to the client. 

To the right of the protocol layer is the Optimizer layer of the TiDB Server, which processes SQL statements. The process is as follows:

1. The SQL statement reaches the SQL optimizer through the `protocol layer` and is initially parsed into an `Abstract Syntax Tree` (AST).
2. `Pre-Process` checks for `Point Get`. If identified as a `Point Get`, subsequent optimization steps can be bypassed, and the process proceeds directly to the `SQL Executor`.
3. If it is not a `Point Get`, the AST goes to the `Logical Transformation`, where the SQL is logically rewritten according to certain rules.
4. The AST that has gone through `Logical Transformation` will undergo `Cost-Based Optimization`.
5. During `Cost-Based Optimization`, the optimizer utilizes statistics to select specific operators and finally producing a physically executable physical execution plan.
6. The generated physical execution plan is sent to the `SQL Executor` of the TiDB database for execution.
7. Unlike traditional databases, TiDB databases requires pushing down the execution plan to various TiKV nodes to read and write data.