MySQL - Can we use the same temporary table name in different stored procedure? In our database, we generate statistics by periodically calling a large number of stored procedures in the event.

Considering there are two SP


auto_update_daily_users   
auto_update_daily_orders


Is there a conflict when using the same temporary table name (lets say temp1)in both stored procedures?

I checked Q&amp;A on Stack Overflow, they say the temporary table's scope is the current session. I think it means when we connect the db server with clients.

But in my case all the sp are running on the server side. So could anyone explain this?

Will the temporary table be automatically destroyed after one SP is finished? What if two SPs are running at the same time? Aren't they running in the same session?
in my case all the sp are running on the server side


Any case the SP is executed using some client connection (from Event Scheduler, for example). If they are called one-by-one from some outer SP/UDF - they are executed in the same connection, and temp table created by 1st SP exists when 2nd starts. If they are executed independently (for example, as/from 2 separate event procedures) - they are executed in different connections, and each have its own independent (local) temp table.

Server only accept queries and returns its results. Anything that sends queries and receives its results is client. See SHOW PROCESSLIST - you will see all client connections, including Event Scheduler service connection and executed events connections, separate connection for each separate event.


  Will the temporary table be automatically destroyed after one SP is finished?


Temporary tables have a connection scope. If you execute 2 SPs in two different connections, each have its own temp table with its own structure and data despite the fact that their names are the same.

If you execute one SP then another, but close connection after executing 1st and create new for executing 2nd - each SP will have its own temp table again.

But if you execute one SP then another in the same connection then temptable created by 1st will exist while 2nd start, with the data inserted by 1st. - akina