To figure out why MySQL's stored procedures are efficient, we need to understand what the MySQL execution process is, and when the SQL statement is entered, MySQL checks the syntax of the SQL statement before compiling it, then executes it and returns the result. As shown in the following:
Normal SQL statements are parsed and compiled by the MySQL engine, and stored procedures require parsing and compiling at the first run, but the subsequent call to the stored procedure eliminates the need for parsing and compiling, which greatly improves the efficiency of SQL execution. What is a stored procedure? stored procedures are precompiled collections of SQL statements and control statements that are stored as a single name and processed as a unit. Advantages of stored procedures:1 enhanced the functionality and flexibility of SQL statements2 achieve faster execution speed3 Reduced network traffic create a stored procedureCREATE user PROCEDURE stored procedure name (parameter 1, parameter 2,...)Process Body There are three types of parameters: in Out INOUT Process Body: 1 The process body consists of arbitrary and legitimate SQL statements
MySQL Stored procedure analysis