The pre-compiled MySQL

First, the three stages:

  1. Lexical and semantic parsing

  2. Optimization sql statement, to develop the implementation plan

  3. Execution and returns the result

Second, the reason appears precompiled

  1, in many cases, an SQL statement might be repeated, or每次执行的时候只有个别的值不同

  2, such as the value of where the query conditions are different, a different set of values ​​of the update, insert the value of different values, will result in different SQL statements.

  3, since each of these values would be different lexical semantic parsing , optimization, implementation of the development plan , it will affect the efficiency .

  4, step 1, and often longer than the combined duration of the time step 3.

 

  We need precompiled played in this case.

 

Third, pre-compiled

  1, precompiled: drive refers to the database compiled prior to sql statement sent to the DBMS in the sql statement and the parameters, so that when the DBMS sql executed, there is no need to recompile.

 

  2, precompiled benefits:

    1, in most cases after the next SQL pre-compiler can be executed directly, DBMS do not need to re-compile.

    2, the SQL more complex, the greater will be the complexity of the compiler, the compiler pre-stage multiple operations may be combined into one operation.

    3, the same pre-compiled SQL can be reused. (The PreparedStatement object produced after a pre-compiled SQL cached,

        Next time for the same SQL, you can directly use this cache PreparedState object. )

    4, such a value may be SQL statement with placeholders Alternatively, each compiler does not need to be performed directly,

      Just when executed, direct a different value for each request to set the position of the placeholder.

    5, can be seen as pre-compiled sql statement templated or parametric.

Four, mybatis sql dynamic analysis of source code and precompiled

  mybatis sql dynamic analysis

    mybatis before the call connection be precompiled sql, sql statement will be dynamic resolution, dynamic analysis mainly includes the following features:

    • Processing the placeholder

    • Dynamic sql processing

    • Parameter Type checking

  Note: mybatis By default, all the sql will be precompiled.

Published 15 original articles · won praise 7 · views 10000 +

Guess you like

Origin blog.csdn.net/J_M_S_H_T/article/details/104897931