The typical process of the SQL engine from accepting an SQL request to execution is shown in the following figure:

The following table describes the modules involved in the SQL request execution process.
Module |
Description |
|---|---|
| Quick Parametric Module | The rapid parameterization module converts constants in SQL statements into parameters, then uses the parameterized SQL text as a key to retrieve an execution plan from the PlanCache. This enables SQL statements with only parameter differences to share the same execution plan. |
| Plan Cache | The execution plan cache module caches the execution plan generated for an SQL statement in memory upon its first execution. Subsequent executions can then reuse this plan, eliminating the need to repeatedly perform the query optimization process. |
| Syntax Analysis Module (Parser) | Upon receiving an SQL request string from the user, the lexical/syntactic parsing module breaks the string into individual "tokens" and parses the entire request according to predefined syntactic rules. This converts the SQL request string into a memory data structure with syntactic information, known as a syntax tree. |
| Semantic Resolution Module (Resolver) | The resolver converts the generated syntax tree into an internal data structure that incorporates database semantics. In this process, the resolver translates the tokens in the SQL request into corresponding objects (such as databases, tables, columns, and indexes) based on the database metadata. The resulting data structure is called a statement tree. |
| Query Rewrite | Query rewriting refers to the process of transforming an SQL statement into another that is easier to optimize. |
| Optimizer | The optimizer is at the core of SQL request optimization, responsible for generating the optimal execution plan for an SQL request. During the optimization process, the optimizer must comprehensively consider various factors such as the semantics of the SQL request, the characteristics of object data, and the physical distribution of objects. It addresses core issues including access path selection, join order determination, join algorithm choice, and distributed plan generation, ultimately selecting the best execution plan for the corresponding SQL. |
| Code Generator | Converts the execution plan into executable code without making any optimization choices. |