Is MySQL Temporary table a shared resource?

岁酱吖の 提交于 2019-11-27 13:42:00

问题


I have a MySQL stored procedure that uses a temporary table. Assume that my table name is 'temp' and I use it to store some middle data. It will create at the beginning of procedure, and will drop at the end.

CREATE PROCEDURE p()
BEGIN

CREATE TEMPORARY TABLE \`temp\`(...);

INSERT INTO \`temp\` VALUES(...);

DROP TEMPORARY TABLE \`temp\`;

END;

The problem is that this stored procedure may be used by different users concurrently, so I want to know if this can cause any problems (i.e. any conflict in inserted data in temp table). In other word is temp table a shared resource within different calls to the same SP?


回答1:


No, a temp table is limited to the scope of your database connection. You can use the temp table in subsequent calls to the procedure during the same database connection, but other connections cannot access it. They can create a table by the same name, but each temp table will be independent. Temp tables go away when you close your connection.




回答2:


Temporary table is visible only for current session.

So if you have several simultaneuous sessions - each one will have its own independent temporary table with the same name.

Documentation: http://dev.mysql.com/doc/refman/5.1/en/create-table.html, ctrl+f for "You can use the TEMPORARY"



来源:https://stackoverflow.com/questions/6567730/is-mysql-temporary-table-a-shared-resource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!