Issues with SQL Parsing and Compilation: Which One to Choose

This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: SQL解析和编译的问题,这个选啥

| username: hacker_77powerful

Regarding the parsing and compilation of SQL in the TiDB database, which of the following statements are correct? (Please select 2 items)
A. The product of the compile operation is the AST syntax tree
B. Logical optimization occurs during the Compile operation
C. The TSO acquisition of the SQL statement is generally completed before the parsing and compilation operations
D. Physical optimization occurs during the Compile operation

| username: 小龙虾爱大龙虾 | Original post link

A. The product of parsing is the AST (Abstract Syntax Tree), so A is :x:.
B. *Compile stage: Based on the AST and statistical information output from the parse stage, an execution plan is compiled. The main steps of the entire process are logical optimization and physical optimization. The former optimizes the query plan through some rules, such as column pruning based on relational algebra, while the latter estimates the cost of the execution plan through statistical information and a cost-based optimizer, and selects the physical execution plan with the lowest overall cost. Reference: TiDB 性能分析和优化方法 | PingCAP 文档中心 So B is correct.
C. Obtaining TSO is asynchronous with parsing and compiling, not necessarily before.
D. Same as B, correct.

So the choices are B and D.

| username: 数据库真NB | Original post link

Only option D is correct, right?

| username: hacker_77powerful | Original post link

Thank you for the explanation.