Should prepared statements be released when used within stored procedures?

When using prepared instructions inside stored procedures, should they be freed at the end of the procedure or not, or does it not matter, and why?

Some code to explain:

CREATE PROCEDURE getCompanyByName (IN name VARCHAR(100))
NOT DETERMINISTIC
BEGIN
  PREPARE gcbnStatement FROM 'SELECT * FROM Companies WHERE name=? LIMIT 1';
  SET @companyName = name;
  EXECUTE gcbnStatement USING @companyName;
  DEALLOCATE PREPARE gcbnStatement;
END $$

So - should there be a DEALLOCATE statement or not? Hurrah!

/ Victor

+6
source share
3 answers

According to docs :

The prepared report is specific to the session in which it was created. If you end a session without releasing a previously prepared one, the server frees it automatically.

, , , .

+6

, , .

+1

I have the same problem too, the document mentions that

A prepared statement is also global to the session. If you create a prepared statement within a stored routine, it is not deallocated when the stored routine ends.

At first I thought it meant that he should be released explicitly.

But this is not the case.

0
source

All Articles