MySQL临时表是共享资源吗?

发布于 2024-11-18 05:35:08 字数 337 浏览 4 评论 0原文

我有一个使用临时表的 MySQL 存储过程。假设我的表名称是“temp”,我用它来存储一些中间数据。它将在程序开始时创建,并在程序结束时删除。

CREATE PROCEDURE p()
BEGIN

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

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

DROP TEMPORARY TABLE \`temp\`;

END;

问题是这个存储过程可能被不同的用户同时使用,所以我想知道这是否会导致任何问题(即临时表中插入的数据有任何冲突)。换句话说,临时表是对同一 SP 的不同调用中的共享资源吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

俏︾媚 2024-11-25 05:35:08

不,临时表仅限于数据库连接的范围。您可以在同一数据库连接期间对过程的后续调用中使用临时表,但其他连接无法访问它。他们可以创建同名的表,但每个临时表都是独立的。当您关闭连接时,临时表就会消失。

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.

丘比特射中我 2024-11-25 05:35:08

临时表仅对当前会话可见。

因此,如果您同时有多个会话 - 每个会话都将拥有自己独立的同名临时表。

文档: http://dev.mysql.com/doc/refman /5.1/en/create-table.html, ctrl+f 表示“您可以使用临时表”

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"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文