# Parsing and Compiling SQL Statements: `Compiler`

![`smart`](CompilingProcess_aa_002_20220509.png)

------------------------------------------------------------
After the SQL statement is parsed, the AST syntax tree is generated and passed to the `Compiler` module. The `Compiler` module performs the following tasks:

- Semantic checks and name bindings.

- Performs the logical optimization. The logical optimization rules of TiDB mainly includes column pruning, maximum and minimum elimination, projection elimination, predicate push down, subquery de-correlation, outer join elimination, aggregation elimination, etc. More details are described in the section on query optimization.

- Performs the physical optimization. Physical optimization is based on logical optimization output, considers the distribution of data and decides how to select physical operators. Select the optimal execution path, a process that depends on statistics. The physical optimization mainly includes techniques such as join methods, table join order, and sorting. More details are described in the section on query optimization. Additionally, physical optimization requires querying the metadata of the table (metadata information is also required for semantic checking) and statistics, and the metadata and statistics of the table can be stored in the cache of the TiDB server to improve performance.