01 丨 Understanding SQL: a language with a long half-life
02 丨 The past and present of DBMS
03 丨 Learn to use the database to think about how SQL is executed
How to execute SQL in Oracle? Let's first look at the execution process of SQL in Oracle:
As can be seen from the above picture, the SQL statement has gone through the following steps in Oracle.
Grammar check: Check whether the SQL spelling is correct. If it is not correct, Oracle will report a grammatical error.
Semantic check: Check whether the access object in SQL exists. For example, when we write a SELECT statement, the column name is wrong, the system will prompt an error. The role of syntax check and semantic check is to ensure that the SQL statement is error-free.
Permission check: See if the user has permission to access the data.
Shared pool check: Shared pool (Shared Pool) is a memory pool, the main role is to cache SQL statements and the execution plan of the statement. Oracle checks whether there is an execution plan for SQL statements in the shared pool to determine whether to perform soft analysis or hard analysis. How to understand soft analysis and hard analysis? In the shared pool, Oracle first performs Hash operation on the SQL statement, and then searches in the library cache according to the Hash value. If there is an execution plan for the SQL statement, it is directly used to execute and directly enter the "executor" link , This is soft analysis. If the SQL statement and execution plan are not found, Oracle needs to create a parse tree for analysis, generate an execution plan, and enter the "optimizer" step. This is hard analysis.
Optimizer: The optimizer is to perform hard parsing, that is, to decide how to do it, such as creating a parse tree and generating an execution plan.
Executor: When you have the parse tree and execution plan, you know how the SQL should be executed, so that you can execute the statement in the executor.
How is SQL executed in MySQL