SQL Optimization Process
In TiDB, the process from inputting a query to getting the execution result according to the final execution plan is illustrated as follows:
After parsing the original query text by
parser and some simple validity checks, TiDB first makes some logically equivalent changes to the query. For detailed changes, see SQL Logical Optimization.
Through these equivalent changes, this query becomes easier to handle in the logical execution plan. After the equivalent change is done, TiDB obtains a query plan structure equivalent to the original query, and then obtains a final execution plan based on the data distribution and the specific execution cost of an operator. For details, see SQL Physical Optimization.
At the same time, when TiDB executes the
PREPARE statement, you can choose to enable caching to reduce the cost of generating the execution plan in TiDB. For details, see Execution Plan Cache.