Deleting a temp table at the end of a stored procedure in MySQL

Do I need to add DROP TEMPORARY TABLE IF EXISTS data; at the end of the stored procedure, even if I have a check at the top? Are there any performance implications?

 CREATE DEFINER=`TEST`@`%` PROCEDURE `TEST`() BEGIN DROP TEMPORARY TABLE IF EXISTS data; CREATE TEMPORARY TABLE data AS ... END; 
+6
source share
1 answer

In MySQL, temporary tables are automatically discarded when the database connection is closed. If you plan to leave your connection open after the stored procedure, your temporary table will exist on disk until that connection is closed. The performance implications depend on many factors, for example, how you set up temporary table storage on your server, the amount of data in the table, etc.

It is considered best practice to simply drop the temporary table as soon as you are done with it. Then you get rid of worries about these potential performance implications.

+9
source

Source: https://habr.com/ru/post/922243/


All Articles